From 77a8cb293ad4980b9e8fc24cef888aed7247c11c Mon Sep 17 00:00:00 2001 From: sgrekhov Date: Tue, 8 Feb 2022 17:42:24 +0700 Subject: [PATCH] #1258. Add more tests on user-written 'index' and 'values' --- .../implementing_enum_A03_t13.dart | 73 +++++++++++++++++ .../implementing_enum_A03_t14.dart | 73 +++++++++++++++++ .../implementing_enum_A03_t15.dart | 73 +++++++++++++++++ .../implementing_enum_A03_t16.dart | 73 +++++++++++++++++ .../implementing_enum_A04_t01.dart | 73 +++++++++++++++++ .../implementing_enum_A04_t02.dart | 73 +++++++++++++++++ .../implementing_enum_A04_t03.dart | 73 +++++++++++++++++ .../implementing_enum_A04_t04.dart | 73 +++++++++++++++++ .../implementing_enum_A04_t05.dart | 80 +++++++++++++++++++ .../implementing_enum_A04_t06.dart | 80 +++++++++++++++++++ .../implementing_enum_A04_t07.dart | 80 +++++++++++++++++++ .../implementing_enum_A04_t08.dart | 80 +++++++++++++++++++ .../implementing_enum_A04_t09.dart | 73 +++++++++++++++++ .../implementing_enum_A04_t10.dart | 73 +++++++++++++++++ .../implementing_enum_A04_t11.dart | 73 +++++++++++++++++ .../implementing_enum_A04_t12.dart | 73 +++++++++++++++++ 16 files changed, 1196 insertions(+) create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t13.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t14.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t15.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t16.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t01.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t02.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t03.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t04.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t05.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t06.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t07.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t08.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t09.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t10.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t11.dart create mode 100644 LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t12.dart diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t13.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t13.dart new file mode 100644 index 0000000000..dba767aed3 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t13.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a class has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +abstract class E1 extends Enum { + final int values = 42; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +abstract class E2 extends Enum { + final List values = []; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E1); + print(E2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t14.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t14.dart new file mode 100644 index 0000000000..250735740c --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t14.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a class has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +abstract class E1 extends Enum { + int values() => 42; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +abstract class E2 extends Enum { + List values() => []; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E1); + print(E2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t15.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t15.dart new file mode 100644 index 0000000000..9f231e8677 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t15.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a class has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +abstract class E1 extends Enum { + int get values => 42; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +abstract class E2 extends Enum { + List get values => []; +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E1); + print(E2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t16.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t16.dart new file mode 100644 index 0000000000..69a0456ab4 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A03_t16.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a class has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +abstract class E1 extends Enum { + void set values(int val) {} +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +abstract class E2 extends Enum { + void set values(List val) {} +// ^^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E1); + print(E2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t01.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t01.dart new file mode 100644 index 0000000000..6899e0dc6b --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t01.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a class declaration has +/// Enum as a superinterface, and it declares a non-abstract instance member +/// named `index`. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +abstract class E1 extends Enum { + final int index = 42; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +abstract class E2 extends Enum { + final List index = []; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E1); + print(E2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t02.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t02.dart new file mode 100644 index 0000000000..b06b5006fd --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t02.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a class declaration has +/// Enum as a superinterface, and it declares a non-abstract instance member +/// named `index`. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +abstract class E1 extends Enum { + int index() => 42; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +abstract class E2 extends Enum { + List index() => []; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E1); + print(E2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t03.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t03.dart new file mode 100644 index 0000000000..e3a527ef91 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t03.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a class declaration has +/// Enum as a superinterface, and it declares a non-abstract instance member +/// named `index`. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +abstract class E1 extends Enum { + int get index => 42; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +abstract class E2 extends Enum { + List get index => []; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E1); + print(E2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t04.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t04.dart new file mode 100644 index 0000000000..17d1ca06a2 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t04.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a class declaration has +/// Enum as a superinterface, and it declares a non-abstract instance member +/// named `index`. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +abstract class E1 extends Enum { + void set index(int val) {} +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +abstract class E2 extends Enum { + void set index(List val) {} +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E1); + print(E2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t05.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t05.dart new file mode 100644 index 0000000000..dee1605c9a --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t05.dart @@ -0,0 +1,80 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a enum declaration has +/// Enum as a superinterface, and it declares a non-abstract instance member +/// named `index`. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +enum E1 { + e1, + e2; + + final int index = 42; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E2 { + e1(42), + e2(0); + + const E2(int i); + final List index = []; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E1); + print(E2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t06.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t06.dart new file mode 100644 index 0000000000..dd0cb24008 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t06.dart @@ -0,0 +1,80 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a enum declaration has +/// Enum as a superinterface, and it declares a non-abstract instance member +/// named `index`. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +enum E1 { + e1, + e2; + + int index() => 42; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E2 { + e1(42), + e2(0); + + const E2(int i); + List index() => []; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E1); + print(E2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t07.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t07.dart new file mode 100644 index 0000000000..1bfc8034eb --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t07.dart @@ -0,0 +1,80 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a enum declaration has +/// Enum as a superinterface, and it declares a non-abstract instance member +/// named `index`. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +enum E1 { + e1, + e2; + + int get index => 42; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E2 { + e1(42), + e2(0); + + const E2(int i); + List get index => []; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E1); + print(E2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t08.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t08.dart new file mode 100644 index 0000000000..85203140b0 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t08.dart @@ -0,0 +1,80 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a enum declaration has +/// Enum as a superinterface, and it declares a non-abstract instance member +/// named `index`. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +enum E1 { + e1, + e2; + + void set index(int val) {} +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +enum E2 { + e1(42), + e2(0); + + const E2(int i); + void set index(List val) {} +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(E1); + print(E2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t09.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t09.dart new file mode 100644 index 0000000000..b7e15e709c --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t09.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a mixin declaration has +/// Enum as a superinterface, and it declares a non-abstract instance member +/// named `index`. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +mixin M1 on Enum { + final int index = 42; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M2 on Enum { + final List index = []; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(M1); + print(M2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t10.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t10.dart new file mode 100644 index 0000000000..eb144adcd0 --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t10.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a mixin declaration has +/// Enum as a superinterface, and it declares a non-abstract instance member +/// named `index`. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +mixin M1 on Enum { + int index() => 42; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M2 on Enum { + List index() => []; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(M1); + print(M2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t11.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t11.dart new file mode 100644 index 0000000000..2fd17de5af --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t11.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a mixin declaration has +/// Enum as a superinterface, and it declares a non-abstract instance member +/// named `index`. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +mixin M1 on Enum { + int get index => 42; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M2 on Enum { + List get index => []; +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(M1); + print(M2); +} diff --git a/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t12.dart b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t12.dart new file mode 100644 index 0000000000..aef55122aa --- /dev/null +++ b/LanguageFeatures/Enhanced-Enum/implementing_enum_A04_t12.dart @@ -0,0 +1,73 @@ +// Copyright (c) 2022, 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 has Enum as a +/// superinterface (directly or transitively) unless it is the corresponding +/// class of an enum declaration. +/// +/// It is a compile-time error if a class implements, extends or mixes-in the +/// class or interface introduced by an enum declaration. (An enum class can’t +/// be used as a mixin since it is not a mixin declaration and the class has a +/// superclass other than Object, but we include “mixes-in” for completeness.) +/// +/// It's a compile-time error if a class or mixin declaration has Enum as a +/// superinterface and the interface of the declarations contains an instance +/// member with the name values, whether declared or inherited. If any concrete +/// class implements this interface, it will be an enum declaration class, and +/// then the values member would conflict with the static values constant getter +/// that is automatically added to enum declaration classes. Such an instance +/// values declaration is either useless or wrong, so we disallow it entirely. +/// +/// It's a compile-time error if a class, mixin or enum declaration has Enum as +/// a superinterface, and it declares a non-abstract instance member named index. +/// That member would override the index getter inherited from Enum, and we +/// currently do not allow that. +/// +/// Those restrictions 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. +/// +/// The restrictions 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. It's also impossible +/// to override or prevent the instance index and static values members without +/// causing a compile-time error. Say implementing an interface with +/// `Never get index;` as a member, then because it's not possible to override +/// `int get index;` from Enum, the resulting class does not implement its +/// interface and is a compile-time error. +/// +/// @description Check that it's a compile-time error if a mixin declaration has +/// Enum as a superinterface, and it declares a non-abstract instance member +/// named `index`. +/// @author sgrekhov@unipro.ru + +// SharedOptions=--enable-experiment=enhanced-enums + +mixin M1 on Enum { + void set index(int v) {} +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +mixin M2 on Enum { + void set index(List val) {} +// ^^^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(M1); + print(M2); +}