Skip to content

Commit 52b0285

Browse files
srawlinscommit-bot@chromium.org
authored andcommitted
Analyzer: Gather operator super calls for mustCallSuper
Fixes #27896 Change-Id: I7017026346a92ffc43a3cfa506f7a257af1a3471 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164421 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent ea20802 commit 52b0285

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5395,6 +5395,14 @@ class HiddenElements {
53955395
class _InvocationCollector extends RecursiveAstVisitor<void> {
53965396
final List<String> superCalls = <String>[];
53975397

5398+
@override
5399+
void visitBinaryExpression(BinaryExpression node) {
5400+
if (node.leftOperand is SuperExpression) {
5401+
superCalls.add(node.operator.lexeme);
5402+
}
5403+
super.visitBinaryExpression(node);
5404+
}
5405+
53985406
@override
53995407
void visitMethodInvocation(MethodInvocation node) {
54005408
if (node.target is SuperExpression) {

pkg/analyzer/test/src/diagnostics/must_call_super_test.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,36 @@ class B extends A {
8282
''');
8383
}
8484

85+
test_fromExtendingClass_operator() async {
86+
await assertErrorsInCode(r'''
87+
import 'package:meta/meta.dart';
88+
class A {
89+
@mustCallSuper
90+
operator ==(Object o) => o is A;
91+
}
92+
class B extends A {
93+
@override
94+
operator ==(Object o) => o is B;
95+
}
96+
''', [
97+
error(HintCode.MUST_CALL_SUPER, 140, 2),
98+
]);
99+
}
100+
101+
test_fromExtendingClass_operator_containsSuperCall() async {
102+
await assertNoErrorsInCode(r'''
103+
import 'package:meta/meta.dart';
104+
class A {
105+
@mustCallSuper
106+
operator ==(Object o) => o is A;
107+
}
108+
class B extends A {
109+
@override
110+
operator ==(Object o) => o is B && super == o;
111+
}
112+
''');
113+
}
114+
85115
test_fromInterface() async {
86116
await assertNoErrorsInCode(r'''
87117
import 'package:meta/meta.dart';

0 commit comments

Comments
 (0)