AssemblyScript / assemblyscript

A TypeScript-like language for WebAssembly.
https://www.assemblyscript.org
Apache License 2.0
16.82k stars 655 forks source link

fix: compile incrementors in for loops within the initializer's flow #2826

Closed CountBleck closed 6 months ago

CountBleck commented 6 months ago

Fixes #2825.

Changes proposed in this pull request: ⯈ Compile for-loop incrementors within the initializer's flow

CountBleck commented 6 months ago

@HerrCai0907 I don't think that's possible to do unless I have an assert in the incrementor. This should likely work just fine.

HerrCai0907 commented 6 months ago

Like

function inc(i: i32): i32 {
  assert(i != 100); // failed
  return i + 1;
}

export function _start(): void {
  for (let i = 0; i < 1; i = inc(i)) {
    let i = 100;
  }
}