-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Readonly members symbol display #34876
Readonly members symbol display #34876
Conversation
src/Compilers/CSharp/Portable/Symbols/PropertySymbolExtensions.cs
Outdated
Show resolved
Hide resolved
@@ -168,6 +173,11 @@ public override void VisitEvent(IEventSymbol symbol) | |||
AddAccessibilityIfRequired(symbol); | |||
AddMemberModifiersIfRequired(symbol); | |||
|
|||
if ((symbol.AddMethod ?? symbol.RemoveMethod)?.IsReadOnly == true) |
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.
(symbol.AddMethod ?? symbol.RemoveMethod)?.IsReadOnly == true [](start = 16, length = 61)
What if add
is readonly
but remove
is not?
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.
We don't provide a way to declare such a combination of event accessors in the language, so I'd write it off as a malformed symbol that we can't display reliably--we just need to avoid crashing.
src/Compilers/CSharp/Portable/Symbols/PropertySymbolExtensions.cs
Outdated
Show resolved
Hide resolved
So it looks like a lot of modifiers such as |
Looks like changing symbol display might have broken a bunch of IL tests? |
Part of the print out of IL includes symbol display and the methods used here have some In reply to: 481947213 [](ancestors = 481947213) |
src/Compilers/CSharp/Portable/Symbols/PropertySymbolExtensions.cs
Outdated
Show resolved
Hide resolved
Putting this on hold until we have a chance to discuss the design |
We concluded in design that "explicitly readonly" members should show a 'readonly' keyword in Quick Info. If the member is only readonly due to the containing struct being 'readonly', then we don't show the keyword. /cc @sharwell @jasonmalinowski. Will revise accordingly when I get the chance (focusing on #34778 first) |
src/Compilers/CSharp/Portable/SymbolDisplay/SymbolDisplayVisitor.Members.cs
Show resolved
Hide resolved
src/Compilers/CSharp/Portable/Symbols/PropertySymbolExtensions.cs
Outdated
Show resolved
Hide 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.
Done with review pass (iteration 6)
Marked PR as "private" for now. Remove the tag once ready for another look. Thanks |
@@ -367,7 +367,7 @@ .maxstack 2 | |||
IL_0003: stfld ""int S.<X>k__BackingField"" | |||
IL_0008: ldarg.0 | |||
IL_0009: ldarg.0 | |||
IL_000a: call ""int S.X.get"" | |||
IL_000a: call ""readonly int S.X.get"" |
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.
One quirk of this work: after a property is emitted we have no decent way of knowing whether it was implicitly readonly in source. So when the member is in a non-readonly type we just display readonly
if the IsReadOnlyAttribute is present on the member.
I tried to avoid displaying readonly
where it was not present in source, and for members of readonly types, because it minimizes test churn and limits showing the keyword to cases where its presence or absence will be more informative.
@@ -68,6 +68,8 @@ public enum SymbolDisplayMemberOptions | |||
|
|||
/// <summary> | |||
/// Includes the <c>ref</c>, <c>ref readonly</c>, <c>ByRef</c> keywords for ref-returning methods and properties/indexers. | |||
/// Also includes the <c>readonly</c> keyword on methods, properties/indexers, and events due to the keyword | |||
/// changing the <c>this</c> parameter's ref kind from <c>ref</c> to <c>ref readonly</c>. |
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.
cc @jcouv
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.
This seems fishy. Is this a name we regret and should fix?
PTAL @dotnet/roslyn-compiler @dotnet/roslyn-ide |
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.
IDE parts look fine; there's some suspicious bits in the compiler code to me. Also tagging @sharwell since I know he was doing some work on quick info tests. If this is the new structure, great; if not then maybe there's work needed.
return false; | ||
} | ||
|
||
if (method is SourcePropertyAccessorSymbol sourceAccessor && propertyOpt is SourcePropertySymbol sourceProperty) |
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.
Should this be using method.AssociatedSymbol to get the source property instead? My guess being one of three things are true:
- ShouldMethodDisplayReadOnly gets called directly with an accessor and not just from ShouldPropertyDisplayReadOnly, at which point the callers are having to get the source property,
- This is only being passed by ShouldPropertyDisplayReadOnly, at which point we could just inline this into that, or:
- We're trying to do something fancier here, and we probably should have a comment.
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 believe (1) is the answer here. See the AddAccessor
method in this file.
@@ -68,6 +68,8 @@ public enum SymbolDisplayMemberOptions | |||
|
|||
/// <summary> | |||
/// Includes the <c>ref</c>, <c>ref readonly</c>, <c>ByRef</c> keywords for ref-returning methods and properties/indexers. | |||
/// Also includes the <c>readonly</c> keyword on methods, properties/indexers, and events due to the keyword | |||
/// changing the <c>this</c> parameter's ref kind from <c>ref</c> to <c>ref readonly</c>. |
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.
This seems fishy. Is this a name we regret and should fix?
Responding to @jasonmalinowski's comment:
Maybe! I approached the situation by looking for an existing SymbolDisplayMemberOption which would:
I felt throwing it under the It's possible that the name of the option should change, but I can't readily think of a more appropriate name. (I think it would also be a breaking change to rename it.) |
It sounds like I'm using the right pattern for Quick Info tests. Are there any remaining concerns about the use or documentation of |
I'm going to merge now as it feels like we've resolved the concerns. Please let me know if there's anything that should be revised in a separate PR. |
Part of #34650