The following code:
for i in 1 to 5 {
let a = ref(None)
if i == 3 {
a := Some(3)
}
Js.log(a.contents)
}
gets compiled to:
for(var i = 1; i <= 5; ++i){
var a;
if (i === 3) {
a = 3;
}
console.log(a);
}
rescript playground
reason playground
Expected result:
Variable a is re-initialized to undefined in each iteration of the loop.
undefined
undefined
3
undefined
undefined
Actual result:
undefined
undefined
3
3
3
Correct compilation result should be:
for(var i = 1; i <= 5; ++i){
var a = undefined;
if (i === 3) {
a = 3;
}
console.log(a);
}
The following code:
gets compiled to:
rescript playground
reason playground
Expected result:
Variable
ais re-initialized toundefinedin each iteration of the loop.Actual result:
Correct compilation result should be: