-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Extensions: fix GetSymbolInfo within ExtensionMemberCrefSyntax #81722
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7160,6 +7160,122 @@ class Nested | |
| Diagnostic(ErrorCode.WRN_BadXMLRef, "extension(int).M()").WithArguments("extension(int).M()").WithLocation(10, 28)); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81710")] | ||
| public void Cref_68() | ||
| { | ||
| var src = """ | ||
| /// <see cref="E.extension(int).M(string)"/> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| static class E | ||
| { | ||
| extension(int i) | ||
| { | ||
| public void M(string s) => throw null!; | ||
| } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src, parseOptions: TestOptions.RegularPreviewWithDocumentationComments); | ||
| comp.VerifyEmitDiagnostics(); | ||
|
|
||
| var tree = comp.SyntaxTrees.Single(); | ||
| var extensionCref = GetSyntax<ExtensionMemberCrefSyntax>(tree, "extension(int).M(string)", descendIntoTrivia: true); | ||
| var model = comp.GetSemanticModel(tree); | ||
| AssertEx.Equal("E.extension(int).M(string)", model.GetSymbolInfo(extensionCref).Symbol.ToDisplayString()); | ||
| AssertEx.Equal("E.extension(int).M(string)", model.GetSymbolInfo(extensionCref.Member).Symbol.ToDisplayString()); | ||
|
|
||
| var m = ((NameMemberCrefSyntax)extensionCref.Member).Name; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. That uncovered another problem |
||
| Assert.Equal("M", m.ToString()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider asserting those found symbols are the same (reference equals) between themselves and also with the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, I don't think there's a requirement that the symbols from semantic model be reference equal. Definitions should be reference equal, but that's not about the semantic model and here we're not dealing with definitions in this test anyways. |
||
| AssertEx.Equal("E.extension(int).M(string)", model.GetSymbolInfo(m).Symbol.ToDisplayString()); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81710")] | ||
| public void Cref_69() | ||
| { | ||
| var src = """ | ||
| /// <see cref="E.extension(int).Property"/> | ||
| static class E | ||
| { | ||
| extension(int i) | ||
| { | ||
| public int Property => throw null!; | ||
| } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src, parseOptions: TestOptions.RegularPreviewWithDocumentationComments); | ||
| comp.VerifyEmitDiagnostics(); | ||
|
|
||
| var tree = comp.SyntaxTrees.Single(); | ||
| var extensionCref = GetSyntax<ExtensionMemberCrefSyntax>(tree, "extension(int).Property", descendIntoTrivia: true); | ||
| var model = comp.GetSemanticModel(tree); | ||
| AssertEx.Equal("E.extension(int).Property", model.GetSymbolInfo(extensionCref).Symbol.ToDisplayString()); | ||
| AssertEx.Equal("E.extension(int).Property", model.GetSymbolInfo(extensionCref.Member).Symbol.ToDisplayString()); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81710")] | ||
| public void Cref_70() | ||
| { | ||
| var src = """ | ||
| namespace N; | ||
|
|
||
| /// <see cref="N.E.extension(int).M(string)"/> | ||
| static class E | ||
| { | ||
| extension(int i) | ||
| { | ||
| public void M(string s) => throw null!; | ||
| } | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src, parseOptions: TestOptions.RegularPreviewWithDocumentationComments); | ||
| comp.VerifyEmitDiagnostics(); | ||
|
|
||
| var tree = comp.SyntaxTrees.Single(); | ||
| var model = comp.GetSemanticModel(tree); | ||
|
|
||
| var qualifiedCref = GetSyntax<QualifiedCrefSyntax>(tree, "N.E.extension(int).M(string)", descendIntoTrivia: true); | ||
| AssertEx.Equal("N.E.extension(int).M(string)", model.GetSymbolInfo(qualifiedCref).Symbol.ToDisplayString()); | ||
|
|
||
| var extensionCref = GetSyntax<ExtensionMemberCrefSyntax>(tree, "extension(int).M(string)", descendIntoTrivia: true); | ||
| AssertEx.Equal("N.E.extension(int).M(string)", model.GetSymbolInfo(extensionCref).Symbol.ToDisplayString()); | ||
| AssertEx.Equal("N.E.extension(int).M(string)", model.GetSymbolInfo(extensionCref.Member).Symbol.ToDisplayString()); | ||
|
|
||
| var m = ((NameMemberCrefSyntax)extensionCref.Member).Name; | ||
| Assert.Equal("M", m.ToString()); | ||
| AssertEx.Equal("N.E.extension(int).M(string)", model.GetSymbolInfo(m).Symbol.ToDisplayString()); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/81710")] | ||
| public void Cref_71() | ||
| { | ||
| var src = """ | ||
| /// <see cref="extension(int).M(string)"/> | ||
| extension(int i) | ||
| { | ||
| public void M(string s) => throw null!; | ||
| } | ||
| """; | ||
| var comp = CreateCompilation(src, parseOptions: TestOptions.RegularPreviewWithDocumentationComments); | ||
| comp.VerifyEmitDiagnostics( | ||
| // (1,16): warning CS1574: XML comment has cref attribute 'extension(int).M(string)' that could not be resolved | ||
| // /// <see cref="extension(int).M(string)"/> | ||
| Diagnostic(ErrorCode.WRN_BadXMLRef, "extension(int).M(string)").WithArguments("extension(int).M(string)").WithLocation(1, 16), | ||
| // (2,1): error CS9283: Extensions must be declared in a top-level, non-generic, static class | ||
| // extension(int i) | ||
| Diagnostic(ErrorCode.ERR_BadExtensionContainingType, "extension").WithLocation(2, 1), | ||
| // (4,17): warning CS1591: Missing XML comment for publicly visible type or member 'extension(int).M(string)' | ||
| // public void M(string s) => throw null!; | ||
| Diagnostic(ErrorCode.WRN_MissingXMLComment, "M").WithArguments("extension(int).M(string)").WithLocation(4, 17)); | ||
|
|
||
| var tree = comp.SyntaxTrees.Single(); | ||
| var model = comp.GetSemanticModel(tree); | ||
|
|
||
| var extensionCref = GetSyntax<ExtensionMemberCrefSyntax>(tree, "extension(int).M(string)", descendIntoTrivia: true); | ||
| Assert.Null(model.GetSymbolInfo(extensionCref).Symbol); | ||
| Assert.Null(model.GetSymbolInfo(extensionCref.Member).Symbol); | ||
|
|
||
| var m = ((NameMemberCrefSyntax)extensionCref.Member).Name; | ||
| Assert.Null(model.GetSymbolInfo(m).Symbol); | ||
| } | ||
|
|
||
| [Fact] | ||
| public void PropertyAccess_Set_01() | ||
| { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -246,6 +246,27 @@ public static class E | |
| Await TestAPIAndFeature(input, kind, host) | ||
| End Function | ||
|
|
||
| <WpfTheory, CombinatorialData> | ||
| <WorkItem("https://github.com/dotnet/roslyn/issues/81710")> | ||
| Public Async Function FindReferences_ExtensionBlockMethod_Cref(kind As TestKind, host As TestHost) As Task | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nice. i'm glad this just fell out. #Resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This thread was resolved, but I do not see any changes made in response. Since these are not compiler tests, I am going to sign off, but I will reactivate the thread in case you resolved it by mistake. |
||
| Dim input = | ||
| <Workspace> | ||
| <Project Language="C#" CommonReferences="true" LanguageVersion="Preview"> | ||
| <Document> | ||
| /// <see cref="E.extension(int).[|M|]()"/> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Consider wrapping the code in
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I leaned towards this encoding |
||
| public static class E | ||
| { | ||
| extension(int i) | ||
| { | ||
| public void {|Definition:$$M|}() { } | ||
| } | ||
| } | ||
| </Document> | ||
| </Project> | ||
| </Workspace> | ||
| Await TestAPIAndFeature(input, kind, host) | ||
| End Function | ||
|
|
||
| <WorkItem("https://github.com/dotnet/roslyn/issues/81507")> | ||
| <WpfTheory, CombinatorialData> | ||
| Public Async Function FindReferences_ExtensionBlockProperty(kind As TestKind, host As TestHost) As Task | ||
|
|
@@ -429,6 +450,12 @@ class C7 | |
| { | ||
| _ = new C() { [|P|] = 1 }; | ||
| } | ||
| } | ||
| </Document> | ||
| <Document> | ||
| /// <see cref="E.extension(C).[|P|]"/> | ||
| class C8 | ||
| { | ||
| } | ||
| </Document> | ||
| <Document> | ||
|
|
@@ -445,6 +472,27 @@ public static class E | |
| Await TestAPIAndFeature(input, kind, host) | ||
| End Function | ||
|
|
||
| <WorkItem("https://github.com/dotnet/roslyn/issues/81710")> | ||
| <WpfTheory, CombinatorialData> | ||
| Public Async Function FindReferences_ExtensionBlockProperty_FromAccess_Cref(kind As TestKind, host As TestHost) As Task | ||
| Dim input = | ||
| <Workspace> | ||
| <Project Language="C#" CommonReferences="true" LanguageVersion="Preview"> | ||
| <Document> | ||
| /// <see cref="E.extension(int).[|P|]"/> | ||
| public static class E | ||
| { | ||
| extension(int i) | ||
| { | ||
| public int {|Definition:$$P|} { get => i; set { } } | ||
| } | ||
| } | ||
| </Document> | ||
| </Project> | ||
| </Workspace> | ||
| Await TestAPIAndFeature(input, kind, host) | ||
| End Function | ||
|
|
||
| <WorkItem("https://github.com/dotnet/roslyn/issues/81507")> | ||
| <WpfTheory, CombinatorialData> | ||
| Public Async Function FindReferences_ExtensionBlockProperty_FromImplementationMethodInvocation(kind As TestKind, host As TestHost) As Task | ||
|
|
@@ -688,5 +736,25 @@ public static class E | |
| Await TestAPIAndFeature(input, kind, host) | ||
| End Function | ||
|
|
||
| <WpfTheory, CombinatorialData> | ||
| Public Async Function FindReferences_ExtensionBlockMethod_GenericCref(kind As TestKind, host As TestHost) As Task | ||
| Dim input = | ||
| <Workspace> | ||
| <Project Language="C#" CommonReferences="true" LanguageVersion="Preview"> | ||
| <Document> | ||
| /// <see cref="E.extension{$${|Definition:U|}}([|U|]).M([|U|])"/> | ||
| public static class E | ||
| { | ||
| extension<T>(T t1) | ||
| { | ||
| public void M(T t2) { } | ||
| } | ||
| } | ||
| </Document> | ||
| </Project> | ||
| </Workspace> | ||
| Await TestAPIAndFeature(input, kind, host) | ||
| End Function | ||
|
|
||
| End Class | ||
| End Namespace | ||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
raw string? #Resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(indented raw string, rather).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The formatting is intentional