Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix finding references to CtorGroup #15884

Merged
merged 2 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"]);
T-Gro marked this conversation as resolved.
Show resolved Hide resolved
("Impl", "Impl", "file1", ((2, 7), (2, 11)), ["defn"], ["module"])|]

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