-
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.
Additional test cases in support of record/variable pattern disambigu…
…ation. Two of these tests (`recordPattern_nullable_beforeAs` and `recordPattern_nullable_beforeWhen`) verify that the fix for #52439 (Destructuring with explicit type of nullable record is a parsing error), which causes `(...)? identifier` to be recognized as a variable pattern, doesn't get confused by the pseudo-identifiers `as` and `when`, and so it continues to correctly parse `(...)? as ...` as a cast pattern and `(...)? when ...` as a guarded pattern. The other two tests (`recordPattern_nonNullable_beforeAs` and `recordPattern_nonNullable_beforeWhen`) verify that `(...) as ...` and `(...) when ...` are parsed correctly. These forms were never broken, but they were not well tested either. Bug: #52439 Change-Id: I866e1c7a6a8e47e0cd91a1a77654405f395b50da Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305844 Reviewed-by: Jens Johansen <jensj@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
- Loading branch information
1 parent
cf07d75
commit 76f803a
Showing
21 changed files
with
911 additions
and
0 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
5 changes: 5 additions & 0 deletions
5
pkg/front_end/parser_testcases/patterns/recordPattern_nonNullable_beforeAs.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,5 @@ | ||
void f(x) { | ||
switch (x) { | ||
case (_,) as (Object,): | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
pkg/front_end/parser_testcases/patterns/recordPattern_nonNullable_beforeAs.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,58 @@ | ||
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) | ||
beginPattern(case) | ||
beginPattern(() | ||
handleNoType(_) | ||
handleWildcardPattern(null, _) | ||
endPattern(_) | ||
handlePatternField(null) | ||
handleRecordPattern((, 1) | ||
beginAsOperatorType(as) | ||
beginRecordType(() | ||
beginRecordTypeEntry() | ||
beginMetadataStar(Object) | ||
endMetadataStar(0) | ||
handleIdentifier(Object, typeReference) | ||
handleNoTypeArguments(,) | ||
handleType(Object, null) | ||
handleNoName(,) | ||
endRecordTypeEntry() | ||
endRecordType((, null, 1, false) | ||
endAsOperatorType(as) | ||
handleCastPattern(as) | ||
endPattern()) | ||
handleSwitchCaseNoWhenClause()) | ||
endCaseExpression(case, null, :) | ||
beginSwitchCase(0, 1, case) | ||
endSwitchCase(0, 1, null, null, 0, case, }) | ||
endSwitchBlock(1, {, }) | ||
endSwitchStatement(switch, }) | ||
endBlockFunctionBody(1, {, }) | ||
endTopLevelMethod(void, null, }) | ||
endTopLevelDeclaration() | ||
endCompilationUnit(1, ) |
116 changes: 116 additions & 0 deletions
116
..._end/parser_testcases/patterns/recordPattern_nonNullable_beforeAs.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,116 @@ | ||
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) | ||
parseFormalParameter((, FormalParameterKind.requiredPositional, MemberKind.TopLevelMethod) | ||
parseMetadataStar(() | ||
listener: beginMetadataStar(x) | ||
listener: endMetadataStar(0) | ||
listener: beginFormalParameter(x, MemberKind.TopLevelMethod, null, null, null) | ||
listener: handleNoType(() | ||
ensureIdentifier((, formalParameterDeclaration) | ||
listener: handleIdentifier(x, formalParameterDeclaration) | ||
listener: handleFormalParameterWithoutValue()) | ||
listener: endFormalParameter(null, null, null, x, null, null, FormalParameterKind.requiredPositional, MemberKind.TopLevelMethod) | ||
listener: endFormalParameters(1, (, ), MemberKind.TopLevelMethod) | ||
parseAsyncModifierOpt()) | ||
listener: handleAsyncModifier(null, null) | ||
inPlainSync() | ||
parseFunctionBody(), false, false) | ||
listener: beginBlockFunctionBody({) | ||
notEofOrValue(}, switch) | ||
parseStatement({) | ||
parseStatementX({) | ||
parseSwitchStatement({) | ||
listener: beginSwitchStatement(switch) | ||
ensureParenthesizedCondition(switch, allowCase: false) | ||
parseExpressionInParenthesisRest((, allowCase: false) | ||
parseExpression(() | ||
looksLikeOuterPatternEquals(() | ||
skipOuterPattern(() | ||
skipObjectPatternRest(x) | ||
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(x, expression) | ||
listener: handleNoTypeArguments()) | ||
parseArgumentsOpt(x) | ||
listener: handleNoArguments()) | ||
listener: handleSend(x, )) | ||
ensureCloseParen(x, () | ||
listener: handleParenthesizedCondition((, null, null) | ||
parseSwitchBlock()) | ||
ensureBlock(), null, switch statement) | ||
listener: beginSwitchBlock({) | ||
notEofOrValue(}, case) | ||
peekPastLabels(case) | ||
listener: beginCaseExpression(case) | ||
parsePattern(case, PatternContext.matching, precedence: 1) | ||
listener: beginPattern(case) | ||
parsePrimaryPattern(case, PatternContext.matching) | ||
parseParenthesizedPatternOrRecordPattern(case, PatternContext.matching) | ||
parsePattern((, PatternContext.matching, precedence: 1) | ||
listener: beginPattern(() | ||
parsePrimaryPattern((, PatternContext.matching) | ||
parseVariablePattern((, PatternContext.matching, typeInfo: Instance of 'NoType') | ||
listener: handleNoType(_) | ||
listener: handleWildcardPattern(null, _) | ||
listener: endPattern(_) | ||
listener: handlePatternField(null) | ||
ensureCloseParen(,, () | ||
listener: handleRecordPattern((, 1) | ||
listener: beginAsOperatorType(as) | ||
computeTypeAfterIsOrAs(as) | ||
parseRecordType((, as, false) | ||
listener: beginRecordType(() | ||
parseRecordTypeField((, identifierIsOptional: true) | ||
listener: beginRecordTypeEntry() | ||
parseMetadataStar(() | ||
listener: beginMetadataStar(Object) | ||
listener: endMetadataStar(0) | ||
listener: handleIdentifier(Object, typeReference) | ||
listener: handleNoTypeArguments(,) | ||
listener: handleType(Object, null) | ||
listener: handleNoName(,) | ||
listener: endRecordTypeEntry() | ||
listener: endRecordType((, null, 1, false) | ||
listener: endAsOperatorType(as) | ||
listener: handleCastPattern(as) | ||
listener: endPattern()) | ||
listener: handleSwitchCaseNoWhenClause()) | ||
ensureColon()) | ||
listener: endCaseExpression(case, null, :) | ||
peekPastLabels(}) | ||
parseStatementsInSwitchCase(:, }, case, 0, 1, null, null) | ||
listener: beginSwitchCase(0, 1, case) | ||
listener: endSwitchCase(0, 1, null, null, 0, case, }) | ||
notEofOrValue(}, }) | ||
listener: endSwitchBlock(1, {, }) | ||
listener: endSwitchStatement(switch, }) | ||
notEofOrValue(}, }) | ||
listener: endBlockFunctionBody(1, {, }) | ||
listener: endTopLevelMethod(void, null, }) | ||
listener: endTopLevelDeclaration() | ||
reportAllErrorTokens(void) | ||
listener: endCompilationUnit(1, ) |
13 changes: 13 additions & 0 deletions
13
...front_end/parser_testcases/patterns/recordPattern_nonNullable_beforeAs.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,13 @@ | ||
void f(x) { | ||
switch (x) { | ||
case (_,) as (Object,): | ||
} | ||
} | ||
|
||
|
||
void[KeywordToken] f[StringToken]([BeginToken]x[StringToken])[SimpleToken] {[BeginToken] | ||
switch[KeywordToken] ([BeginToken]x[StringToken])[SimpleToken] {[BeginToken] | ||
case[KeywordToken] ([BeginToken]_[StringToken],[SimpleToken])[SimpleToken] as[KeywordToken] ([BeginToken]Object[StringToken],[SimpleToken])[SimpleToken]:[SimpleToken] | ||
}[SimpleToken] | ||
}[SimpleToken] | ||
[SimpleToken] |
13 changes: 13 additions & 0 deletions
13
...ront_end/parser_testcases/patterns/recordPattern_nonNullable_beforeAs.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,13 @@ | ||
void f(x) { | ||
switch (x) { | ||
case (_,) as (Object,): | ||
} | ||
} | ||
|
||
|
||
void[KeywordToken] f[StringToken]([BeginToken]x[StringToken])[SimpleToken] {[BeginToken] | ||
switch[KeywordToken] ([BeginToken]x[StringToken])[SimpleToken] {[BeginToken] | ||
case[KeywordToken] ([BeginToken]_[StringToken],[SimpleToken])[SimpleToken] as[KeywordToken] ([BeginToken]Object[StringToken],[SimpleToken])[SimpleToken]:[SimpleToken] | ||
}[SimpleToken] | ||
}[SimpleToken] | ||
[SimpleToken] |
5 changes: 5 additions & 0 deletions
5
pkg/front_end/parser_testcases/patterns/recordPattern_nonNullable_beforeWhen.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,5 @@ | ||
void f(x) { | ||
switch (x) { | ||
case (_,) when true: | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
pkg/front_end/parser_testcases/patterns/recordPattern_nonNullable_beforeWhen.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,47 @@ | ||
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) | ||
beginPattern(case) | ||
beginPattern(() | ||
handleNoType(_) | ||
handleWildcardPattern(null, _) | ||
endPattern(_) | ||
handlePatternField(null) | ||
handleRecordPattern((, 1) | ||
endPattern()) | ||
beginSwitchCaseWhenClause(when) | ||
handleLiteralBool(true) | ||
endSwitchCaseWhenClause(true) | ||
endCaseExpression(case, when, :) | ||
beginSwitchCase(0, 1, case) | ||
endSwitchCase(0, 1, null, null, 0, case, }) | ||
endSwitchBlock(1, {, }) | ||
endSwitchStatement(switch, }) | ||
endBlockFunctionBody(1, {, }) | ||
endTopLevelMethod(void, null, }) | ||
endTopLevelDeclaration() | ||
endCompilationUnit(1, ) |
Oops, something went wrong.