Skip to content

Commit

Permalink
Fix finding references to CtorGroup (#15884)
Browse files Browse the repository at this point in the history
  • Loading branch information
0101 authored Aug 30, 2023
1 parent aaf4c11 commit a1cc8b7
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
7 changes: 6 additions & 1 deletion src/Compiler/Checking/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,12 @@ type Item =
| Item.Property(name = nm) -> nm |> ConvertValLogicalNameToDisplayNameCore
| Item.MethodGroup(_, FSMeth(_, _, v, _) :: _, _) -> v.DisplayNameCore
| Item.MethodGroup(nm, _, _) -> nm |> ConvertValLogicalNameToDisplayNameCore
| Item.CtorGroup(nm, _) -> nm |> DemangleGenericTypeName
| Item.CtorGroup(nm, ILMeth(_, ilMethInfo, _) :: _) ->
match ilMethInfo.ApparentEnclosingType |> tryNiceEntityRefOfTy with
| ValueSome tcref -> tcref.DisplayNameCore
| _ -> nm
|> DemangleGenericTypeName
| Item.CtorGroup(nm, _) -> nm |> DemangleGenericTypeName
| Item.FakeInterfaceCtor ty
| Item.DelegateCtor ty ->
match ty with
Expand Down
11 changes: 6 additions & 5 deletions src/Compiler/Service/ItemKey.fs
Original file line number Diff line number Diff line change
Expand Up @@ -415,11 +415,12 @@ and [<Sealed>] ItemKeyStoreBuilder() =
match info with
| FSMeth (_, ty, vref, _) when vref.IsConstructor -> writeType true ty
| FSMeth (_, _, vref, _) -> writeValue vref
| ILMeth (_, info, _) ->
info.ILMethodRef.ArgTypes |> List.iter writeILType
writeILType info.ILMethodRef.ReturnType
writeString info.ILName
writeType false info.ApparentEnclosingType
| ILMeth (_, ilMethInfo, _) when info.IsConstructor -> writeType true ilMethInfo.ApparentEnclosingType
| ILMeth (_, ilMethInfo, _) ->
ilMethInfo.ILMethodRef.ArgTypes |> List.iter writeILType
writeILType ilMethInfo.ILMethodRef.ReturnType
writeString ilMethInfo.ILName
writeType false ilMethInfo.ApparentEnclosingType
| _ ->
writeString ItemKeyTags.itemValueMember
writeEntityRef info.DeclaringTyconRef
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,28 @@ let foo x = x ++ 4""" })
])
}

[<Theory>]
[<InlineData("First")>]
[<InlineData("Second")>]
let ``We find disposable constructors`` searchIn =
let source1 = "type MyReader = System.IO.StreamReader"
let source2 = """open ModuleFirst
let reader = MyReader "test.txt"
"""
{ SyntheticProject.Create(
{ sourceFile "First" [] with Source = source1 },
{ sourceFile "Second" [] with Source = source2 })
with SkipInitialCheck = true }

.Workflow {
placeCursor searchIn "MyReader"
findAllReferences (expectToFind [
"FileFirst.fs", 2, 5, 13
"FileSecond.fs", 3, 13, 21
])
}


module Parameters =

[<Fact>]
Expand Down
2 changes: 1 addition & 1 deletion tests/service/ProjectAnalysisTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3070,7 +3070,7 @@ let ``Test Project21 all symbols`` () =
("unit", "unit", "file1", ((12, 43), (12, 47)), ["type"], ["abbrev"]);
("val raise", "raise", "file1", ((13, 18), (13, 23)), [], ["val"]);
("System", "System", "file1", ((13, 25), (13, 31)), [], ["namespace"]);
("member .ctor", "``.ctor``", "file1", ((13, 25), (13, 55)), [], ["member"]);
("member .ctor", "NotImplementedException", "file1", ((13, 25), (13, 55)), [], ["member"]);
("Impl", "Impl", "file1", ((2, 7), (2, 11)), ["defn"], ["module"])|]

//-----------------------------------------------------------------------------------------
Expand Down

0 comments on commit a1cc8b7

Please sign in to comment.