diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A01_t01.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A01_t01.dart new file mode 100644 index 0000000000..e998419bbf --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A01_t01.dart @@ -0,0 +1,43 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion It’s currently a compile-time error for a class to implement, +/// extend or mix-in the Enum class. +/// +/// Because we want to allow interfaces and mixins that are intended to be +/// applied to enum declarations, and therefore to assume Enum to be a +/// superclass, we loosen that restriction to: +/// +/// It’s a compile-time error if a non-abstract class implements Enum unless it +/// is the implicit class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in a +/// class declared by an enum declaration. +/// +/// That allows abstract classes (interfaces) which implements Enum in order to +/// have the int index; getter member available, and it allows mixin +/// declarations to use Enum as an on type because mixin declarations cannot be +/// instantiated directly. +/// +/// This restriction still ensure enum values are the only object instances +/// which implements Enum, while making it valid to declare abstract class +/// MyInterface implements Enum and mixin MyMixin on Enum for interfaces and +/// mixins intended to be used in declaring enum classes. +/// +/// @description Check that it’s a compile-time error if a non-abstract class +/// implements Enum and it is not the implicit class of an enum declaration. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +class C implements Enum { +// ^^^^ +// [analyzer] unspecified +// [cfe] unspecified + int get index => 42; +} + +main() { + C? c; +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A01_t02.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A01_t02.dart new file mode 100644 index 0000000000..9ad30538bc --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A01_t02.dart @@ -0,0 +1,49 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion It’s currently a compile-time error for a class to implement, +/// extend or mix-in the Enum class. +/// +/// Because we want to allow interfaces and mixins that are intended to be +/// applied to enum declarations, and therefore to assume Enum to be a +/// superclass, we loosen that restriction to: +/// +/// It’s a compile-time error if a non-abstract class implements Enum unless it +/// is the implicit class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in a +/// class declared by an enum declaration. +/// +/// That allows abstract classes (interfaces) which implements Enum in order to +/// have the int index; getter member available, and it allows mixin +/// declarations to use Enum as an on type because mixin declarations cannot be +/// instantiated directly. +/// +/// This restriction still ensure enum values are the only object instances +/// which implements Enum, while making it valid to declare abstract class +/// MyInterface implements Enum and mixin MyMixin on Enum for interfaces and +/// mixins intended to be used in declaring enum classes. +/// +/// @description Check that abstract classes may implement enum +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +import "../../Utils/expect.dart"; + +abstract class C implements Enum { + int foo(); +} + +enum E implements C { + e1, + e2; + + int foo() => this.index; +} + +main() { + Expect.equals(0, E.e1.foo()); + Expect.equals(1, E.e2.foo()); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A01_t03.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A01_t03.dart new file mode 100644 index 0000000000..500dd6bea4 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A01_t03.dart @@ -0,0 +1,50 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion It’s currently a compile-time error for a class to implement, +/// extend or mix-in the Enum class. +/// +/// Because we want to allow interfaces and mixins that are intended to be +/// applied to enum declarations, and therefore to assume Enum to be a +/// superclass, we loosen that restriction to: +/// +/// It’s a compile-time error if a non-abstract class implements Enum unless it +/// is the implicit class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in a +/// class declared by an enum declaration. +/// +/// That allows abstract classes (interfaces) which implements Enum in order to +/// have the int index; getter member available, and it allows mixin +/// declarations to use Enum as an on type because mixin declarations cannot be +/// instantiated directly. +/// +/// This restriction still ensure enum values are the only object instances +/// which implements Enum, while making it valid to declare abstract class +/// MyInterface implements Enum and mixin MyMixin on Enum for interfaces and +/// mixins intended to be used in declaring enum classes. +/// +/// @description Check that implicit class of enum declaration implements Enum +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +import "../../Utils/expect.dart"; + +enum E1 { + e1, + e2 +} + +enum E2 { + e1(42), + e2(0); + + const E2(int i); +} + +main() { + Expect.isTrue(E1.e1 is Enum); + Expect.isTrue(E2.e1 is Enum); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t01.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t01.dart new file mode 100644 index 0000000000..b31fa02bf1 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t01.dart @@ -0,0 +1,54 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion It’s currently a compile-time error for a class to implement, +/// extend or mix-in the Enum class. +/// +/// Because we want to allow interfaces and mixins that are intended to be +/// applied to enum declarations, and therefore to assume Enum to be a +/// superclass, we loosen that restriction to: +/// +/// It’s a compile-time error if a non-abstract class implements Enum unless it +/// is the implicit class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in a +/// class declared by an enum declaration. +/// +/// That allows abstract classes (interfaces) which implements Enum in order to +/// have the int index; getter member available, and it allows mixin +/// declarations to use Enum as an on type because mixin declarations cannot be +/// instantiated directly. +/// +/// This restriction still ensure enum values are the only object instances +/// which implements Enum, while making it valid to declare abstract class +/// MyInterface implements Enum and mixin MyMixin on Enum for interfaces and +/// mixins intended to be used in declaring enum classes. +/// +/// @description Check that it is a compile-time error if a class extends +/// a class declared by an enum declaration. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +enum E { + e1, + e2 +} + +abstract class E1 extends E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class E2 extends E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + E1? e1; + E2? e2; +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t02.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t02.dart new file mode 100644 index 0000000000..e64ca4d7a2 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t02.dart @@ -0,0 +1,56 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion It’s currently a compile-time error for a class to implement, +/// extend or mix-in the Enum class. +/// +/// Because we want to allow interfaces and mixins that are intended to be +/// applied to enum declarations, and therefore to assume Enum to be a +/// superclass, we loosen that restriction to: +/// +/// It’s a compile-time error if a non-abstract class implements Enum unless it +/// is the implicit class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in a +/// class declared by an enum declaration. +/// +/// That allows abstract classes (interfaces) which implements Enum in order to +/// have the int index; getter member available, and it allows mixin +/// declarations to use Enum as an on type because mixin declarations cannot be +/// instantiated directly. +/// +/// This restriction still ensure enum values are the only object instances +/// which implements Enum, while making it valid to declare abstract class +/// MyInterface implements Enum and mixin MyMixin on Enum for interfaces and +/// mixins intended to be used in declaring enum classes. +/// +/// @description Check that it is a compile-time error if a class extends +/// a class declared by an enum declaration. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +enum E { + e1(42), + e2(0); + + const E(int i); +} + +abstract class E1 extends E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class E2 extends E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + E1? e1; + E2? e2; +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t03.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t03.dart new file mode 100644 index 0000000000..a1d28a50c9 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t03.dart @@ -0,0 +1,54 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion It’s currently a compile-time error for a class to implement, +/// extend or mix-in the Enum class. +/// +/// Because we want to allow interfaces and mixins that are intended to be +/// applied to enum declarations, and therefore to assume Enum to be a +/// superclass, we loosen that restriction to: +/// +/// It’s a compile-time error if a non-abstract class implements Enum unless it +/// is the implicit class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in a +/// class declared by an enum declaration. +/// +/// That allows abstract classes (interfaces) which implements Enum in order to +/// have the int index; getter member available, and it allows mixin +/// declarations to use Enum as an on type because mixin declarations cannot be +/// instantiated directly. +/// +/// This restriction still ensure enum values are the only object instances +/// which implements Enum, while making it valid to declare abstract class +/// MyInterface implements Enum and mixin MyMixin on Enum for interfaces and +/// mixins intended to be used in declaring enum classes. +/// +/// @description Check that it is a compile-time error if a class implements +/// a class declared by an enum declaration. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +enum E { + e1, + e2 +} + +abstract class E1 implements E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class E2 implements E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + E1? e1; + E2? e2; +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t04.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t04.dart new file mode 100644 index 0000000000..3b1966723f --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t04.dart @@ -0,0 +1,56 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion It’s currently a compile-time error for a class to implement, +/// extend or mix-in the Enum class. +/// +/// Because we want to allow interfaces and mixins that are intended to be +/// applied to enum declarations, and therefore to assume Enum to be a +/// superclass, we loosen that restriction to: +/// +/// It’s a compile-time error if a non-abstract class implements Enum unless it +/// is the implicit class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in a +/// class declared by an enum declaration. +/// +/// That allows abstract classes (interfaces) which implements Enum in order to +/// have the int index; getter member available, and it allows mixin +/// declarations to use Enum as an on type because mixin declarations cannot be +/// instantiated directly. +/// +/// This restriction still ensure enum values are the only object instances +/// which implements Enum, while making it valid to declare abstract class +/// MyInterface implements Enum and mixin MyMixin on Enum for interfaces and +/// mixins intended to be used in declaring enum classes. +/// +/// @description Check that it is a compile-time error if a class implements +/// a class declared by an enum declaration. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +enum E { + e1(42), + e2(0); + + const E(int i); +} + +abstract class E1 implements E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class E2 implements E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + E1? e1; + E2? e2; +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t05.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t05.dart new file mode 100644 index 0000000000..6e33273c18 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t05.dart @@ -0,0 +1,59 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion It’s currently a compile-time error for a class to implement, +/// extend or mix-in the Enum class. +/// +/// Because we want to allow interfaces and mixins that are intended to be +/// applied to enum declarations, and therefore to assume Enum to be a +/// superclass, we loosen that restriction to: +/// +/// It’s a compile-time error if a non-abstract class implements Enum unless it +/// is the implicit class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in a +/// class declared by an enum declaration. +/// +/// That allows abstract classes (interfaces) which implements Enum in order to +/// have the int index; getter member available, and it allows mixin +/// declarations to use Enum as an on type because mixin declarations cannot be +/// instantiated directly. +/// +/// This restriction still ensure enum values are the only object instances +/// which implements Enum, while making it valid to declare abstract class +/// MyInterface implements Enum and mixin MyMixin on Enum for interfaces and +/// mixins intended to be used in declaring enum classes. +/// +/// @description Check that it is a compile-time error if a class mixes-in +/// a class declared by an enum declaration. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +enum E { + e1, + e2 +} + +mixin M on E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class C1 = Object with E; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + +class C2 extends Object with E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + E1? e1; + E2? e2; +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t06.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t06.dart new file mode 100644 index 0000000000..332b965ef9 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A02_t06.dart @@ -0,0 +1,61 @@ +// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +/// @assertion It’s currently a compile-time error for a class to implement, +/// extend or mix-in the Enum class. +/// +/// Because we want to allow interfaces and mixins that are intended to be +/// applied to enum declarations, and therefore to assume Enum to be a +/// superclass, we loosen that restriction to: +/// +/// It’s a compile-time error if a non-abstract class implements Enum unless it +/// is the implicit class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in a +/// class declared by an enum declaration. +/// +/// That allows abstract classes (interfaces) which implements Enum in order to +/// have the int index; getter member available, and it allows mixin +/// declarations to use Enum as an on type because mixin declarations cannot be +/// instantiated directly. +/// +/// This restriction still ensure enum values are the only object instances +/// which implements Enum, while making it valid to declare abstract class +/// MyInterface implements Enum and mixin MyMixin on Enum for interfaces and +/// mixins intended to be used in declaring enum classes. +/// +/// @description Check that it is a compile-time error if a class mixes-in +/// a class declared by an enum declaration. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +enum E { + e1(42), + e2(0); + + const E(int i); +} + +mixin M on E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +class C1 = Object with E; +// ^ +// [analyzer] unspecified +// [cfe] unspecified + +class C2 extends Object with E { +// ^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + E1? e1; + E2? e2; +}