Skip to content

Commit a3b1126

Browse files
committed
Augment. Enable a few hierarchy tests, add more.
Change-Id: I24df92334408ee04f4fe638200561c63b4fd4ce7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507266 Reviewed-by: Paul Berry <paulberry@google.com>
1 parent fa9895b commit a3b1126

8 files changed

Lines changed: 338 additions & 9 deletions

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

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,56 @@ augment class B extends A {}
4444
''');
4545
}
4646

47+
test_alreadyPresent2_part() async {
48+
var a = getFile('$testPackageLibPath/a.dart');
49+
var b = getFile('$testPackageLibPath/b.dart');
50+
51+
await resolveFilesWithDiagnostics({
52+
a: r'''
53+
part 'b.dart';
54+
55+
class A {}
56+
57+
class B extends A {}
58+
// ^
59+
// [context 1] The declaration being augmented.
60+
61+
augment class B {}
62+
''',
63+
b: r'''
64+
part of 'a.dart';
65+
66+
augment class B extends A {}
67+
// ^^^^^^^
68+
// [diag.augmentationExtendsClauseAlreadyPresent][context 1] The augmentation has an 'extends' clause, but an augmentation target already includes an 'extends' clause and it isn't allowed to be repeated or changed.
69+
''',
70+
});
71+
}
72+
73+
test_alreadyPresent_part() async {
74+
var a = getFile('$testPackageLibPath/a.dart');
75+
var b = getFile('$testPackageLibPath/b.dart');
76+
77+
await resolveFilesWithDiagnostics({
78+
a: r'''
79+
part 'b.dart';
80+
81+
class A {}
82+
83+
class B extends A {}
84+
// ^
85+
// [context 1] The declaration being augmented.
86+
''',
87+
b: r'''
88+
part of 'a.dart';
89+
90+
augment class B extends A {}
91+
// ^^^^^^^
92+
// [diag.augmentationExtendsClauseAlreadyPresent][context 1] The augmentation has an 'extends' clause, but an augmentation target already includes an 'extends' clause and it isn't allowed to be repeated or changed.
93+
''',
94+
});
95+
}
96+
4797
test_notPresent() async {
4898
await resolveTestCodeWithDiagnostics(r'''
4999
class A {}

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,39 @@ main() {
1616

1717
@reflectiveTest
1818
class ConflictingGenericInterfacesTest extends PubPackageResolutionTest {
19-
@SkippedTest() // TODO(scheglov): implement augmentation
2019
test_class_extends_augmentation_implements() async {
2120
await resolveTestCodeWithDiagnostics('''
2221
class I<T> {}
2322
class A implements I<int> {}
2423
class B extends A {}
24+
// ^
25+
// [diag.conflictingGenericInterfaces] The class 'B' can't implement both 'I<int>' and 'I<String>' because the type arguments are different.
2526
augment class B implements I<String> {}
2627
''');
2728
}
2829

30+
test_class_extends_augmentation_implements_part() async {
31+
var a = getFile('$testPackageLibPath/a.dart');
32+
var b = getFile('$testPackageLibPath/b.dart');
33+
34+
await resolveFilesWithDiagnostics({
35+
a: r'''
36+
part 'b.dart';
37+
38+
class I<T> {}
39+
class A implements I<int> {}
40+
class B extends A {}
41+
// ^
42+
// [diag.conflictingGenericInterfaces] The class 'B' can't implement both 'I<int>' and 'I<String>' because the type arguments are different.
43+
''',
44+
b: r'''
45+
part of 'a.dart';
46+
47+
augment class B implements I<String> {}
48+
''',
49+
});
50+
}
51+
2952
test_class_extends_implements() async {
3053
await resolveTestCodeWithDiagnostics('''
3154
class I<T> {}

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

Lines changed: 91 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,37 @@ ImplementsClause
4040
''');
4141
}
4242

43-
@SkippedTest() // TODO(scheglov): implement augmentation
4443
test_class_implements_2times_augmentation() async {
4544
await resolveTestCodeWithDiagnostics(r'''
4645
class A {}
4746
class B implements A {}
4847
augment class B implements A {}
48+
// ^
49+
// [diag.implementsRepeated] 'A' can only be implemented once.
4950
''');
5051
}
5152

53+
test_class_implements_2times_augmentation_part() async {
54+
var a = getFile('$testPackageLibPath/a.dart');
55+
var b = getFile('$testPackageLibPath/b.dart');
56+
57+
await resolveFilesWithDiagnostics({
58+
a: r'''
59+
part 'b.dart';
60+
61+
class A {}
62+
class B implements A {}
63+
''',
64+
b: r'''
65+
part of 'a.dart';
66+
67+
augment class B implements A {}
68+
// ^
69+
// [diag.implementsRepeated] 'A' can only be implemented once.
70+
''',
71+
});
72+
}
73+
5274
test_class_implements_2times_viaTypeAlias() async {
5375
var result = await resolveTestCodeWithDiagnostics(r'''
5476
class A {}
@@ -114,15 +136,37 @@ ImplementsClause
114136
''');
115137
}
116138

117-
@SkippedTest() // TODO(scheglov): implement augmentation
118139
test_enum_implements_2times_augmentation() async {
119140
await resolveTestCodeWithDiagnostics(r'''
120141
class A {}
121142
enum E implements A {v}
122143
augment enum E implements A {}
144+
// ^
145+
// [diag.implementsRepeated] 'A' can only be implemented once.
123146
''');
124147
}
125148

149+
test_enum_implements_2times_augmentation_part() async {
150+
var a = getFile('$testPackageLibPath/a.dart');
151+
var b = getFile('$testPackageLibPath/b.dart');
152+
153+
await resolveFilesWithDiagnostics({
154+
a: r'''
155+
part 'b.dart';
156+
157+
class A {}
158+
enum E implements A {v}
159+
''',
160+
b: r'''
161+
part of 'a.dart';
162+
163+
augment enum E implements A {}
164+
// ^
165+
// [diag.implementsRepeated] 'A' can only be implemented once.
166+
''',
167+
});
168+
}
169+
126170
test_enum_implements_2times_viaTypeAlias() async {
127171
var result = await resolveTestCodeWithDiagnostics(r'''
128172
class A {}
@@ -189,14 +233,35 @@ ImplementsClause
189233
''');
190234
}
191235

192-
@SkippedTest() // TODO(scheglov): implement augmentation
193236
test_extensionType_implements_2times_augmentation() async {
194237
await resolveTestCodeWithDiagnostics(r'''
195238
extension type A(int it) implements int {}
196239
augment extension type A implements int {}
240+
// ^^^
241+
// [diag.implementsRepeated] 'int' can only be implemented once.
197242
''');
198243
}
199244

245+
test_extensionType_implements_2times_augmentation_part() async {
246+
var a = getFile('$testPackageLibPath/a.dart');
247+
var b = getFile('$testPackageLibPath/b.dart');
248+
249+
await resolveFilesWithDiagnostics({
250+
a: r'''
251+
part 'b.dart';
252+
253+
extension type A(int it) implements int {}
254+
''',
255+
b: r'''
256+
part of 'a.dart';
257+
258+
augment extension type A implements int {}
259+
// ^^^
260+
// [diag.implementsRepeated] 'int' can only be implemented once.
261+
''',
262+
});
263+
}
264+
200265
test_extensionType_implements_2times_viaTypeAlias() async {
201266
var result = await resolveTestCodeWithDiagnostics(r'''
202267
typedef A = int;
@@ -243,15 +308,37 @@ mixin M implements A, A {}
243308
''');
244309
}
245310

246-
@SkippedTest() // TODO(scheglov): implement augmentation
247311
test_mixin_implements_2times_augmentation() async {
248312
await resolveTestCodeWithDiagnostics(r'''
249313
class A {}
250314
mixin M implements A {}
251315
augment mixin M implements A {}
316+
// ^
317+
// [diag.implementsRepeated] 'A' can only be implemented once.
252318
''');
253319
}
254320

321+
test_mixin_implements_2times_augmentation_part() async {
322+
var a = getFile('$testPackageLibPath/a.dart');
323+
var b = getFile('$testPackageLibPath/b.dart');
324+
325+
await resolveFilesWithDiagnostics({
326+
a: r'''
327+
part 'b.dart';
328+
329+
class A {}
330+
mixin M implements A {}
331+
''',
332+
b: r'''
333+
part of 'a.dart';
334+
335+
augment mixin M implements A {}
336+
// ^
337+
// [diag.implementsRepeated] 'A' can only be implemented once.
338+
''',
339+
});
340+
}
341+
255342
test_mixin_implements_4times() async {
256343
await resolveTestCodeWithDiagnostics(r'''
257344
class A {}

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

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,68 @@ class B extends A implements A {}
2323
''');
2424
}
2525

26+
test_class_extendsThenAugmentsImplements() async {
27+
await resolveTestCodeWithDiagnostics(r'''
28+
class A {}
29+
class B extends A {}
30+
augment class B implements A {}
31+
// ^
32+
// [diag.implementsSuperClass] 'class A' can't be used in both the 'extends' and 'implements' clauses.
33+
''');
34+
}
35+
36+
test_class_extendsThenAugmentsImplements_part() async {
37+
var a = getFile('$testPackageLibPath/a.dart');
38+
var b = getFile('$testPackageLibPath/b.dart');
39+
40+
await resolveFilesWithDiagnostics({
41+
a: r'''
42+
part 'b.dart';
43+
44+
class A {}
45+
class B extends A {}
46+
''',
47+
b: r'''
48+
part of 'a.dart';
49+
50+
augment class B implements A {}
51+
// ^
52+
// [diag.implementsSuperClass] 'class A' can't be used in both the 'extends' and 'implements' clauses.
53+
''',
54+
});
55+
}
56+
57+
test_class_implementsThenAugmentsExtends() async {
58+
await resolveTestCodeWithDiagnostics(r'''
59+
class A {}
60+
class B implements A {}
61+
// ^
62+
// [diag.implementsSuperClass] 'class A' can't be used in both the 'extends' and 'implements' clauses.
63+
augment class B extends A {}
64+
''');
65+
}
66+
67+
test_class_implementsThenAugmentsExtends_part() async {
68+
var a = getFile('$testPackageLibPath/a.dart');
69+
var b = getFile('$testPackageLibPath/b.dart');
70+
71+
await resolveFilesWithDiagnostics({
72+
a: r'''
73+
part 'b.dart';
74+
75+
class A {}
76+
class B implements A {}
77+
// ^
78+
// [diag.implementsSuperClass] 'class A' can't be used in both the 'extends' and 'implements' clauses.
79+
''',
80+
b: r'''
81+
part of 'a.dart';
82+
83+
augment class B extends A {}
84+
''',
85+
});
86+
}
87+
2688
test_class_Object() async {
2789
await resolveTestCodeWithDiagnostics(r'''
2890
class A implements Object {}

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

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,39 @@ class C extends Object with M {}
6363
''');
6464
}
6565

66-
@SkippedTest() // TODO(scheglov): implement augmentation
6766
test_class_noMatchingInterface_fromAugmentation() async {
6867
await resolveTestCodeWithDiagnostics('''
6968
class B with M {}
69+
// ^
70+
// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'Object' because 'Object' doesn't implement 'A'.
7071
mixin M {}
7172
class A {}
7273
augment mixin M on A {}
7374
''');
7475
}
7576

77+
test_class_noMatchingInterface_fromAugmentation_part() async {
78+
var a = getFile('$testPackageLibPath/a.dart');
79+
var b = getFile('$testPackageLibPath/b.dart');
80+
81+
await resolveFilesWithDiagnostics({
82+
a: r'''
83+
part 'b.dart';
84+
85+
class B with M {}
86+
// ^
87+
// [diag.mixinApplicationNotImplementedInterface] 'M' can't be mixed onto 'Object' because 'Object' doesn't implement 'A'.
88+
mixin M {}
89+
class A {}
90+
''',
91+
b: r'''
92+
part of 'a.dart';
93+
94+
augment mixin M on A {}
95+
''',
96+
});
97+
}
98+
7699
test_class_noMatchingInterface_withTypeArguments() async {
77100
await resolveTestCodeWithDiagnostics('''
78101
abstract class A<T> {}
@@ -280,7 +303,6 @@ enum E with M {
280303
''');
281304
}
282305

283-
@SkippedTest() // TODO(scheglov): implement augmentation
284306
test_enum_noSuperclassConstraint_augmented() async {
285307
await resolveTestCodeWithDiagnostics(r'''
286308
mixin M {}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ MixinOnClause
4343
''');
4444
}
4545

46-
@SkippedTest() // TODO(scheglov): implement augmentation
4746
test_in_inAugmentation() async {
4847
await resolveTestCodeWithDiagnostics(r'''
4948
mixin A {}
5049
augment mixin A on int {}
50+
// ^^^
51+
// [diag.mixinSuperClassConstraintDisallowedClass] 'int' can't be used as a superclass constraint.
5152
''');
5253
}
5354

0 commit comments

Comments
 (0)