Skip to content

break within the else clause of an if within a while loop traps #1239

Closed
@ospencer

Description

@ospencer

Program:

export function test(): void {
  let foo = 0
  while (true) {
    foo++
    if (foo < 10) {
      3
    } else {
      break
    }
  }
  return
}

compiled with: asc test.ts -o test.wasm -O3 --runtime none
run with wasmtime results in

Error: failed to run main module `test.wasm`

Caused by:
    0: failed to invoke `test`
    1: wasm trap: unreachable, source location: @0049
       wasm backtrace:
         0: <unknown>!<wasm function 0>

I originally discovered this running on Node.js, but checked with wasmtime as well.

If the logic is reversed and the break is in the if clause, this works just fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions