Skip to content

dart2wasm miscompilation around dynamic switch targets  #56321

@simolus3

Description

@simolus3

Consider this Dart script:

void main() {
  print(3 == 3.0);
  dynamic x = 3.0;

  switch (x) {
    case 0:
      print('0');
    case 1:
      print('1');
    case 2:
      print('2');
    case 3:
      print('3');
  }
}

When running it in a Dart VM, it prints

true
3

When compiled with dart2wasm, however:

true
Uncaught (in promise) RuntimeError: illegal cast
    at main (0006e8c2:0x13f6b)
    at main tear-off trampoline (0006e8c2:0x13fd9)
    at _invokeMain (0006e8c2:0xaba0)
    at invoke (wasm.mjs:286:26)
    at wasm.dart.js:9:3

The generated code shows the problem:

    global.get $global787 ;; BoxedDouble { $field0: 4, $field1: 3.0 }
    local.set $var3
    block $label5
      local.get $var3
      ref.cast null $BoxedInt ;; this obviously fails
      local.set $var5
      loop

I've tested this with a SDK built from the current tree.

Metadata

Metadata

Assignees

Labels

area-dart2wasmIssues for the dart2wasm compiler.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