Skip to content

Commit f8cdf13

Browse files
committed
dart-lang#1959. Test valid combinations of modifiers. Part 2
1 parent f052bbe commit f8cdf13

16 files changed

+957
-0
lines changed

LanguageFeatures/Class-modifiers/class_modifiers_lib.dart

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ typedef TypedefAbstractBaseMixinClass = AbstractBaseMixinClass;
3939
typedef TypedefMixin = Mixin;
4040
typedef TypedefBaseMixin = BaseMixin;
4141

42+
class ExtendsClass1 extends Class {}
43+
class ExtendsClass2 extends Class {}
44+
45+
base class BaseExtendsBaseClass1 extends BaseClass {}
46+
base class BaseExtendsBaseClass2 extends BaseClass {}
47+
48+
class ExtendsInterfaceClass1 extends InterfaceClass {} // reopen
49+
interface class ExtendsInterfaceClass2 extends InterfaceClass {}
50+
51+
final class ExtendsFinalClass1 extends FinalClass {}
52+
final class ExtendsFinalClass2 extends FinalClass {}
53+
4254
class ExtendsSealedClass extends SealedClass {}
4355
class ImplementsSealedClass implements SealedClass {}
4456
mixin MixinOnSealed on SealedClass {}
57+
58+
class ExtendsAbstractClass1 extends AbstractClass {}
59+
class ExtendsAbstractClass2 extends AbstractClass {}
60+
61+
ExtendsSealedClass extendsSealedClass = ExtendsSealedClass();
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract base class can be extended but not constructed,
6+
/// implemented or mixed in and is not exhaustive
7+
///
8+
/// @description Check that it is a compile-time error to construct an
9+
/// `abstract base class`
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=class-modifiers
13+
14+
import "class_modifiers_lib.dart";
15+
16+
abstract base class LocalAbstractBaseClass {}
17+
18+
abstract base class LocalAbstractBaseClassWithConstructor {
19+
LocalAbstractClassWithConstructor() {}
20+
}
21+
22+
main() {
23+
AbstractBaseClass();
24+
//^^^^^^^^^^^^^^^^^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
28+
LocalAbstractBaseClass();
29+
//^^^^^^^^^^^^^^^^^^^^^^
30+
// [analyzer] unspecified
31+
// [cfe] unspecified
32+
33+
LocalAbstractBaseClassWithConstructor();
34+
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
35+
// [analyzer] unspecified
36+
// [cfe] unspecified
37+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract base class can be extended but not constructed,
6+
/// implemented or mixed in and is not exhaustive
7+
///
8+
/// @description Check that it is not an error to extend an
9+
/// `abstract base class` (by `base/final/sealed`) or declare mixin `on` it, in
10+
/// the same library where it is defined
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=class-modifiers
14+
15+
abstract base class AbstractBaseClass {}
16+
17+
base class BaseClassExtendsAbstractBaseClass extends AbstractBaseClass {}
18+
19+
final class FinalClassExtendsAbstractBaseClass extends AbstractBaseClass {}
20+
21+
sealed class SealedClassExtendsAbstractBaseClass extends AbstractBaseClass {}
22+
23+
abstract base class AbstractBaseClassExtendsAbstractBaseClass
24+
extends AbstractBaseClass {}
25+
26+
abstract final class AbstractFinalClassExtendsAbstractBaseClass
27+
extends AbstractBaseClass {}
28+
29+
base mixin BaseMixinOnAbstractBaseClass on AbstractBaseClass {}
30+
31+
main() {
32+
print(BaseClassExtendsAbstractBaseClass);
33+
print(FinalClassExtendsAbstractBaseClass);
34+
print(SealedClassExtendsAbstractBaseClass);
35+
print(AbstractBaseClassExtendsAbstractBaseClass);
36+
print(AbstractFinalClassExtendsAbstractBaseClass);
37+
print(BaseMixinOnAbstractBaseClass);
38+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract base class can be extended but not constructed,
6+
/// implemented or mixed in and is not exhaustive
7+
///
8+
/// @description Check that it is not an error to extend an
9+
/// `abstract base class` (by `base/final/sealed`) or declare mixin `on` it,
10+
/// outside of the library where it is defined
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=class-modifiers
14+
15+
import "class_modifiers_lib.dart";
16+
17+
base class BaseClassExtendsAbstractBaseClass extends AbstractBaseClass {}
18+
19+
final class FinalClassExtendsAbstractBaseClass extends AbstractBaseClass {}
20+
21+
sealed class SealedClassExtendsAbstractBaseClass extends AbstractBaseClass {}
22+
23+
abstract base class AbstractBaseClassExtendsAbstractBaseClass
24+
extends AbstractBaseClass {}
25+
26+
abstract final class AbstractFinalClassExtendsAbstractBaseClass
27+
extends AbstractBaseClass {}
28+
29+
base mixin BaseMixinOnAbstractBaseClass on AbstractBaseClass {}
30+
31+
main() {
32+
print(BaseClassExtendsAbstractBaseClass);
33+
print(FinalClassExtendsAbstractBaseClass);
34+
print(SealedClassExtendsAbstractBaseClass);
35+
print(AbstractBaseClassExtendsAbstractBaseClass);
36+
print(AbstractFinalClassExtendsAbstractBaseClass);
37+
print(BaseMixinOnAbstractBaseClass);
38+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract base class can be extended but not constructed,
6+
/// implemented or mixed in and is not exhaustive
7+
///
8+
/// @description Check that it is not an error to implement an
9+
/// `abstract base class` (by `base/final/sealed`), in the same library where it
10+
/// is defined
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=class-modifiers
14+
15+
abstract base class AbstractBaseClass {}
16+
17+
base class BaseClassImplementsBaseClass implements AbstractBaseClass {}
18+
19+
final class FinalClassImplementsBaseClass implements AbstractBaseClass {}
20+
21+
sealed class SealedClassImplementsBaseClass implements AbstractBaseClass {}
22+
23+
abstract base class AbstractBaseClassImplementsBaseClass
24+
implements AbstractBaseClass {}
25+
26+
abstract final class AbstractFinalClassImplementsBaseClass
27+
implements AbstractBaseClass {}
28+
29+
base mixin class BaseMixinOnAbstractBaseClass implements AbstractBaseClass {}
30+
31+
abstract base mixin class AbstractBaseMixinOnAbstractBaseClass
32+
implements AbstractBaseClass {}
33+
34+
main() {
35+
print(BaseClassImplementsBaseClass);
36+
print(FinalClassImplementsBaseClass);
37+
print(SealedClassImplementsBaseClass);
38+
print(AbstractBaseClassImplementsBaseClass);
39+
print(AbstractFinalClassImplementsBaseClass);
40+
print(BaseMixinOnAbstractBaseClass);
41+
print(AbstractBaseMixinOnAbstractBaseClass);
42+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract base class can be extended but not constructed,
6+
/// implemented or mixed in and is not exhaustive
7+
///
8+
/// @description Checks that it is a compile-time error if an
9+
/// `abstract base class` is implemented outside of the library where it is
10+
/// defined
11+
/// @author [email protected]
12+
13+
// SharedOptions=--enable-experiment=class-modifiers
14+
15+
import "class_modifiers_lib.dart";
16+
17+
base class BaseClassImplementsAbstractBaseClass implements AbstractBaseClass {}
18+
// ^^^^^^^^^^^^^^^^^
19+
// [analyzer] unspecified
20+
// [cfe] unspecified
21+
22+
final class FinalClassImplementsAbstractBaseClass implements AbstractBaseClass {}
23+
// ^^^^^^^^^^^^^^^^^
24+
// [analyzer] unspecified
25+
// [cfe] unspecified
26+
27+
sealed class SealedClassImplementsAbstractBaseClass implements AbstractBaseClass {}
28+
// ^^^^^^^^^^^^^^^^^
29+
// [analyzer] unspecified
30+
// [cfe] unspecified
31+
32+
abstract base class AbstractBaseClassImplementsAbstractBaseClass implements AbstractBaseClass {}
33+
// ^^^^^^^^^^^^^^^^^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
37+
abstract final class AbstractFinalClassImplementsAbstractBaseClass implements AbstractBaseClass {}
38+
// ^^^^^^^^^^^^^^^^^
39+
// [analyzer] unspecified
40+
// [cfe] unspecified
41+
42+
base mixin class BaseMixinOnAbstractBaseClass implements AbstractBaseClass {}
43+
// ^^^^^^^^^^^^^^^^^
44+
// [analyzer] unspecified
45+
// [cfe] unspecified
46+
47+
abstract base mixin class AbstractBaseMixinOnAbstractBaseClass implements AbstractBaseClass {}
48+
// ^^^^^^^^^^^^^^^^^
49+
// [analyzer] unspecified
50+
// [cfe] unspecified
51+
52+
main() {
53+
print(BaseClassImplementsAbstractBaseClass);
54+
print(FinalClassImplementsAbstractBaseClass);
55+
print(SealedClassImplementsAbstractBaseClass);
56+
print(AbstractBaseClassImplementsAbstractBaseClass);
57+
print(AbstractFinalClassImplementsAbstractBaseClass);
58+
print(BaseMixinOnAbstractBaseClass);
59+
print(AbstractBaseMixinOnAbstractBaseClass);
60+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract base class can be extended but not constructed,
6+
/// implemented or mixed in and is not exhaustive
7+
///
8+
/// @description Checks that it is a compile-time error if an
9+
/// `abstract base class` is mixed in in the same library where it is defined
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=class-modifiers
13+
14+
abstract base class AbstractBaseClass {}
15+
16+
base class BaseClassWithAbstractBaseClass1 with AbstractBaseClass {}
17+
// ^^^^^^^^^^^^^^^^^
18+
// [analyzer] unspecified
19+
// [cfe] unspecified
20+
21+
base class BaseClassWithAbstractBaseClass2 = Object with AbstractBaseClass;
22+
// ^^^^^^^^^^^^^^^^^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
26+
final class FinalClassWithAbstractBaseClass1 with AbstractBaseClass {}
27+
// ^^^^^^^^^^^^^^^^^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
31+
final class FinalClassWithAbstractBaseClass2 = Object with AbstractBaseClass;
32+
// ^^^^^^^^^^^^^^^^^
33+
// [analyzer] unspecified
34+
// [cfe] unspecified
35+
36+
sealed class SealedClassWithAbstractBaseClass1 with AbstractBaseClass {}
37+
// ^^^^^^^^^^^^^^^^^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
41+
sealed class SealedClassWithAbstractBaseClass2 = Object with AbstractBaseClass;
42+
// ^^^^^^^^^^^^^^^^^
43+
// [analyzer] unspecified
44+
// [cfe] unspecified
45+
46+
abstract base class AbstractBaseClassWithAbstractBaseClass1 with AbstractBaseClass {}
47+
// ^^^^^^^^^^^^^^^^^
48+
// [analyzer] unspecified
49+
// [cfe] unspecified
50+
51+
abstract base class AbstractBaseClassWithAbstractBaseClass2 = Object with AbstractBaseClass;
52+
// ^^^^^^^^^^^^^^^^^
53+
// [analyzer] unspecified
54+
// [cfe] unspecified
55+
56+
abstract final class AbstractFinalClassWithAbstractBaseClass1 with AbstractBaseClass {}
57+
// ^^^^^^^^^^^^^^^^^
58+
// [analyzer] unspecified
59+
// [cfe] unspecified
60+
61+
abstract final class AbstractFinalClassWithAbstractBaseClass2 = Object with AbstractBaseClass;
62+
// ^^^^^^^^^^^^^^^^^
63+
// [analyzer] unspecified
64+
// [cfe] unspecified
65+
66+
main() {
67+
print(BaseClassWithAbstractBaseClass1);
68+
print(BaseClassWithAbstractBaseClass2);
69+
print(FinalClassWithAbstractBaseClass1);
70+
print(FinalClassWithAbstractBaseClass2);
71+
print(SealedClassWithAbstractBaseClass1);
72+
print(SealedClassWithAbstractBaseClass2);
73+
print(AbstractBaseClassWithAbstractBaseClass1);
74+
print(AbstractBaseClassWithAbstractBaseClass2);
75+
print(AbstractFinalClassWithAbstractBaseClass1);
76+
print(AbstractFinalClassWithAbstractBaseClass2);
77+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Abstract base class can be extended but not constructed,
6+
/// implemented or mixed in and is not exhaustive
7+
///
8+
/// @description Checks that it is a compile-time error if an
9+
/// `abstract base class` is mixed in outside of the library where it is defined
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=class-modifiers
13+
14+
import "class_modifiers_lib.dart";
15+
16+
base class BaseClassWithAbstractBaseClass1 with AbstractBaseClass {}
17+
// ^^^^^^^^^^^^^^^^^
18+
// [analyzer] unspecified
19+
// [cfe] unspecified
20+
21+
base class BaseClassWithAbstractBaseClass2 = Object with AbstractBaseClass;
22+
// ^^^^^^^^^^^^^^^^^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
26+
final class FinalClassWithAbstractBaseClass1 with AbstractBaseClass {}
27+
// ^^^^^^^^^^^^^^^^^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
31+
final class FinalClassWithAbstractBaseClass2 = Object with AbstractBaseClass;
32+
// ^^^^^^^^^^^^^^^^^
33+
// [analyzer] unspecified
34+
// [cfe] unspecified
35+
36+
sealed class SealedClassWithAbstractBaseClass1 with AbstractBaseClass {}
37+
// ^^^^^^^^^^^^^^^^^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
41+
sealed class SealedClassWithAbstractBaseClass2 = Object with AbstractBaseClass;
42+
// ^^^^^^^^^^^^^^^^^
43+
// [analyzer] unspecified
44+
// [cfe] unspecified
45+
46+
abstract base class AbstractBaseClassWithAbstractBaseClass1 with AbstractBaseClass {}
47+
// ^^^^^^^^^^^^^^^^^
48+
// [analyzer] unspecified
49+
// [cfe] unspecified
50+
51+
abstract base class AbstractBaseClassWithAbstractBaseClass2 = Object with AbstractBaseClass;
52+
// ^^^^^^^^^^^^^^^^^
53+
// [analyzer] unspecified
54+
// [cfe] unspecified
55+
56+
abstract final class AbstractFinalClassWithAbstractBaseClass1 with AbstractBaseClass {}
57+
// ^^^^^^^^^^^^^^^^^
58+
// [analyzer] unspecified
59+
// [cfe] unspecified
60+
61+
abstract final class AbstractFinalClassWithAbstractBaseClass2 = Object with AbstractBaseClass;
62+
// ^^^^^^^^^^^^^^^^^
63+
// [analyzer] unspecified
64+
// [cfe] unspecified
65+
66+
main() {
67+
print(BaseClassWithAbstractBaseClass1);
68+
print(BaseClassWithAbstractBaseClass2);
69+
print(FinalClassWithAbstractBaseClass1);
70+
print(FinalClassWithAbstractBaseClass2);
71+
print(SealedClassWithAbstractBaseClass1);
72+
print(SealedClassWithAbstractBaseClass2);
73+
print(AbstractBaseClassWithAbstractBaseClass1);
74+
print(AbstractBaseClassWithAbstractBaseClass2);
75+
print(AbstractFinalClassWithAbstractBaseClass1);
76+
print(AbstractFinalClassWithAbstractBaseClass2);
77+
}

0 commit comments

Comments
 (0)