-
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
Changes from 2 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 |
---|---|---|
|
@@ -2,16 +2,28 @@ | |
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using Roslyn.Utilities; | ||
|
||
namespace Microsoft.CodeAnalysis.CSharp.Symbols | ||
{ | ||
// 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{ | ||
Unscoped = 0, | ||
RefScoped = 1, | ||
ValueScoped = 2, | ||
} | ||
|
||
internal static class DeclarationScopeExtensions | ||
{ | ||
internal static ScopedKind AsScopedKind(this DeclarationScope scope) | ||
{ | ||
return scope switch | ||
{ | ||
DeclarationScope.Unscoped => ScopedKind.None, | ||
DeclarationScope.RefScoped => ScopedKind.ScopedRef, | ||
DeclarationScope.ValueScoped => ScopedKind.ScopedValue, | ||
_ => throw ExceptionUtilities.UnexpectedValue(scope), | ||
}; | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
/// </summary> | ||
ScopedKind ScopedKind { get; } | ||
|
||
/// <summary> | ||
/// Returns true if the parameter was declared as a parameter array. | ||
/// </summary> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
namespace Microsoft.CodeAnalysis | ||
{ | ||
/// <summary> | ||
/// Enumeration for kinds of scoped modifiers. | ||
/// </summary> | ||
public enum ScopedKind : byte | ||
{ | ||
/// <summary> | ||
/// Not scoped. | ||
/// </summary> | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
/// </summary> | ||
ScopedRef = 1, | ||
|
||
/// <summary> | ||
/// A value scoped to the current method or block. | ||
/// </summary> | ||
ScopedValue = 2, | ||
} | ||
} |
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? #ClosedThere 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 onModuleSymbol.UsesUpdatedEscapeRules
, which is not tracked in VB, nor isscoped
. Changed to use for C# symbols only.