-
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
Add ScopedKind to IParameterSymbol and ILocalSymbol #64190
Conversation
/// <summary> | ||
/// Enumeration for kinds of scoped modifiers. | ||
/// </summary> | ||
public enum ScopedKind |
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.
// https://github.com/dotnet/roslyn/issues/61647: Internally, scope is represented with this enum, | ||
// but the public API uses a pair of IsRefScoped and IsValueScoped bools (see ILocalSymbol, | ||
// IParameterSymbol, and ScopedRefAttribute). We should have a common representation. | ||
// And we should use common terms for the attribute and enum names. | ||
internal enum DeclarationScope : byte |
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.
Seems like it would be a reasonable change.
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.
@@ -22,6 +22,11 @@ public interface IParameterSymbol : ISymbol | |||
/// </summary> | |||
RefKind RefKind { get; } | |||
|
|||
/// <summary> | |||
/// Returns the scoped kind of the local. |
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.
None = 0, | ||
|
||
/// <summary> | ||
/// A ref scoped to the current method or block. |
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.
if ((symbol as Symbols.PublicModel.ParameterSymbol)?.GetSymbol<ParameterSymbol>() is { } parameter && | ||
parameter.EffectiveScope == DeclarationScope.RefScoped && | ||
if (symbol.ScopedKind == ScopedKind.ScopedRef && | ||
(symbol as Symbols.PublicModel.ParameterSymbol)?.GetSymbol<ParameterSymbol>() is { } parameter && | ||
!ParameterHelpers.IsRefScopedByDefault(parameter) && |
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.
Are we missing IsRefScopedByDefault
as a public API? Is there an alternative way to detect this in a language independent way? #Closed
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.
If not, perhaps we should use this condition only for C# symbols and not dismiss other symbols?
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.
IsRefScopedByDefault()
relies on ModuleSymbol.UsesUpdatedEscapeRules
, which is not tracked in VB, nor is scoped
. Changed to use for C# symbols only.
Done with review pass (commit 3) |
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.
LGTM (commit 4)
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.
LGTM (commit 4). It does seem like it would be reasonable to remove DeclarationScope
and just use ScopedKind
everywhere, imo.
// https://github.com/dotnet/roslyn/issues/61647: Internally, scope is represented with this enum, | ||
// but the public API uses a pair of IsRefScoped and IsValueScoped bools (see ILocalSymbol, | ||
// IParameterSymbol, and ScopedRefAttribute). We should have a common representation. | ||
// And we should use common terms for the attribute and enum names. | ||
internal enum DeclarationScope : byte |
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.
Seems like it would be a reasonable change.
See #61647.