Skip to content

Commit 8a5ddec

Browse files
pqCommit Queue
authored and
Commit Queue
committed
+ extension type target kind (and @optionalTypeArgs support)
Adds a new TargetKind for extension types and adds it to `@optionalTypeArgs`. Change-Id: I7254c1299c296451b9adc5d1f8eceb50af66f039 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/324769 Commit-Queue: Phil Quitslund <[email protected]> Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent dd970ba commit 8a5ddec

File tree

7 files changed

+44
-0
lines changed

7 files changed

+44
-0
lines changed

pkg/analysis_server/test/mock_packages/meta/lib/meta.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ class _NonVirtual {
518518
@Target({
519519
TargetKind.classType,
520520
TargetKind.extension,
521+
TargetKind.extensionType,
521522
TargetKind.function,
522523
TargetKind.method,
523524
TargetKind.mixinType,

pkg/analysis_server/test/mock_packages/meta/lib/meta_meta.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class TargetKind {
3939
/// Indicates that an annotation is valid on any extension declaration.
4040
static const extension = TargetKind._('extensions', 'extension');
4141

42+
/// Indicates that an annotation is valid on any extension type declaration.
43+
static const extensionType = TargetKind._('extension types', 'extensionType');
44+
4245
/// Indicates that an annotation is valid on any field declaration, both
4346
/// instance and static fields, whether it's in a class, mixin or extension.
4447
static const field = TargetKind._('fields', 'field');
@@ -91,6 +94,7 @@ class TargetKind {
9194
classType,
9295
enumType,
9396
extension,
97+
extensionType,
9498
field,
9599
function,
96100
library,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -554,6 +554,8 @@ class AnnotationVerifier {
554554
} else if (target is EnumDeclaration) {
555555
return kinds.contains(TargetKind.enumType) ||
556556
kinds.contains(TargetKind.type);
557+
} else if (target is ExtensionTypeDeclaration) {
558+
return kinds.contains(TargetKind.extensionType);
557559
} else if (target is ExtensionDeclaration) {
558560
return kinds.contains(TargetKind.extension);
559561
} else if (target is FieldDeclaration) {

pkg/analyzer/lib/src/test_utilities/mock_packages.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ class _NonVirtual {
238238
@Target({
239239
TargetKind.classType,
240240
TargetKind.extension,
241+
TargetKind.extensionType,
241242
TargetKind.function,
242243
TargetKind.method,
243244
TargetKind.mixinType,
@@ -284,6 +285,7 @@ class TargetKind {
284285
static const classType = TargetKind._('classes', 'classType');
285286
static const enumType = TargetKind._('enums', 'enumType');
286287
static const extension = TargetKind._('extensions', 'extension');
288+
static const extensionType = TargetKind._('extension types', 'extensionType');
287289
static const field = TargetKind._('fields', 'field');
288290
static const function = TargetKind._('top-level functions', 'function');
289291
static const library = TargetKind._('libraries', 'library');
@@ -302,6 +304,7 @@ class TargetKind {
302304
classType,
303305
enumType,
304306
extension,
307+
extensionType,
305308
field,
306309
function,
307310
library,

pkg/linter/test/rules/always_specify_types_test.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,38 @@ main() {
1414

1515
@reflectiveTest
1616
class AlwaysSpecifyTypesTest extends LintRuleTest {
17+
@override
18+
bool get addMetaPackageDep => true;
19+
1720
@override
1821
String get lintRule => 'always_specify_types';
1922

23+
test_extensionType_optionalTypeArgs() async {
24+
await assertNoDiagnostics(r'''
25+
import 'package:meta/meta.dart';
26+
27+
@optionalTypeArgs
28+
extension type E<T>(int i) { }
29+
30+
void f() {
31+
E e = E(1);
32+
}
33+
''');
34+
}
35+
36+
test_extensionType_typeArgs() async {
37+
await assertDiagnostics(r'''
38+
extension type E<T>(int i) { }
39+
40+
void f() {
41+
E e = E(1);
42+
}
43+
''', [
44+
lint(45, 1),
45+
lint(51, 1),
46+
]);
47+
}
48+
2049
test_listPattern_destructured() async {
2150
await assertDiagnostics(r'''
2251
f() {

pkg/meta/lib/meta.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ class _NonVirtual {
518518
@Target({
519519
TargetKind.classType,
520520
TargetKind.extension,
521+
TargetKind.extensionType,
521522
TargetKind.function,
522523
TargetKind.method,
523524
TargetKind.mixinType,

pkg/meta/lib/meta_meta.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ class TargetKind {
3939
/// Indicates that an annotation is valid on any extension declaration.
4040
static const extension = TargetKind._('extensions', 'extension');
4141

42+
/// Indicates that an annotation is valid on any extension type declaration.
43+
static const extensionType = TargetKind._('extension types', 'extensionType');
44+
4245
/// Indicates that an annotation is valid on any field declaration, both
4346
/// instance and static fields, whether it's in a class, mixin or extension.
4447
static const field = TargetKind._('fields', 'field');
@@ -91,6 +94,7 @@ class TargetKind {
9194
classType,
9295
enumType,
9396
extension,
97+
extensionType,
9498
field,
9599
function,
96100
library,

0 commit comments

Comments
 (0)