Skip to content

Commit 85d09eb

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
Issue 52387. Report an error for !super
Bug: #52387 Change-Id: I9893315b988c3096ea2d103f6a46f00ff0450afe Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303446 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]>
1 parent fef8185 commit 85d09eb

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

pkg/analyzer/lib/src/fasta/ast_builder.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5509,10 +5509,16 @@ class AstBuilder extends StackListener {
55095509
assert(operator.type.isUnaryPrefixOperator);
55105510
debugEvent("UnaryPrefixExpression");
55115511

5512+
final operand = pop() as ExpressionImpl;
5513+
if (!(operator.type == TokenType.MINUS ||
5514+
operator.type == TokenType.TILDE)) {
5515+
reportErrorIfSuper(operand);
5516+
}
5517+
55125518
push(
55135519
PrefixExpressionImpl(
55145520
operator: operator,
5515-
operand: pop() as ExpressionImpl,
5521+
operand: operand,
55165522
),
55175523
);
55185524
}

pkg/analyzer/test/generated/expression_parser_test.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2509,7 +2509,9 @@ class ExpressionParserTest extends FastaParserTestCase {
25092509
void test_parseUnaryExpression_not_super() {
25102510
PrefixExpression expression = parseUnaryExpression('!super');
25112511
expect(expression, isNotNull);
2512-
assertNoErrors();
2512+
assertErrors(errors: [
2513+
error(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, 1, 5),
2514+
]);
25132515
expect(expression.operator, isNotNull);
25142516
expect(expression.operator.type, TokenType.BANG);
25152517
expect(expression.operand, isNotNull);

pkg/analyzer/test/src/dart/resolution/prefix_expression_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,30 @@ PrefixExpression
5151
''');
5252
}
5353

54+
test_bang_super() async {
55+
await assertErrorsInCode(r'''
56+
class A {
57+
void f() {
58+
!super;
59+
}
60+
}
61+
''', [
62+
error(ParserErrorCode.MISSING_ASSIGNABLE_SELECTOR, 28, 5),
63+
error(CompileTimeErrorCode.NON_BOOL_NEGATION_EXPRESSION, 28, 5),
64+
]);
65+
66+
final node = findNode.singlePrefixExpression;
67+
assertResolvedNodeText(node, r'''
68+
PrefixExpression
69+
operator: !
70+
operand: SuperExpression
71+
superKeyword: super
72+
staticType: A
73+
staticElement: <null>
74+
staticType: bool
75+
''');
76+
}
77+
5478
test_formalParameter_inc_inc() async {
5579
await assertErrorsInCode(r'''
5680
void f(int x) {

0 commit comments

Comments
 (0)