-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.feature-dot-shorthandsImplementation of the dot shorthands feature.Implementation of the dot shorthands feature.model-featuresGeneral feature work in the analyzer and CFE.General feature work in the analyzer and CFE.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)
Description
I have been trying out the dot-shorthands experiment, and I came across this.
This occurs when you have an enum, which has another enum as a constructor parameter.
If you try to use shorthands for every enum value you will get an error on one of the values in particular (it's not always the first value).
void main() {
A a = .a1;
print(a);
}
enum A {
a1(.b1), // error here
a2(.b2),
a3(.b3);
const A(this.value);
final B value;
}
enum B { b1, b2, b3 }error:
PS C:\Users\mmcdo\AndroidStudioProjects\experiment> dart --enable-experiment=dot-shorthands bin\ab.dart
Unhandled exception:
'file:///C:/Users/mmcdo/AndroidStudioProjects/experiment/bin/ab.dart': error: bin/ab.dart:7:6: Error: This couldn't be parsed.
a1(.b1),
^
#0 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:314:19)
#1 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:193:12)
If you add the full qualifier to whichever value the error complains about, you can use shorthands for the remaining values, and it will compile and run successfully.
void main() {
A a = .a1;
print(a);
}
enum A {
a1(B.b1),
a2(.b2),
a3(.b3);
const A(this.value);
final B value;
}
enum B { b1, b2, b3 }output:
A.a1
Dart SDK version: 3.9.0-32.0.dev (dev) (Fri Apr 18 09:03:27 2025 -0700) on "windows_x64"
Metadata
Metadata
Assignees
Labels
area-dart-modelFor issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer.feature-dot-shorthandsImplementation of the dot shorthands feature.Implementation of the dot shorthands feature.model-featuresGeneral feature work in the analyzer and CFE.General feature work in the analyzer and CFE.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)Incorrect behavior (everything from a crash to more subtle misbehavior)