-
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
Disallow 'var' as an explicit lambda expression return type #56911
Conversation
var resetPoint = this.GetResetPoint(); | ||
try | ||
{ | ||
returnType = ParseReturnType(); | ||
if (CurrentToken.Kind != SyntaxKind.OpenParenToken) | ||
if (!IsVarType()) |
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.
Perhaps even in binding.
Done with review pass (commit 2) |
@@ -12787,6 +12787,12 @@ LambdaExpressionSyntax parseLambdaExpressionWorker() | |||
arrow = CheckFeatureAvailability(arrow, MessageID.IDS_FeatureLambda); | |||
var (block, expression) = ParseLambdaBody(); | |||
|
|||
// Disallow 'var' as explicit return type. | |||
if ((returnType as IdentifierNameSyntax)?.Identifier.ContextualKind == SyntaxKind.VarKeyword) |
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 verify(string source, ParseOptions? parseOptions = null) | ||
{ | ||
UsingDeclaration(source, parseOptions, | ||
// (1,9): error CS1031: Type expected |
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.
Perhaps error CS0825: The contextual keyword 'var' may only appear within a local variable declaration or in script code
is suitable. SharpLab
Moved PR to target |
|
||
// Breaking change from C#9 which binds calls to F(Func<Func<object>>, int). | ||
// | ||
// The calls such as F(() => () => 1, 2) should be considered ambiguous in C#9 as per the C# spec. |
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.
@@ -248,6 +248,11 @@ static void checkAttributes(AnonymousFunctionExpressionSyntax syntax, SyntaxList | |||
MessageID.IDS_FeatureLambdaReturnType.CheckFeatureAvailability(diagnostics, syntax); | |||
|
|||
syntax = syntax.SkipRef(out RefKind refKind); | |||
if ((syntax as IdentifierNameSyntax)?.Identifier.ContextualKind() == SyntaxKind.VarKeyword) | |||
{ | |||
diagnostics.Add(ErrorCode.ERR_LambdaExplicitReturnTypeVar, syntax.Location); |
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.
Probably should document as breaking change in 17.1 #Pending
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.
Does the spec capture that design decision?
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've added an item to the breaking changes document. I'll update the spec in a subsequent PR.
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 Thanks (iteration 7) modulo documentation questions
{ | ||
static void Main() | ||
{ | ||
F(var (var v) => v); |
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.
Perhaps there is a mismatch in source for VerifyDiagnostics below.
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)
See LDM-2021-06-02 notes.
Relates to #52192