Skip to content

Commit c9923e2

Browse files
committed
dart-lang#1959. More basic and mixin restrictions tests
1 parent c01fbd7 commit c9923e2

6 files changed

+464
-0
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
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 An enum declaration still cannot be implemented, extended or
6+
/// mixed in anywhere, independently of modifiers.
7+
///
8+
/// @description Check that it is a compile-time error if an enum declaration is
9+
/// extended or used in mixin's `on` part
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=class-modifiers
13+
14+
enum E {e1, e2}
15+
16+
class ExtendsEnum extends E {}
17+
// ^
18+
// [analyzer] unspecified
19+
// [cfe] unspecified
20+
21+
base class BaseExtendsEnum extends E {}
22+
// ^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
26+
interface class InterfaceExtendsEnum extends E {}
27+
// ^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
31+
final class FinalExtendsEnum extends E {}
32+
// ^
33+
// [analyzer] unspecified
34+
// [cfe] unspecified
35+
36+
sealed class SealedExtendsEnum extends E {}
37+
// ^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
41+
abstract class AbstractExtendsEnum extends E {}
42+
// ^
43+
// [analyzer] unspecified
44+
// [cfe] unspecified
45+
46+
abstract base class AbstractBaseExtendsEnum extends E {}
47+
// ^
48+
// [analyzer] unspecified
49+
// [cfe] unspecified
50+
51+
52+
abstract interface class AbstractInterfaceExtendsEnum extends E {}
53+
// ^
54+
// [analyzer] unspecified
55+
// [cfe] unspecified
56+
57+
abstract final class AbstractFinalExtendsEnum extends E {}
58+
// ^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
62+
mixin MixinOnEnum on E {}
63+
// ^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
66+
67+
base mixin BaseMixinOnEnum on E {}
68+
// ^
69+
// [analyzer] unspecified
70+
// [cfe] unspecified
71+
72+
main() {
73+
print(ExtendsEnum);
74+
print(BaseExtendsEnum);
75+
print(InterfaceExtendsEnum);
76+
print(FinalExtendsEnum);
77+
print(SealedExtendsEnum);
78+
print(AbstractExtendsEnum);
79+
print(AbstractBaseExtendsEnum);
80+
print(AbstractInterfaceExtendsEnum);
81+
print(AbstractFinalExtendsEnum);
82+
print(MixinOnEnum);
83+
print(BaseMixinOnEnum);
84+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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 An enum declaration still cannot be implemented, extended or
6+
/// mixed in anywhere, independently of modifiers.
7+
///
8+
/// @description Check that it is a compile-time error if an enum declaration is
9+
/// implemented
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=class-modifiers
13+
14+
enum E {e1, e2}
15+
16+
class ImplementsEnum implements E {}
17+
// ^
18+
// [analyzer] unspecified
19+
// [cfe] unspecified
20+
21+
base class BaseImplementsEnum implements E {}
22+
// ^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
26+
interface class InterfaceImplementsEnum implements E {}
27+
// ^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
31+
final class FinalImplementsEnum implements E {}
32+
// ^
33+
// [analyzer] unspecified
34+
// [cfe] unspecified
35+
36+
sealed class SealedImplementsEnum implements E {}
37+
// ^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
41+
abstract class AbstractImplementsEnum implements E {}
42+
// ^
43+
// [analyzer] unspecified
44+
// [cfe] unspecified
45+
46+
abstract base class AbstractBaseImplementsEnum implements E {}
47+
// ^
48+
// [analyzer] unspecified
49+
// [cfe] unspecified
50+
51+
52+
abstract interface class AbstractInterfaceImplementsEnum implements E {}
53+
// ^
54+
// [analyzer] unspecified
55+
// [cfe] unspecified
56+
57+
abstract final class AbstractFinalImplementsEnum implements E {}
58+
// ^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
62+
mixin class MixinClassImplementsEnum implements E {}
63+
// ^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
66+
67+
base mixin class BaseMixinClassImplementsEnum implements E {}
68+
// ^
69+
// [analyzer] unspecified
70+
// [cfe] unspecified
71+
72+
abstract mixin class AbstractMixinClassImplementsEnum implements E {}
73+
// ^
74+
// [analyzer] unspecified
75+
// [cfe] unspecified
76+
77+
abstract base mixin class AbstractBaseMixinClassImplementsEnum implements E {}
78+
// ^
79+
// [analyzer] unspecified
80+
// [cfe] unspecified
81+
82+
mixin MixinImplementsEnum implements E {}
83+
// ^
84+
// [analyzer] unspecified
85+
// [cfe] unspecified
86+
87+
base mixin BaseMixinImplementsEnum implements E {}
88+
// ^
89+
// [analyzer] unspecified
90+
// [cfe] unspecified
91+
92+
main() {
93+
print(ImplementsEnum);
94+
print(BaseImplementsEnum);
95+
print(InterfaceImplementsEnum);
96+
print(FinalImplementsEnum);
97+
print(SealedImplementsEnum);
98+
print(AbstractImplementsEnum);
99+
print(AbstractBaseImplementsEnum);
100+
print(AbstractInterfaceImplementsEnum);
101+
print(AbstractFinalImplementsEnum);
102+
print(MixinClassImplementsEnum);
103+
print(BaseMixinClassImplementsEnum);
104+
print(AbstractMixinClassImplementsEnum);
105+
print(AbstractBaseMixinClassImplementsEnum);
106+
print(MixinImplementsEnum);
107+
print(BaseMixinImplementsEnum);
108+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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 An enum declaration still cannot be implemented, extended or
6+
/// mixed in anywhere, independently of modifiers.
7+
///
8+
/// @description Check that it is a compile-time error if an enum declaration is
9+
/// mixed in
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=class-modifiers
13+
14+
enum E {e1, e2}
15+
16+
class WithEnum with E {}
17+
// ^
18+
// [analyzer] unspecified
19+
// [cfe] unspecified
20+
21+
base class BaseWithEnum with E {}
22+
// ^
23+
// [analyzer] unspecified
24+
// [cfe] unspecified
25+
26+
interface class InterfaceWithEnum with E {}
27+
// ^
28+
// [analyzer] unspecified
29+
// [cfe] unspecified
30+
31+
final class FinalWithEnum with E {}
32+
// ^
33+
// [analyzer] unspecified
34+
// [cfe] unspecified
35+
36+
sealed class SealedWithEnum with E {}
37+
// ^
38+
// [analyzer] unspecified
39+
// [cfe] unspecified
40+
41+
abstract class AbstractWithEnum with E {}
42+
// ^
43+
// [analyzer] unspecified
44+
// [cfe] unspecified
45+
46+
abstract base class AbstractBaseWithEnum with E {}
47+
// ^
48+
// [analyzer] unspecified
49+
// [cfe] unspecified
50+
51+
52+
abstract interface class AbstractInterfaceWithEnum with E {}
53+
// ^
54+
// [analyzer] unspecified
55+
// [cfe] unspecified
56+
57+
abstract final class AbstractFinalWithEnum with E {}
58+
// ^
59+
// [analyzer] unspecified
60+
// [cfe] unspecified
61+
62+
mixin class MixinClassWithEnum with E {}
63+
// ^
64+
// [analyzer] unspecified
65+
// [cfe] unspecified
66+
67+
base mixin class BaseMixinClassWithEnum with E {}
68+
// ^
69+
// [analyzer] unspecified
70+
// [cfe] unspecified
71+
72+
abstract mixin class AbstractMixinClassWithEnum with E {}
73+
// ^
74+
// [analyzer] unspecified
75+
// [cfe] unspecified
76+
77+
abstract base mixin class AbstractBaseMixinClassWithEnum with E {}
78+
// ^
79+
// [analyzer] unspecified
80+
// [cfe] unspecified
81+
82+
main() {
83+
print(WithEnum);
84+
print(BaseWithEnum);
85+
print(InterfaceWithEnum);
86+
print(FinalWithEnum);
87+
print(SealedWithEnum);
88+
print(AbstractWithEnum);
89+
print(AbstractBaseWithEnum);
90+
print(AbstractInterfaceWithEnum);
91+
print(AbstractFinalWithEnum);
92+
print(MixinClassWithEnum);
93+
print(BaseMixinClassWithEnum);
94+
print(AbstractMixinClassWithEnum);
95+
print(AbstractBaseMixinClassWithEnum);
96+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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+
/// @description Library defining some base classes for testing class modifiers
6+
/// @author [email protected]
7+
8+
// SharedOptions=--enable-experiment=class-modifiers
9+
10+
library class_modifiers_lib;
11+
12+
class Class {}
13+
base class BaseClass {}
14+
interface class InterfaceClass {}
15+
final class FinalClass {}
16+
abstract class AbstractClass {}
17+
sealed class SealedClass {}
18+
abstract base class AbstractBaseClass {}
19+
abstract interface class AbstractInterfaceClass {}
20+
abstract final class AbstractFinalClass {}
21+
mixin class MixinClass {}
22+
base mixin class BaseMixinClass {}
23+
abstract mixin class AbstractMixinClass {}
24+
abstract base mixin class AbstractBaseMixinClass {}
25+
mixin Mixin {}
26+
base mixin BaseMixin {}
27+
28+
typedef TypedefBaseClass = BaseClass;
29+
typedef TypedefInterfaceClass = InterfaceClass;
30+
typedef TypedefFinalClass = FinalClass;
31+
typedef TypedefSealedClass = SealedClass;
32+
typedef TypedefAbstractClass = AbstractClass;
33+
typedef TypedefAbstractBaseClass = AbstractBaseClass;
34+
typedef TypedefAbstractInterfaceClass = AbstractInterfaceClass;
35+
typedef TypedefAbstractFinalClass = AbstractFinalClass;
36+
typedef TypedefMixinClass = MixinClass;
37+
typedef TypedefBaseMixinClass = BaseMixinClass;
38+
typedef TypedefAbstractBaseMixinClass = AbstractBaseMixinClass;
39+
typedef TypedefMixin = Mixin;
40+
typedef TypedefBaseMixin = BaseMixin;
41+
42+
class ExtendsSealedClass extends SealedClass {}
43+
class ImplementsSealedClass implements SealedClass {}
44+
mixin MixinOnSealed on SealedClass {}

0 commit comments

Comments
 (0)