-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patterns parsing: make it an error to use
var
before a type in a va…
…riable pattern. Bug: #50035 Change-Id: I46b23ef0d1856401eac4b0a05c6bc6008711d35a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291780 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Jens Johansen <[email protected]>
- Loading branch information
1 parent
de2abc6
commit 134007a
Showing
34 changed files
with
1,170 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...t_end/parser_testcases/patterns/declaredVariable_inPatternAssignment_usingVarAndType.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
void f() { | ||
[a, var int d] = y; | ||
} |
36 changes: 36 additions & 0 deletions
36
...arser_testcases/patterns/declaredVariable_inPatternAssignment_usingVarAndType.dart.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
Problems reported: | ||
|
||
parser/patterns/declaredVariable_inPatternAssignment_usingVarAndType:2:15: Variable 'd' can't be declared in a pattern assignment. | ||
[a, var int d] = y; | ||
^ | ||
|
||
beginCompilationUnit(void) | ||
beginMetadataStar(void) | ||
endMetadataStar(0) | ||
beginTopLevelMember(void) | ||
beginTopLevelMethod(, null, null) | ||
handleVoidKeyword(void) | ||
handleIdentifier(f, topLevelFunctionDeclaration) | ||
handleNoTypeVariables(() | ||
beginFormalParameters((, MemberKind.TopLevelMethod) | ||
endFormalParameters(0, (, ), MemberKind.TopLevelMethod) | ||
handleAsyncModifier(null, null) | ||
beginBlockFunctionBody({) | ||
handleNoTypeArguments([) | ||
handleAssignedVariablePattern(a) | ||
handleIdentifier(int, typeReference) | ||
handleNoTypeArguments(d) | ||
handleType(int, null) | ||
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) | ||
handleDeclaredVariablePattern(var, d, true) | ||
handleListPattern(2, [, ]) | ||
handleIdentifier(y, expression) | ||
handleNoTypeArguments(;) | ||
handleNoArguments(;) | ||
handleSend(y, ;) | ||
handlePatternAssignment(=) | ||
handleExpressionStatement(;) | ||
endBlockFunctionBody(1, {, }) | ||
endTopLevelMethod(void, null, }) | ||
endTopLevelDeclaration() | ||
endCompilationUnit(1, ) |
81 changes: 81 additions & 0 deletions
81
...ses/patterns/declaredVariable_inPatternAssignment_usingVarAndType.dart.intertwined.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
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: handleIdentifier(int, typeReference) | ||
listener: handleNoTypeArguments(d) | ||
listener: handleType(int, null) | ||
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(var, 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, ) |
9 changes: 9 additions & 0 deletions
9
...estcases/patterns/declaredVariable_inPatternAssignment_usingVarAndType.dart.parser.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
void f() { | ||
[a, var int d] = y; | ||
} | ||
|
||
|
||
void[KeywordToken] f[StringToken]([BeginToken])[SimpleToken] {[BeginToken] | ||
[[BeginToken]a[StringToken],[SimpleToken] var[KeywordToken] int[StringToken] d[StringToken]][SimpleToken] =[SimpleToken] y[StringToken];[SimpleToken] | ||
}[SimpleToken] | ||
[SimpleToken] |
9 changes: 9 additions & 0 deletions
9
...stcases/patterns/declaredVariable_inPatternAssignment_usingVarAndType.dart.scanner.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
void f() { | ||
[a, var int d] = y; | ||
} | ||
|
||
|
||
void[KeywordToken] f[StringToken]([BeginToken])[SimpleToken] {[BeginToken] | ||
[[BeginToken]a[StringToken],[SimpleToken] var[KeywordToken] int[StringToken] d[StringToken]][SimpleToken] =[SimpleToken] y[StringToken];[SimpleToken] | ||
}[SimpleToken] | ||
[SimpleToken] |
3 changes: 3 additions & 0 deletions
3
...nt_end/parser_testcases/patterns/varKeywordInTypedVariablePattern_declarationContext.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
void f(int x) { | ||
var (var int y) = x; | ||
} |
44 changes: 44 additions & 0 deletions
44
...parser_testcases/patterns/varKeywordInTypedVariablePattern_declarationContext.dart.expect
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
Problems reported: | ||
|
||
parser/patterns/varKeywordInTypedVariablePattern_declarationContext:2:8: Variable patterns in declaration context can't specify 'var' or 'final' keyword. | ||
var (var int y) = x; | ||
^^^ | ||
|
||
beginCompilationUnit(void) | ||
beginMetadataStar(void) | ||
endMetadataStar(0) | ||
beginTopLevelMember(void) | ||
beginTopLevelMethod(, null, null) | ||
handleVoidKeyword(void) | ||
handleIdentifier(f, topLevelFunctionDeclaration) | ||
handleNoTypeVariables(() | ||
beginFormalParameters((, MemberKind.TopLevelMethod) | ||
beginMetadataStar(int) | ||
endMetadataStar(0) | ||
beginFormalParameter(int, MemberKind.TopLevelMethod, null, null, null) | ||
handleIdentifier(int, typeReference) | ||
handleNoTypeArguments(x) | ||
handleType(int, null) | ||
handleIdentifier(x, formalParameterDeclaration) | ||
handleFormalParameterWithoutValue()) | ||
endFormalParameter(null, null, null, x, null, null, FormalParameterKind.requiredPositional, MemberKind.TopLevelMethod) | ||
endFormalParameters(1, (, ), MemberKind.TopLevelMethod) | ||
handleAsyncModifier(null, null) | ||
beginBlockFunctionBody({) | ||
beginMetadataStar(var) | ||
endMetadataStar(0) | ||
handleIdentifier(int, typeReference) | ||
handleNoTypeArguments(y) | ||
handleType(int, null) | ||
handleRecoverableError(VariablePatternKeywordInDeclarationContext, var, var) | ||
handleDeclaredVariablePattern(var, y, false) | ||
handleParenthesizedPattern(() | ||
handleIdentifier(x, expression) | ||
handleNoTypeArguments(;) | ||
handleNoArguments(;) | ||
handleSend(x, ;) | ||
handlePatternVariableDeclarationStatement(var, =, ;) | ||
endBlockFunctionBody(1, {, }) | ||
endTopLevelMethod(void, null, }) | ||
endTopLevelDeclaration() | ||
endCompilationUnit(1, ) |
Oops, something went wrong.