[ddc] switch case doesn't match enum when enum comes from a different library and has a final field that's not initialized via constructor #59939
Labels
area-web
Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop.
This is a very niche and unusual case with an easy workaround, but I still wanted to report it.
Running the following code prints
this should NOT happen
when compiled with ddc:It only happens if the enum is defined in a separate library (with
main.dart
in the web directory andmy_enum.dart
in the lib directory). The generated code looks like this:someText: null
seems to be the problem. It's correctly initialized toHello World
if the enum is in the same library or if it's initialized via constructor.A simple workaround is to initialize the field in the constructor or turning it into a getter. (I've only run into this issue because my actual enum implements an interface that has a field that I'm not yet using)
tested with:
Dart SDK version: 3.7.0-309.0.dev (dev) (Tue Jan 7 20:06:23 2025 -0800) on "windows_x64"
Dart SDK version: 3.7.0-323.0.dev (dev) (Mon Jan 13 04:02:13 2025 -0800) on "windows_x64"
The text was updated successfully, but these errors were encountered: