-
Notifications
You must be signed in to change notification settings - Fork 4k
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 symbol display for backing fields #76000
base: main
Are you sure you want to change the base?
Conversation
{ | ||
AddPropertyNameAndParameters(associatedProperty); | ||
AddPunctuation(SyntaxKind.DotToken); | ||
AddKeyword(SyntaxKind.FieldKeyword); |
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.
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 closest flag I found was SymbolDisplayCompilerInternalOptions.UseMetadataMethodNames
, was this the one you had in mind?
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.
Yes something like this. I guess, we might want to make it more general, or add a similar flag for field names and specify it for existing formats that are using UseMetadataMethodNames
today.
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.
For testing purposes I am going to try checking and using this flag. I expect this will fix a large number of failing tests, which had started using the new symbol display for backing field after the 1st iteration of this PR.
After I see results of that, I will try to figure out a more permanent solution, perhaps by renaming the flag to UseMetadataMemberNames
.
I also noticed that this flag is not respected when displaying a property accessor (e.g. Type.Prop.get
is still used when the flag is set). I added a test to show that. I'm not sure whether we want to change the behavior for that case.
Done with review pass (commit 1) |
@@ -59,7 +59,13 @@ public override void VisitField(IFieldSymbol symbol) | |||
AddPunctuation(SyntaxKind.DotToken); | |||
} | |||
|
|||
if (symbol.ContainingType.TypeKind == TypeKind.Enum) | |||
if (symbol.AssociatedSymbol is IPropertySymbol associatedProperty) |
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.
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.
I am expecting this change to only affect C# symbols due to being in C# layer. I will look for, or add, a VB test to demonstrate that an appropriate display of the backing field is used there.
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.
I am expecting this change to only affect C# symbols due to being in C# layer.
I do not think this is the case. This layer can be invoked on VB symbols. It operates on common interfaces. I am sure we have a bunch of tests checking C# display for VB symbols and checking VB display for C# symbols.
@@ -59,7 +59,13 @@ public override void VisitField(IFieldSymbol symbol) | |||
AddPunctuation(SyntaxKind.DotToken); | |||
} | |||
|
|||
if (symbol.ContainingType.TypeKind == TypeKind.Enum) | |||
if (symbol.AssociatedSymbol is IPropertySymbol associatedProperty) |
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.
Closes #75529