-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Update documentation for DeclaringSyntaxReferences and Locations to clarify partial members behavior #80704
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
Update documentation for DeclaringSyntaxReferences and Locations to clarify partial members behavior #80704
Changes from 5 commits
d1ffbbf
86b9a8e
7cf70f9
f7560e5
a2577d2
0c0af75
dc7f595
d93ff58
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 |
|---|---|---|
|
|
@@ -2576,5 +2576,57 @@ public partial void M<T>() { } | |
| Assert.False(partialImpl.IsPartialDefinition); | ||
| Assert.False(partialImplConstructed.IsPartialDefinition); | ||
| } | ||
|
|
||
| [Fact, WorkItem("https://github.com/dotnet/roslyn/issues/13456")] | ||
|
CyrusNajmabadi marked this conversation as resolved.
Outdated
|
||
| public void PartialMethodsLocationsAndSyntaxReferences() | ||
| { | ||
| var source1 = """ | ||
| namespace N1 | ||
| { | ||
| partial class C1 | ||
| { | ||
| partial void PartialM(); | ||
| } | ||
| } | ||
| """; | ||
|
|
||
| var source2 = """ | ||
| namespace N1 | ||
| { | ||
| partial class C1 | ||
| { | ||
| partial void PartialM() { } | ||
| } | ||
| } | ||
| """; | ||
|
|
||
| var comp = CreateCompilation([(source1, "source1"), (source2, "source2")]); | ||
| comp.VerifyDiagnostics(); | ||
|
|
||
| var methodSymbols = comp.GetSymbolsWithName("PartialM"); | ||
|
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. This is unnecessary lengthy and complicated. Since we know there's only one and it's a method symbol: we can do 1 line,
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. @copilot remove lengthy and complicated assertion checking. Also add to the copilot-instructions file that tests should avoid unnecessary assertations and should do the minimal work necessary to get to the core assertions that validate the issue being addressed.
Contributor
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. Simplified test and updated Compiler.instructions.md to guide future tests in commit 2c7c5d9
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 inlining
Contributor
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. Inlined in commit 2c7c5d9 |
||
|
|
||
| var method = (IMethodSymbol)methodSymbols.Single(); | ||
| Assert.NotNull(method); | ||
|
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. Unnecessary assertion #Closed
Contributor
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. Removed in commit 2c7c5d9 |
||
|
|
||
| // For partial methods, Locations and DeclaringSyntaxReferences contain only one location | ||
| Assert.Equal(1, method.Locations.Length); | ||
| Assert.Equal(1, method.DeclaringSyntaxReferences.Length); | ||
|
|
||
| // The single location is the definition part | ||
| Assert.True(method.IsPartialDefinition); | ||
| Assert.Null(method.PartialDefinitionPart); | ||
| Assert.NotNull(method.PartialImplementationPart); | ||
|
|
||
| // To get all locations, you need to use PartialImplementationPart | ||
| var implementationPart = method.PartialImplementationPart; | ||
| Assert.Equal(1, implementationPart.Locations.Length); | ||
| Assert.Equal(1, implementationPart.DeclaringSyntaxReferences.Length); | ||
|
|
||
| // Verify the locations are different | ||
| Assert.NotEqual(method.Locations[0], implementationPart.Locations[0]); | ||
|
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. By naming the sources when creating the compilation ( |
||
|
|
||
| Assert.Equal("source1", method.Locations[0].SourceTree.FilePath); | ||
| Assert.Equal("source2", implementationPart.Locations[0].SourceTree.FilePath); | ||
| } | ||
| } | ||
| } | ||
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.
Link is wrong here too #Closed