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

CSE machine: bug in for loops #1727

Open
martin-henz opened this issue Oct 29, 2024 · 1 comment
Open

CSE machine: bug in for loops #1727

martin-henz opened this issue Oct 29, 2024 · 1 comment
Labels
Bug Something isn't working

Comments

@martin-henz
Copy link
Member

let y = 0;
for (let i = (y = y + 1); i <= 1; i = i + 1) {
    display(i);
}

should result in one loop execution and return 1, but it results in no loop executions and returns undefined in the CSE machine. Explanation: the value expression is duplicated in interpreter.ts (530):

      control.push(
        ast.blockStatement(
          [
            init,
            ^ here
            ast.forStatement(
              ast.assignmentExpression(id, valueExpression, command.loc),
                                                 ^ and here
              test,
              update,
@martin-henz martin-henz added the Bug Something isn't working label Oct 29, 2024
@martin-henz
Copy link
Member Author

The fix is to stick to the specs:
https://docs.sourceacademy.org/source_3.pdf
which says for (name = name; ...)
to avoid the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant