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>
44 lines
1.7 KiB
Plaintext
44 lines
1.7 KiB
Plaintext
beginCompilationUnit(void)
|
|
beginMetadataStar(void)
|
|
endMetadataStar(0)
|
|
beginTopLevelMember(void)
|
|
beginTopLevelMethod(, null, null)
|
|
handleVoidKeyword(void)
|
|
handleIdentifier(f, topLevelFunctionDeclaration)
|
|
handleNoTypeVariables(()
|
|
beginFormalParameters((, MemberKind.TopLevelMethod)
|
|
beginMetadataStar(x)
|
|
endMetadataStar(0)
|
|
beginFormalParameter(x, MemberKind.TopLevelMethod, null, null, null)
|
|
handleNoType(()
|
|
handleIdentifier(x, formalParameterDeclaration)
|
|
handleFormalParameterWithoutValue())
|
|
endFormalParameter(null, null, null, x, null, null, FormalParameterKind.requiredPositional, MemberKind.TopLevelMethod)
|
|
endFormalParameters(1, (, ), MemberKind.TopLevelMethod)
|
|
handleAsyncModifier(null, null)
|
|
beginBlockFunctionBody({)
|
|
beginSwitchStatement(switch)
|
|
handleIdentifier(x, expression)
|
|
handleNoTypeArguments())
|
|
handleNoArguments())
|
|
handleSend(x, ))
|
|
handleParenthesizedCondition((, null, null)
|
|
beginSwitchBlock({)
|
|
beginCaseExpression(case)
|
|
handleNoTypeArguments({)
|
|
handleNoType(var)
|
|
handleDeclaredVariablePattern(var, y, false)
|
|
handleRestPattern(..., true)
|
|
handleMapPattern(1, {, })
|
|
handleSwitchCaseNoWhenClause(})
|
|
endCaseExpression(case, null, :)
|
|
beginSwitchCase(0, 1, case)
|
|
handleBreakStatement(false, break, ;)
|
|
endSwitchCase(0, 1, null, null, 1, case, })
|
|
endSwitchBlock(1, {, })
|
|
endSwitchStatement(switch, })
|
|
endBlockFunctionBody(1, {, })
|
|
endTopLevelMethod(void, null, })
|
|
endTopLevelDeclaration()
|
|
endCompilationUnit(1, )
|