Skip to content

Miscompilation of assignment #7170

Description

@AndreasLoow

Hi, the following code

{
let j = ref(0)

if Js.String.get("%", j.contents) == "%" {
 j := j.contents + 1
 j := j.contents + 1
} else {
 j := j.contents + 1
}

Console.log(j.contents)
}

is compiled into

var j = 0;

j = j + 1 | 0;

if ("%"[j] === "%") {
  j = j + 1 | 0;
}

console.log(j);

Note how the assignment of j is moved outside the if-expression despite the move changing the evaluation of the condition of the if-expression. The code without the surrounding { and } is compiled correctly.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions