Skip to content

Commit 725de4e

Browse files
pqCommit Queue
authored and
Commit Queue
committed
validate @mustBeOverridden on extension type methods
See: #53434 Change-Id: Ibeab460fa8cc9d7e7fa0efdb062c839659243e45 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324574 Reviewed-by: Samuel Rawlins <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 4176e16 commit 725de4e

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pkg/analyzer/lib/src/error/annotation_verifier.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,7 @@ class AnnotationVerifier {
210210
if ((parent is MethodDeclaration && parent.isStatic) ||
211211
(parent is FieldDeclaration && parent.isStatic) ||
212212
parent.parent is ExtensionDeclaration ||
213+
parent.parent is ExtensionTypeDeclaration ||
213214
parent.parent is EnumDeclaration) {
214215
_errorReporter.reportErrorForNode(
215216
WarningCode.INVALID_ANNOTATION_TARGET,

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,19 @@ extension E on String {
157157
]);
158158
}
159159

160+
test_extensionType_instance_method() async {
161+
await assertErrorsInCode(r'''
162+
import 'package:meta/meta.dart';
163+
164+
extension type E(int i) {
165+
@mustBeOverridden
166+
void m() { }
167+
}
168+
''', [
169+
error(WarningCode.INVALID_ANNOTATION_TARGET, 62, 17),
170+
]);
171+
}
172+
160173
test_mixin_instance_method() async {
161174
await assertNoErrorsInCode(r'''
162175
import 'package:meta/meta.dart';

0 commit comments

Comments
 (0)