Skip to content

Illegal cast in switch statement for dynamic values on WASM #59782

@thomasostfeld

Description

@thomasostfeld

A switch statement on a dynamic value tries to cast the value to a type, when all (non-default) cases are matching that type.

Reproducable Code:

void main() {
  dynamic number = 42;
  switch (number) {
    case 'a':
      print('a');
    case 'b':
      print('b');
    default:
      print('default');
  }
}

This code works on web with JS, but fails when running with --wasm.

Expected behaviour:

prints out default.

Actual behaviour:

Uncaught RuntimeError: illegal cast

When adding a case of any other type than String it works.

I thought this would be fixed by #56321, but this is still happening.

dart --version output:

Dart SDK version: 3.6.0 (stable) (Thu Dec 5 07:46:24 2024 -0800) on "macos_arm64"

Metadata

Metadata

Assignees

Labels

area-dart2wasmIssues for the dart2wasm compiler.area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions