Skip to content
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

Fix issue parsing collection literal containing lambdas #68734

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11782,9 +11782,20 @@ private bool IsPossibleLambdaExpression(Precedence precedence)

using var _ = this.GetDisposableResetPoint(resetOnDispose: true);

// A lambda could be starting with attributes, attempt to skip past them and check after that point.
if (CurrentToken.Kind == SyntaxKind.OpenBracketToken)
{
ParseAttributeDeclarations(inExpressionContext: true);
// Subtle case to deal with. Consider:
//
// [X, () => {} vs:
// [X] () => {}
CyrusNajmabadi marked this conversation as resolved.
Show resolved Hide resolved
//
// The former is a collection expression, the latter an attributed-lambda. However, we will likely
// successfully parse out `[X,` as an incomplete attribute, and thus think the former is the latter. So,
// to ensure proper parsing of the collection expressions, bail out if the attribute is not complete.
var attributeDeclarations = ParseAttributeDeclarations(inExpressionContext: true);
if (attributeDeclarations is [.., { CloseBracketToken.IsMissing: true }])
return false;
}

bool seenStatic;
Expand Down
Loading