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>
39 lines
1.5 KiB
Plaintext
39 lines
1.5 KiB
Plaintext
Problems reported:
|
|
|
|
parser/patterns/patternVariableDeclaration_inClass:2:7: A pattern variable declaration may not appear outside a function or method.
|
|
var (a, b) = (0, 1);
|
|
^^^^^^
|
|
|
|
beginCompilationUnit(class)
|
|
beginMetadataStar(class)
|
|
endMetadataStar(0)
|
|
beginClassOrMixinOrNamedMixinApplicationPrelude(class)
|
|
handleIdentifier(C, classOrMixinDeclaration)
|
|
handleNoTypeVariables({)
|
|
beginClassDeclaration(class, null, null, null, null, null, null, null, null, null, C)
|
|
handleNoType(C)
|
|
handleClassExtends(null, 1)
|
|
handleClassNoWithClause()
|
|
handleImplements(null, 0)
|
|
handleClassHeader(class, class, null)
|
|
beginClassOrMixinOrExtensionBody(DeclarationKind.Class, {)
|
|
beginMetadataStar(var)
|
|
endMetadataStar(0)
|
|
beginMember()
|
|
handleRecoverableError(PatternVariableDeclarationOutsideFunctionOrMethod, (, ))
|
|
beginFields(DeclarationKind.Class, null, null, null, null, null, null, var, {)
|
|
handleNoType(var)
|
|
handleIdentifier(, fieldDeclaration)
|
|
beginFieldInitializer(=)
|
|
beginParenthesizedExpressionOrRecordLiteral(()
|
|
handleLiteralInt(0)
|
|
handleLiteralInt(1)
|
|
endRecordLiteral((, 2, null)
|
|
endFieldInitializer(=, ;)
|
|
endClassFields(null, null, null, null, null, null, var, 1, var, ;)
|
|
endMember()
|
|
endClassOrMixinOrExtensionBody(DeclarationKind.Class, 1, {, })
|
|
endClassDeclaration(class, })
|
|
endTopLevelDeclaration()
|
|
endCompilationUnit(1, )
|