analyzer: Report bare 'super' expression as ExpressionFunctionBody
Fixes https://github.com/dart-lang/sdk/issues/55525 Change-Id: Id6e1321d093b4b77f0504748e931db8f460c1b45 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/369122 Auto-Submit: Samuel Rawlins <srawlins@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
committed by
Commit Queue
parent
6e2ef10cde
commit
030b79dc1c
@@ -4196,6 +4196,7 @@ class AstBuilder extends StackListener {
|
||||
debugEvent("ExpressionFunctionBody");
|
||||
|
||||
var expression = pop() as ExpressionImpl;
|
||||
reportErrorIfSuper(expression);
|
||||
var star = pop() as Token?;
|
||||
var asyncKeyword = pop() as Token?;
|
||||
if (parseFunctionBodies) {
|
||||
|
||||
@@ -1865,6 +1865,18 @@ class Wrong<T> {
|
||||
parseExpression("x(y)(z).a++");
|
||||
}
|
||||
|
||||
void test_missingAssignableSelector_superAsExpressionFunctionBody() {
|
||||
CompilationUnit unit = parseCompilationUnit('main() => super;', errors: [
|
||||
error(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, 10, 5),
|
||||
]);
|
||||
var declaration = unit.declarations.first as FunctionDeclaration;
|
||||
var body = declaration.functionExpression.body as ExpressionFunctionBody;
|
||||
var expression = body.expression;
|
||||
expect(expression, isSuperExpression);
|
||||
var superExpression = expression as SuperExpression;
|
||||
expect(superExpression.superKeyword, isNotNull);
|
||||
}
|
||||
|
||||
void test_missingAssignableSelector_superPrimaryExpression() {
|
||||
CompilationUnit unit = parseCompilationUnit('main() {super;}', errors: [
|
||||
expectedError(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, 8, 5)
|
||||
|
||||
Reference in New Issue
Block a user