Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ospencer opened this issue Apr 25, 2020 · 2 comments · Fixed by #1244
Closed

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

ospencer opened this issue Apr 25, 2020 · 2 comments · Fixed by #1244
Labels

Comments

@ospencer
Copy link

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.

@ospencer
Copy link
Author

The wasmtime command used was wasmtime test.wasm --invoke test.

@MaxGraey
Copy link
Member

Can confirm. Minimal reproduction example:

export function test(): void {
  var i = 0
  while (true) {
    i++
    if (i < 1) {
      // continue
    } else {
      break
    }
  }
}

if uncomment continue this example will repair

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants