104ac30cf4
The listener API for variable patterns is split into three separate functions, to handle the three separate behaviors: - `handleAssignedVariablePattern` for variable names appearing in an assignment context (these assign to an existing variable upon a successful match). - `handleDeclaredVariablePattern` for variable declarations appearing in a declaration or matching context (these cause a new variable name to come into scope). - `handleWildcardPattern` for wildcards in any context (these don't capture the matched value). Also, responsibility is shifted to the parser for reporting the following error conditions: - VariablePatternKeywordInDeclarationContext (e.g. `var (var x) = ...;`) - PatternAssignmentDeclaresVariable (e.g. `[x, var y] = ...;`) Previously these errors were detected by the implementations, and weren't fully covering all possible error scenarios. In the case of VariablePatternKeywordInDeclarationContext, the listener method `handleDeclaredVariablePattern` is called instead of `handleAssignedVariablePattern`. This ensures that no tokens are dropped from the analyzer AST. The CFE uses the `inAssignmentPattern` argument of `handleDeclaredVariablePattern` to distinguish this error recovery case from a legitimate declared variable pattern. Fixes #51868. Bug: https://github.com/dart-lang/sdk/issues/51868 Change-Id: I28ec679b73d64033166721c6460be35f15e23171 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291583 Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
80 lines
5.0 KiB
Plaintext
80 lines
5.0 KiB
Plaintext
parseUnit(void)
|
|
skipErrorTokens(void)
|
|
listener: beginCompilationUnit(void)
|
|
syntheticPreviousToken(void)
|
|
parseTopLevelDeclarationImpl(, Instance of 'DirectiveContext')
|
|
parseMetadataStar()
|
|
listener: beginMetadataStar(void)
|
|
listener: endMetadataStar(0)
|
|
parseTopLevelMemberImpl()
|
|
listener: beginTopLevelMember(void)
|
|
parseTopLevelMethod(, null, null, , Instance of 'VoidType', null, f, false)
|
|
listener: beginTopLevelMethod(, null, null)
|
|
listener: handleVoidKeyword(void)
|
|
ensureIdentifierPotentiallyRecovered(void, topLevelFunctionDeclaration, false)
|
|
listener: handleIdentifier(f, topLevelFunctionDeclaration)
|
|
parseMethodTypeVar(f)
|
|
listener: handleNoTypeVariables(()
|
|
parseGetterOrFormalParameters(f, f, false, MemberKind.TopLevelMethod)
|
|
parseFormalParameters(f, MemberKind.TopLevelMethod)
|
|
parseFormalParametersRest((, MemberKind.TopLevelMethod)
|
|
listener: beginFormalParameters((, MemberKind.TopLevelMethod)
|
|
listener: endFormalParameters(0, (, ), MemberKind.TopLevelMethod)
|
|
parseAsyncModifierOpt())
|
|
listener: handleAsyncModifier(null, null)
|
|
inPlainSync()
|
|
parseFunctionBody(), false, false)
|
|
listener: beginBlockFunctionBody({)
|
|
notEofOrValue(}, [)
|
|
parseStatement({)
|
|
parseStatementX({)
|
|
parseExpressionStatementOrDeclaration({, null)
|
|
parseExpressionStatementOrDeclarationAfterModifiers({, {, null, null, null, null)
|
|
looksLikeLocalFunction([)
|
|
parseExpressionStatement({)
|
|
parseExpression({)
|
|
looksLikeOuterPatternEquals({)
|
|
skipOuterPattern({)
|
|
parsePatternAssignment({)
|
|
parsePattern({, PatternContext.assignment, precedence: 1)
|
|
parsePrimaryPattern({, PatternContext.assignment)
|
|
listener: handleNoTypeArguments([)
|
|
parseListPatternSuffix({, PatternContext.assignment)
|
|
parsePattern([, PatternContext.assignment, precedence: 1)
|
|
parsePrimaryPattern([, PatternContext.assignment)
|
|
parseVariablePattern([, PatternContext.assignment, typeInfo: Instance of 'NoType')
|
|
listener: handleAssignedVariablePattern(a)
|
|
parsePattern(,, PatternContext.assignment, precedence: 1)
|
|
parsePrimaryPattern(,, PatternContext.assignment)
|
|
parseVariablePattern(,, PatternContext.assignment, typeInfo: Instance of 'NoType')
|
|
listener: handleNoType(final)
|
|
reportRecoverableError(d, Message[PatternAssignmentDeclaresVariable, Variable 'd' can't be declared in a pattern assignment., Try using a preexisting variable or changing the assignment to a pattern variable declaration., {name: d}])
|
|
listener: handleRecoverableError(Message[PatternAssignmentDeclaresVariable, Variable 'd' can't be declared in a pattern assignment., Try using a preexisting variable or changing the assignment to a pattern variable declaration., {name: d}], d, d)
|
|
listener: handleDeclaredVariablePattern(final, d, true)
|
|
listener: handleListPattern(2, [, ])
|
|
parseExpression(=)
|
|
looksLikeOuterPatternEquals(=)
|
|
skipOuterPattern(=)
|
|
skipObjectPatternRest(y)
|
|
parsePrecedenceExpression(=, 1, true, ConstantPatternContext.none)
|
|
parseUnaryExpression(=, true, ConstantPatternContext.none)
|
|
parsePrimary(=, expression, ConstantPatternContext.none)
|
|
parseSendOrFunctionLiteral(=, expression, ConstantPatternContext.none)
|
|
parseSend(=, expression, ConstantPatternContext.none)
|
|
isNextIdentifier(=)
|
|
ensureIdentifier(=, expression)
|
|
listener: handleIdentifier(y, expression)
|
|
listener: handleNoTypeArguments(;)
|
|
parseArgumentsOpt(y)
|
|
listener: handleNoArguments(;)
|
|
listener: handleSend(y, ;)
|
|
listener: handlePatternAssignment(=)
|
|
ensureSemicolon(y)
|
|
listener: handleExpressionStatement(;)
|
|
notEofOrValue(}, })
|
|
listener: endBlockFunctionBody(1, {, })
|
|
listener: endTopLevelMethod(void, null, })
|
|
listener: endTopLevelDeclaration()
|
|
reportAllErrorTokens(void)
|
|
listener: endCompilationUnit(1, )
|