Skip to content

Commit 584c702

Browse files
authored
Fix exn signature range (#18982)
1 parent 2faf1ca commit 584c702

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

src/Compiler/Symbols/SymbolHelpers.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ module internal SymbolHelpers =
9494
| Item.Value vref | Item.CustomBuilder (_, vref) -> Some (rangeOfValRef preferFlag vref)
9595
| Item.UnionCase(ucinfo, _) -> Some (rangeOfUnionCaseInfo preferFlag ucinfo)
9696
| Item.ActivePatternCase apref -> Some (rangeOfValRef preferFlag apref.ActivePatternVal)
97-
| Item.ExnCase tcref -> Some tcref.Range
97+
| Item.ExnCase tcref -> Some (rangeOfEntityRef preferFlag tcref)
9898
| Item.AnonRecdField (_,_,_,m) -> Some m
9999
| Item.RecdField rfinfo -> Some (rangeOfRecdFieldInfo preferFlag rfinfo)
100100
| Item.UnionCaseField (UnionCaseInfo (_, ucref), fieldIndex) -> Some (rangeOfRecdField preferFlag (ucref.FieldByIndex(fieldIndex)))

tests/FSharp.Compiler.ComponentTests/FSharpChecker/FindReferences.fs

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,22 @@ val myFunc2: param: int -> int
266266
}
267267

268268
module Exceptions =
269-
let project() = SyntheticProject.Create(
270-
{ sourceFile "First" [] with ExtraSource = "exception MyException of string" },
271-
{ sourceFile "Second" [] with ExtraSource = """
269+
let source1 = "exception MyException of string"
270+
let signature1 = "exception MyException of string"
271+
272+
let source2 = """
272273
open ModuleFirst
273-
let foo x = raise (MyException "foo")""" })
274+
let foo x = raise (MyException "foo")
275+
"""
276+
let project() = SyntheticProject.Create(
277+
{ sourceFile "First" [] with ExtraSource = source1 },
278+
{ sourceFile "Second" [] with ExtraSource = source2 })
279+
280+
let projectWithSignature() = SyntheticProject.Create(
281+
{ sourceFile "First" [] with
282+
ExtraSource = source1
283+
SignatureFile = Custom signature1 },
284+
{ sourceFile "Second" [] with ExtraSource = source2 })
274285

275286
[<Fact>]
276287
let ``We find exception from definition`` () =
@@ -292,6 +303,28 @@ let foo x = raise (MyException "foo")""" })
292303
])
293304
}
294305

306+
[<Fact>]
307+
let ``We find exception from definition and signature`` () =
308+
projectWithSignature().Workflow {
309+
placeCursor "First" 6 21 "exception MyException of string" ["MyException"]
310+
findAllReferences (expectToFind [
311+
"FileFirst.fs", 6, 10, 21
312+
"FileFirst.fsi", 2, 10, 21
313+
"FileSecond.fs", 8, 19, 30
314+
])
315+
}
316+
317+
[<Fact>]
318+
let ``We find exception from usage and signature`` () =
319+
projectWithSignature().Workflow {
320+
placeCursor "Second" 8 30 "raise (MyException \"foo\")" ["MyException"]
321+
findAllReferences (expectToFind [
322+
"FileFirst.fs", 6, 10, 21
323+
"FileFirst.fsi", 2, 10, 21
324+
"FileSecond.fs", 8, 19, 30
325+
])
326+
}
327+
295328
module Attributes =
296329

297330
let project() = SyntheticProject.Create(

0 commit comments

Comments
 (0)