Skip to content

Commit 089daf9

Browse files
authored
Remove reference to being able to declare values (#2102)
* Remove reference to being able to declare `values`
1 parent 445aa27 commit 089daf9

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

accepted/future-releases/enhanced-enums/feature-specification.md

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,10 @@ If the resulting class would have any naming conflicts, or other compile-time er
136136

137137
- Declaring or inheriting (from `Enum` or from a declared mixin or interface) any member with the same basename as an enum value which is not a static setter. _(The introduced static declarations would have a conflict.)_
138138
- Declaring or mixing in a member which is not a valid override of a super-interface member declaration, including, but not limited to, the `index` and `toString` members of `Enum`.
139-
- Declaring or inheriting a member signature with no corresponding implementation. _(For example declaring an abstract `Never get index` or `String toString([int optional])`, but not providing an implementation.)_
140-
- Declaring a type parameter on the `enum` which does not have a valid well-bounded or super-bounded instantiate-to-bounds result *and* not declaring or inheriting a member with base-name `values` _(because the then automatically introduced `static const List<EnumName> values` requires a valid instantiate-to-bounds result which is at least super-bounded, and a value declaration may require a well-bounded instantiation)_.
141-
- The type parameters of the enum not having a well-bounded instantiate-to-bounds result *and* an enum element omitting the type arguments and not having arguments which valid type arguments can be inferred from (because an implicit `EnumName(0, "foo", unrelatedArgs)` constructor invocation requires a well-bound inferred type arguments for a generic `EnumName` enum).
142-
- Using a non-constant expression as argument of an enum value.
139+
- Declaring or inheriting an member signature with no corresponding implementation. _(For example declaring an abstract `Never get index` or `String toString([int optional])`, but not providing an implementation.)
140+
- Declaring a generic `enum` which does not have a valid well-bounded instantiate-to-bounds result. _(The automatically introduced `static const List<EnumName> values` requires a well-bounded instantiate-to-bounds result)_.
141+
- Declaring a generic `enum` which does not have a regular-bounded instantiate-to-bounds result *and* that has an enum value declaration omitting the type arguments and not having arguments from which type arguments can be inferred. _(For example `enum EnumName<F extends C<F>> { foo; }` would introduce an implicit `static const foo = EnumName(0, "foo");` declaration where the constructor invocation requires a regular-bounded instantiate-to-bounds result)_.
142+
- Using a non-constant expression as an argument of an enum value declaration.
143143
- Declaring a static member and inheriting an instance member with the same base-name.
144144

145145
If not invalid, the semantics denoted by the `enum` declaration is that class, which we’ll refer to as the *corresponding class* of the `enum` declaration. *(We don’t require the implementation to be exactly such a class declaration, there might be other helper classes involved in the implementation, and different private members, but the publicly visible interface and behavior should match.)*
@@ -154,7 +154,7 @@ Because we want to allow interfaces and mixins that are intended to be applied t
154154

155155
- 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.
156156
- 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.)_
157-
- 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._
157+
- 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._
158158
- 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._
159159

160160
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.
@@ -266,15 +266,14 @@ enum Plain {
266266
would have a corresponding class desugaring of:
267267

268268
```dart
269-
class Plain extends Enum {
270-
static const Plain foo = Plain._$(0, "foo");
271-
static const Plain bar = Plain._$(1, "bar");
272-
static const Plain baz = Plain._$(2, "baz");
273-
static const List<Plain> values = [foo, bar, baz];
274-
275-
const Plain._$(int _$index, String _$name) : super._(_$index, _$name);
276-
277-
// Private names from `dart:core`.
269+
class Plain extends Enum {
270+
static const Plain foo = Plain._$(0, "foo");
271+
static const Plain bar = Plain._$(1, "bar");
272+
static const Plain baz = Plain._$(2, "baz");
273+
static const List<Plain> values = [foo, bar, baz];
274+
const Plain._$(int _$index, String_ $name) : super._(_$index, $_name);
275+
276+
// Private names from `dart:core`.
278277
String _$enumToString() => "Plain.${_$name}";
279278
}
280279
```

0 commit comments

Comments
 (0)