Specify that enums extend _Enum from dart:core.#3671
Specify that enums extend _Enum from dart:core.#3671stereotype441 wants to merge 1 commit intodart-lang:mainfrom
_Enum from dart:core.#3671Conversation
| *or* retain the current `_Enum` class and make that the actual superclass of `enum` classes. Either works, I’ll use `Enum` as the superclass directly in the following. | ||
|
|
||
| Then desugar an `enum` declaration to an actual `class` declaration and rewrite every generative constructor of the `enum` declaration to take two extra leading positional arguments. | ||
| An `enum` declaration is desugared to an actual `class` declaration, which extends a private `_Enum` class in `dart:core`. _This class holds the `final int index;` declaration and a `final String _name;` declaration (used by the the `EnumName.name` getter), and both fields are initialized by a constructor._ Every generative constructor of the `enum` declaration is rewritten to take two extra leading positional arguments. |
There was a problem hiding this comment.
I really wish this wasn't necessary. We're specifying an implementation detail.
Could we at least avoid specifying the name of the class?
Just say that there exists an anonymous class which implements Enum and which enum classes extend,
so that the depth of an enum class is at least depth(Enum) + 2.
That still implies that there is a class at depth(Enum) + 1 that other classes can conflict with. Can we introduce a third class at depth depth(Enum) + 1 that enum classes also implement, so UP can never yield _Enum? Like for class HideEfficientLengthIterable does for EfficientLengthIterable.
There was a problem hiding this comment.
Thinking more about this, I'd prefer to just want to make it unspecified behavior.
Or stop extending _Enum. It is an implementation detail.
Heck, make _Enum not implement Enum, and it would give it a lower depth. (And make inferring Enum impossible, because LUB is moronic.) Or make _Enum a superclass of Enum.
I really, really do not want to enshrine a completely arbitrary private implementation class in the specification. I'd rather make every tool lie about it. That is a more future proof design.
(I do consider if we can make enum classes be allowed to have superclasses, so they only implement Enum. Maybe make _Enum a mixin then - probably needs more mixin features.)
| *or* retain the current `_Enum` class and make that the actual superclass of `enum` classes. Either works, I’ll use `Enum` as the superclass directly in the following. | ||
|
|
||
| Then desugar an `enum` declaration to an actual `class` declaration and rewrite every generative constructor of the `enum` declaration to take two extra leading positional arguments. | ||
| An `enum` declaration is desugared to an actual `class` declaration, which extends a private `_Enum` class in `dart:core`. _This class holds the `final int index;` declaration and a `final String _name;` declaration (used by the the `EnumName.name` getter), and both fields are initialized by a constructor._ Every generative constructor of the `enum` declaration is rewritten to take two extra leading positional arguments. |
See
#3665 (comment) for details.
Contribution guidelines:
dart format.Note that many Dart repos have a weekly cadence for reviewing PRs - please allow for some latency before initial review feedback.