Files
sdk/pkg/front_end/parser_testcases/patterns/patternVariableDeclaration_topLevel.dart.expect
T
Paul Berry 8aa48712be Patterns parsing: recover from patternVariableDeclaration non-statement.
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>
2023-04-04 14:55:00 +00:00

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, )