-
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
Scoped implicitly-typed lambda parameters #64680
Conversation
@@ -611,7 +613,8 @@ private static TypeWithAnnotations DelegateReturnTypeWithAnnotations(MethodSymbo | |||
} | |||
|
|||
var parameterRefKindsBuilder = ArrayBuilder<RefKind>.GetInstance(ParameterCount); | |||
var parameterScopesBuilder = ArrayBuilder<DeclarationScope>.GetInstance(ParameterCount); | |||
var parameterDeclarationScopesBuilder = ArrayBuilder<DeclarationScope>.GetInstance(ParameterCount); |
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.
@@ -304,9 +307,11 @@ internal override void AddDeclarationDiagnostics(BindingDiagnosticBag diagnostic | |||
CSharpCompilation compilation, | |||
UnboundLambda unboundLambda, | |||
ImmutableArray<TypeWithAnnotations> parameterTypes, | |||
ImmutableArray<RefKind> parameterRefKinds) | |||
ImmutableArray<RefKind> parameterRefKinds, | |||
ImmutableArray<DeclarationScope> parameterDeclarationScopes) |
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.
@@ -225,5 +225,28 @@ internal static bool IsValidUnscopedRefAttributeTarget(this MethodSymbol method) | |||
!method.IsConstructor() && | |||
!method.IsInitOnly; | |||
} | |||
|
|||
#nullable enable | |||
internal static ImmutableArray<DeclarationScope> GetByValueParameterDeclarationScopes(this MethodSymbol? method) |
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.
@@ -1054,6 +1094,7 @@ public static ReturnInferenceCacheKey Create(NamedTypeSymbol? delegateType, bool | |||
|
|||
parameterTypes = typesBuilder.ToImmutableAndFree(); | |||
parameterRefKinds = refKindsBuilder.ToImmutableAndFree(); | |||
parameterDeclarationScopes = MethodSymbolExtensions.GetByValueParameterDeclarationScopes(invoke); |
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.
{ | ||
return false; | ||
} | ||
} |
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.
return ParameterDeclarationScopes.SequenceEqual(other.ParameterDeclarationScopes);
#Closed
{ | ||
M2(r => r); | ||
M2((scoped R r) => r); // 1 | ||
} |
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.
{ | ||
void M() | ||
{ | ||
D1 d1 = () => r; |
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.
void M() | ||
{ | ||
D1 d1 = (scoped R r) => r; | ||
} |
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.
return this.ParameterDeclarationScopes.IsDefault == other.ParameterDeclarationScopes.IsDefault; | ||
} | ||
|
||
if (this.ParameterDeclarationScopes.Length != other.ParameterDeclarationScopes.Length) |
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.
@jcouv Is there a spec how this is supposed to work? |
{ | ||
Debug.Assert(parameterTypes.Length == parameterRefKinds.Length); | ||
Debug.Assert(parameterDeclaredScopes.IsDefault || parameterTypes.Length == parameterDeclaredScopes.Length); |
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.
Is there a spec how this is supposed to work?
I'll add spec change 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.
When all parameters are unscoped, we use a default
array.
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.
Created corresponding spec update: dotnet/csharplang#6551
|
||
static DeclarationScope getByValueParameterDeclaredScope(ParameterSymbol parameter) | ||
{ | ||
// For implicitly-typed lambda parameters, we only care about declaration scopes on by-value parameters. |
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.
If a parameter is ref
or out
then the parameters must have been explicitly-typed.
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 a parameter is ref or out then the parameters must have been explicitly-typed.
I am not sure I am following. We are looking at a method symbol. All parameters are explicitly typed for it.
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.
Still looking at other changes, I might get it at the end
@roslyn-compiler please ignore this message. Testing out a GitHub rule change. |
@@ -1502,7 +1502,7 @@ internal sealed class SourceComplexParameterSymbolWithCustomModifiersPrecedingRe | |||
SyntaxReference syntaxRef, | |||
bool isParams, | |||
bool isExtensionMethodThis, | |||
DeclarationScope scope) | |||
DeclarationScope? scope) |
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.
@@ -1479,7 +1479,7 @@ internal sealed class SourceComplexParameterSymbol : SourceComplexParameterSymbo | |||
SyntaxReference syntaxRef, | |||
bool isParams, | |||
bool isExtensionMethodThis, | |||
DeclarationScope scope) | |||
DeclarationScope? scope) |
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.
WithCustomModifiersAndParamsCore
copies this.DeclaredSymbol
(which is Nullable<DeclarationScope>
) using this constructor.
It similarly calls the SourceComplexParameterSymbolWithCustomModifiersPrecedingRef
constructor.
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.
WithCustomModifiersAndParamsCore()
should not be used for LambdaParameterSymbol
though. If it is, we'd presumably need to copy EffectiveScope
as well.
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.
WithCustomModifiersAndParamsCore
isn't used for lambdas. It's used for OHI scenarios.
var declaredScope = this.DeclaredScope; | ||
// DeclaredScope is only null in LambdaParameterSymbol where EffectiveScope can be provided rather than computed | ||
Debug.Assert(this.DeclaredScope is not null); | ||
var declaredScope = this.DeclaredScope.Value; |
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'd rather leave as-is. I thought this was nullable-enabled code.
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 9)
This reverts commit 5bf1a43.
Fixes #62080
Corresponding spec update: dotnet/csharplang#6551
Relates to test plan #59194 (ref fields)