Skip to content
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

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

Merged
merged 1 commit into from
Apr 2, 2024

Conversation

CountBleck
Copy link
Member

Fixes #2825.

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

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

@CountBleck CountBleck force-pushed the fix-2825 branch 2 times, most recently from 6293b10 to 550bbf5 Compare March 10, 2024 02:30
@CountBleck CountBleck changed the title Compile incrementors within the initializer's flow in for loops Compile incrementors in for loops within the initializer's flow Mar 10, 2024
Copy link
Member

@HerrCai0907 HerrCai0907 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after fixes.
Please add assert test case like code in issue to enhance test quality.

@CountBleck
Copy link
Member Author

@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
Copy link
Member

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;
  }
}

It turns out that incrementors were compiled with the body's flow, which
meant that the incrementor had access to local variables declared in the
body. Now, incrementors no longer have access to such variables.

Fixes AssemblyScript#2825.
@CountBleck CountBleck changed the title Compile incrementors in for loops within the initializer's flow fix: compile incrementors in for loops within the initializer's flow Apr 2, 2024
@CountBleck CountBleck merged commit 9102c05 into AssemblyScript:main Apr 2, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loop and variable bug
3 participants