Skip to content

Commit

Permalink
[parser] Better error message for >>> when not enabled in some cases …
Browse files Browse the repository at this point in the history
…(part 2)

#46886

Change-Id: I6195ad921f5c4b9622c735cb919c2d88f957f374
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/211820
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
  • Loading branch information
jensjoha authored and commit-bot@chromium.org committed Sep 1, 2021
1 parent 5881807 commit 1231e3d
Show file tree
Hide file tree
Showing 19 changed files with 885 additions and 31 deletions.
37 changes: 24 additions & 13 deletions pkg/_fe_analyzer_shared/lib/src/parser/parser_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4486,9 +4486,7 @@ class Parser {
begin = next = token.next!;
// Fall through to parse the block.
} else {
token = ensureBlock(
token,
codes.templateExpectedFunctionBody,
token = ensureBlock(token, codes.templateExpectedFunctionBody,
/* missingBlockName = */ null);
listener.handleInvalidFunctionBody(token);
return token.endGroup!;
Expand Down Expand Up @@ -4951,6 +4949,19 @@ class Parser {
// Right associative, so we recurse at the same precedence
// level.
Token next = token.next!;
if (optional(">=", next.next!)) {
// Special case use of triple-shift in cases where it isn't
// enabled.
reportRecoverableErrorWithEnd(
next,
next.next!,
codes.templateExperimentNotEnabled
.withArguments("triple-shift", "2.14"));
assert(next == operator);
next = rewriter.replaceNextTokensWithSyntheticToken(
token, 2, TokenType.GT_GT_GT_EQ);
operator = next;
}
token = optional('throw', next.next!)
? parseThrowExpression(next, /* allowCascades = */ false)
: parsePrecedenceExpression(next, level, allowCascades);
Expand Down Expand Up @@ -5041,18 +5052,10 @@ class Parser {
next.next!,
codes.templateExperimentNotEnabled
.withArguments("triple-shift", "2.14"));
assert(next == operator);
next = rewriter.replaceNextTokensWithSyntheticToken(
token, 2, TokenType.GT_GT_GT);
} else if (optional(">=", next.next!)) {
// Special case use of triple-shift in cases where it isn't
// enabled.
reportRecoverableErrorWithEnd(
next,
next.next!,
codes.templateExperimentNotEnabled
.withArguments("triple-shift", "2.14"));
next = rewriter.replaceNextTokensWithSyntheticToken(
token, 2, TokenType.GT_GT_GT_EQ);
operator = next;
}
}
listener.beginBinaryExpression(next);
Expand Down Expand Up @@ -5201,6 +5204,14 @@ class Parser {
return SELECTOR_PRECEDENCE;
}
return POSTFIX_PRECEDENCE;
} else if (identical(type, TokenType.GT_GT)) {
// ">>" followed by ">=" (without space between tokens) should for
// recovery be seen as ">>>=".
TokenType nextType = token.next!.type;
if (identical(nextType, TokenType.GT_EQ) &&
token.charEnd == token.next!.offset) {
return TokenType.GT_GT_GT_EQ.precedence;
}
} else if (identical(type, TokenType.QUESTION) &&
optional('[', token.next!)) {
// "?[" can be a null-aware bracket or a conditional. If it's a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ beginCompilationUnit(class)
handleRecoverableError(Message[ExperimentNotEnabled, This requires the 'triple-shift' language feature to be enabled., Try updating your pubspec.yaml to set the minimum SDK constraint to 2.14 or higher, and running 'pub get'., {string: triple-shift, string2: 2.14}], >>, >)
beginBinaryExpression(>>>)
handleLiteralInt(42)
endBinaryExpression(>>)
endBinaryExpression(>>>)
handleExpressionStatement(;)
handleIdentifier(print, expression)
handleNoTypeArguments(()
Expand All @@ -112,7 +112,7 @@ beginCompilationUnit(class)
handleRecoverableError(Message[ExperimentNotEnabled, This requires the 'triple-shift' language feature to be enabled., Try updating your pubspec.yaml to set the minimum SDK constraint to 2.14 or higher, and running 'pub get'., {string: triple-shift, string2: 2.14}], >>, >)
beginBinaryExpression(>>>)
handleLiteralInt(42)
endBinaryExpression(>>)
endBinaryExpression(>>>)
endArguments(1, (, ))
handleSend(print, ;)
handleExpressionStatement(;)
Expand All @@ -124,9 +124,8 @@ beginCompilationUnit(class)
handleNoArguments(>>)
handleSend(foo, >>)
handleRecoverableError(Message[ExperimentNotEnabled, This requires the 'triple-shift' language feature to be enabled., Try updating your pubspec.yaml to set the minimum SDK constraint to 2.14 or higher, and running 'pub get'., {string: triple-shift, string2: 2.14}], >>, >=)
beginBinaryExpression(>>>=)
handleLiteralInt(42)
endBinaryExpression(>>)
handleLiteralInt(42)
handleAssignmentExpression(>>>=)
endArguments(1, (, ))
handleSend(print, ;)
handleExpressionStatement(;)
Expand All @@ -136,9 +135,8 @@ beginCompilationUnit(class)
handleNoArguments(>>)
handleSend(foo, >>)
handleRecoverableError(Message[ExperimentNotEnabled, This requires the 'triple-shift' language feature to be enabled., Try updating your pubspec.yaml to set the minimum SDK constraint to 2.14 or higher, and running 'pub get'., {string: triple-shift, string2: 2.14}], >>, >=)
beginBinaryExpression(>>>=)
handleLiteralInt(42)
endBinaryExpression(>>)
handleLiteralInt(42)
handleAssignmentExpression(>>>=)
handleParenthesizedExpression(()
beginBinaryExpression(==)
handleIdentifier(foo, expression)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ parseUnit(class)
parsePrimary(>>>, expression)
parseLiteralInt(>>>)
listener: handleLiteralInt(42)
listener: endBinaryExpression(>>)
listener: endBinaryExpression(>>>)
ensureSemicolon(42)
listener: handleExpressionStatement(;)
notEofOrValue(}, print)
Expand Down Expand Up @@ -222,7 +222,7 @@ parseUnit(class)
parsePrimary(>>>, expression)
parseLiteralInt(>>>)
listener: handleLiteralInt(42)
listener: endBinaryExpression(>>)
listener: endBinaryExpression(>>>)
listener: endArguments(1, (, ))
listener: handleSend(print, ;)
ensureSemicolon())
Expand Down Expand Up @@ -264,13 +264,12 @@ parseUnit(class)
reportRecoverableErrorWithEnd(>>, >=, Message[ExperimentNotEnabled, This requires the 'triple-shift' language feature to be enabled., Try updating your pubspec.yaml to set the minimum SDK constraint to 2.14 or higher, and running 'pub get'., {string: triple-shift, string2: 2.14}])
listener: handleRecoverableError(Message[ExperimentNotEnabled, This requires the 'triple-shift' language feature to be enabled., Try updating your pubspec.yaml to set the minimum SDK constraint to 2.14 or higher, and running 'pub get'., {string: triple-shift, string2: 2.14}], >>, >=)
rewriter()
listener: beginBinaryExpression(>>>=)
parsePrecedenceExpression(>>>=, 13, true)
parsePrecedenceExpression(>>>=, 1, true)
parseUnaryExpression(>>>=, true)
parsePrimary(>>>=, expression)
parseLiteralInt(>>>=)
listener: handleLiteralInt(42)
listener: endBinaryExpression(>>)
listener: handleAssignmentExpression(>>>=)
listener: endArguments(1, (, ))
listener: handleSend(print, ;)
ensureSemicolon())
Expand Down Expand Up @@ -306,13 +305,12 @@ parseUnit(class)
reportRecoverableErrorWithEnd(>>, >=, Message[ExperimentNotEnabled, This requires the 'triple-shift' language feature to be enabled., Try updating your pubspec.yaml to set the minimum SDK constraint to 2.14 or higher, and running 'pub get'., {string: triple-shift, string2: 2.14}])
listener: handleRecoverableError(Message[ExperimentNotEnabled, This requires the 'triple-shift' language feature to be enabled., Try updating your pubspec.yaml to set the minimum SDK constraint to 2.14 or higher, and running 'pub get'., {string: triple-shift, string2: 2.14}], >>, >=)
rewriter()
listener: beginBinaryExpression(>>>=)
parsePrecedenceExpression(>>>=, 13, true)
parsePrecedenceExpression(>>>=, 1, true)
parseUnaryExpression(>>>=, true)
parsePrimary(>>>=, expression)
parseLiteralInt(>>>=)
listener: handleLiteralInt(42)
listener: endBinaryExpression(>>)
listener: handleAssignmentExpression(>>>=)
ensureCloseParen(42, ()
listener: handleParenthesizedExpression(()
listener: beginBinaryExpression(==)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
files:
- define_triple_shift_method.dart
- define_triple_shift_method_prime.dart
filters:
- ignoreListenerArguments
ignored:
- handleRecoverableError
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class Foo {
Foo operator >>(_) => this;
}

main() {
Foo foo = new Foo();
foo >> 42;
print(foo >> 42);
print(foo >>= 42);
if ((foo >>= 42) == foo) {
print("same");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
beginCompilationUnit(class)
beginMetadataStar(class)
endMetadataStar(0)
beginClassOrNamedMixinApplicationPrelude(class)
handleIdentifier(Foo, classOrMixinDeclaration)
handleNoTypeVariables({)
beginClassDeclaration(class, null, Foo)
handleNoType(Foo)
handleClassExtends(null, 1)
handleClassNoWithClause()
handleClassOrMixinImplements(null, 0)
handleClassHeader(class, class, null)
beginClassOrMixinBody(DeclarationKind.Class, {)
beginMetadataStar(Foo)
endMetadataStar(0)
beginMember()
beginMethod(null, null, null, null, null, operator)
handleIdentifier(Foo, typeReference)
handleNoTypeArguments(operator)
handleType(Foo, null)
handleOperatorName(operator, >>)
handleNoTypeVariables(()
beginFormalParameters((, MemberKind.NonStaticMethod)
beginMetadataStar(_)
endMetadataStar(0)
beginFormalParameter(_, MemberKind.NonStaticMethod, null, null, null)
handleNoType(()
handleIdentifier(_, formalParameterDeclaration)
handleFormalParameterWithoutValue())
endFormalParameter(null, null, _, null, null, FormalParameterKind.mandatory, MemberKind.NonStaticMethod)
endFormalParameters(1, (, ), MemberKind.NonStaticMethod)
handleNoInitializers()
handleAsyncModifier(null, null)
handleThisExpression(this, expression)
handleExpressionFunctionBody(=>, ;)
endClassMethod(null, Foo, (, null, ;)
endMember()
endClassOrMixinBody(DeclarationKind.Class, 1, {, })
endClassDeclaration(class, })
endTopLevelDeclaration(main)
beginMetadataStar(main)
endMetadataStar(0)
beginTopLevelMember(main)
beginTopLevelMethod(}, null)
handleNoType(})
handleIdentifier(main, topLevelFunctionDeclaration)
handleNoTypeVariables(()
beginFormalParameters((, MemberKind.TopLevelMethod)
endFormalParameters(0, (, ), MemberKind.TopLevelMethod)
handleAsyncModifier(null, null)
beginBlockFunctionBody({)
beginMetadataStar(Foo)
endMetadataStar(0)
handleIdentifier(Foo, typeReference)
handleNoTypeArguments(foo)
handleType(Foo, null)
beginVariablesDeclaration(foo, null, null)
handleIdentifier(foo, localVariableDeclaration)
beginInitializedIdentifier(foo)
beginVariableInitializer(=)
beginNewExpression(new)
handleIdentifier(Foo, constructorReference)
beginConstructorReference(Foo)
handleNoTypeArguments(()
handleNoConstructorReferenceContinuationAfterTypeArguments(()
endConstructorReference(Foo, null, (, ConstructorReferenceContext.New)
beginArguments(()
endArguments(0, (, ))
endNewExpression(new)
endVariableInitializer(=)
endInitializedIdentifier(foo)
endVariablesDeclaration(1, ;)
handleIdentifier(foo, expression)
handleNoTypeArguments(>>)
handleNoArguments(>>)
handleSend(foo, >>)
beginBinaryExpression(>>)
handleLiteralInt(42)
endBinaryExpression(>>)
handleExpressionStatement(;)
handleIdentifier(print, expression)
handleNoTypeArguments(()
beginArguments(()
handleIdentifier(foo, expression)
handleNoTypeArguments(>>)
handleNoArguments(>>)
handleSend(foo, >>)
beginBinaryExpression(>>)
handleLiteralInt(42)
endBinaryExpression(>>)
endArguments(1, (, ))
handleSend(print, ;)
handleExpressionStatement(;)
handleIdentifier(print, expression)
handleNoTypeArguments(()
beginArguments(()
handleIdentifier(foo, expression)
handleNoTypeArguments(>>=)
handleNoArguments(>>=)
handleSend(foo, >>=)
handleLiteralInt(42)
handleAssignmentExpression(>>=)
endArguments(1, (, ))
handleSend(print, ;)
handleExpressionStatement(;)
beginIfStatement(if)
handleIdentifier(foo, expression)
handleNoTypeArguments(>>=)
handleNoArguments(>>=)
handleSend(foo, >>=)
handleLiteralInt(42)
handleAssignmentExpression(>>=)
handleParenthesizedExpression(()
beginBinaryExpression(==)
handleIdentifier(foo, expression)
handleNoTypeArguments())
handleNoArguments())
handleSend(foo, ))
endBinaryExpression(==)
handleParenthesizedCondition(()
beginThenStatement({)
beginBlock({, BlockKind(statement))
handleIdentifier(print, expression)
handleNoTypeArguments(()
beginArguments(()
beginLiteralString("same")
endLiteralString(0, ))
endArguments(1, (, ))
handleSend(print, ;)
handleExpressionStatement(;)
endBlock(1, {, }, BlockKind(statement))
endThenStatement(})
endIfStatement(if, null)
endBlockFunctionBody(5, {, })
endTopLevelMethod(main, null, })
endTopLevelDeclaration()
endCompilationUnit(2, )
Loading

0 comments on commit 1231e3d

Please sign in to comment.