You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$> dart --enable-experiment=enhanced-enums test.dart
test.dart:2:6: Error: Constant evaluation error:
enum E {
^
test.dart:2:6: Context: Expected constant 'null' to be of type 'E', but was of type 'Null'.
- 'E' is from 'test.dart'.
enum E {
^
test.dart:2:6: Context: While analyzing:
enum E {
^
The text was updated successfully, but these errors were encountered:
@lrhn, is it intended that a constructor const E(); will be generated in an enum declaration E in the case where E contains a factory constructor (redirecting or not)? This seems inconsistent with the treatment of a similar situation for classes:
classC {
factoryC.fac() =D;
}
classDimplementsC {
D();
}
voidmain() {
C(); // Error, there is no constructor named `C`.
}
So I would think that there should be an error in the original example, because it needs to invoke a constructor named E, and there is no such thing, but the spec seems to disagree.
If no generative constructors were declared, and no unnamed factory constructor was added, a default generative constructor const Name._$(this.index, this._$name); is added.
So, yes, it's intended.
There might be reason for not wanting any generative constructors on normal classes. There is never a reason to not have a generative constructor for an enum class, because it must have at least one enum element that must be constructable.
Adding a factory constructor does not change that, so unless it actually uses the unnamed constructor name, we'll always add the default constructor.
Dart SDK version: 2.17.0-28.0.dev (dev) (Tue Jan 18 12:05:00 2022 -0800) on "windows_x64"
Dart produces a compile time error for the following source code example:
Seems like there should not be an error here.
Sample output is:
The text was updated successfully, but these errors were encountered: