Skip to content

Commit

Permalink
Fix issue parsing collection literal containing lambdas
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Jun 22, 2023
1 parent 6bd8524 commit e371b40
Show file tree
Hide file tree
Showing 2 changed files with 611 additions and 1 deletion.
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] () => {}
//
// 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

0 comments on commit e371b40

Please sign in to comment.