8aa48712be
Previously, if a pattern variable declaration appeared outside of a function or method, the parser would get very confused. Now it recognizes the situation, issues a comprehensible error message, and replaces the pattern with a synthetic identifier token so that the analyzer AST is somewhat sensible. Fixes #51322. Bug: https://github.com/dart-lang/sdk/issues/51322 Change-Id: Ica5f060cb483a39c4e50942d639939b1fab40bea Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293087 Reviewed-by: Johnni Winther <johnniwinther@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
24 lines
860 B
Plaintext
24 lines
860 B
Plaintext
Problems reported:
|
|
|
|
parser/patterns/patternVariableDeclaration_topLevel:1:5: A pattern variable declaration may not appear outside a function or method.
|
|
var (a, b) = (0, 1);
|
|
^^^^^^
|
|
|
|
beginCompilationUnit(var)
|
|
beginMetadataStar(var)
|
|
endMetadataStar(0)
|
|
beginTopLevelMember(var)
|
|
handleRecoverableError(PatternVariableDeclarationOutsideFunctionOrMethod, (, ))
|
|
beginFields(DeclarationKind.TopLevel, null, null, null, null, null, null, var, )
|
|
handleNoType(var)
|
|
handleIdentifier(, topLevelVariableDeclaration)
|
|
beginFieldInitializer(=)
|
|
beginParenthesizedExpressionOrRecordLiteral(()
|
|
handleLiteralInt(0)
|
|
handleLiteralInt(1)
|
|
endRecordLiteral((, 2, null)
|
|
endFieldInitializer(=, ;)
|
|
endTopLevelFields(null, null, null, null, var, 1, var, ;)
|
|
endTopLevelDeclaration()
|
|
endCompilationUnit(1, )
|