Skip to content

Miscompilation of assignment #7170

Closed
@AndreasLoow

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions