Skip to content

Commit fcd1a5a

Browse files
committed
Fix #281
1 parent d7a5f1c commit fcd1a5a

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

src/compiler/iroptimizer.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ class TypeState {
9999
});
100100
}
101101

102+
/**
103+
* @param {TypeState} other
104+
* @returns {boolean}
105+
*/
106+
overwrite (other) {
107+
return this.mutate(other, varId => other.variables[varId] ?? InputType.ANY);
108+
}
109+
102110
/**
103111
* @param {*} variable A variable codegen object.
104112
* @param {InputType} type The type to set this variable to
@@ -490,6 +498,8 @@ class IROptimizer {
490498

491499
if (!script || !script.cachedAnalysisEndState) {
492500
modified = state.clear() || modified;
501+
} else if (script.yields) {
502+
modified = state.overwrite(script.cachedAnalysisEndState) || modified;
493503
} else {
494504
modified = state.after(script.cachedAnalysisEndState) || modified;
495505
}
@@ -578,6 +588,8 @@ class IROptimizer {
578588

579589
if (!script || !script.cachedAnalysisEndState) {
580590
modified = state.clear() || modified;
591+
} else if (script.yields) {
592+
modified = state.overwrite(script.cachedAnalysisEndState) || modified;
581593
} else {
582594
modified = state.after(script.cachedAnalysisEndState) || modified;
583595
}

test/snapshot/__snapshots__/tw-procedure-return-recursion.sb3.tw-snapshot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ return function* genXYZ () {
1010
yield* executeInCompatibilityLayer({"MESSAGE":"plan 18",}, b0, false, false, "G", null);
1111
b1.value = 0;
1212
b2.value = (yield* thread.procedures["Znon warp recursion should yield %s"](8));
13-
if ((b1.value === 4)) {
13+
if (((+b1.value || 0) === 4)) {
1414
yield* executeInCompatibilityLayer({"MESSAGE":"pass non warp recursion yields",}, b0, false, false, "ao", null);
1515
}
1616
b1.value = 0;
@@ -20,7 +20,7 @@ yield* executeInCompatibilityLayer({"MESSAGE":"pass warp recursion does not yiel
2020
}
2121
b1.value = 0;
2222
b2.value = (yield* thread.procedures["Zfib %s"](7));
23-
if ((b1.value === 20)) {
23+
if (((+b1.value || 0) === 20)) {
2424
yield* executeInCompatibilityLayer({"MESSAGE":"pass non warp fib yielded",}, b0, false, false, "au", null);
2525
}
2626
yield* thread.procedures["Zrecursing yields between each %s"]("initial");

test/snapshot/__snapshots__/warp-timer/tw-procedure-return-recursion.sb3.tw-snapshot

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ return function* genXYZ () {
1010
yield* executeInCompatibilityLayer({"MESSAGE":"plan 18",}, b0, false, false, "G", null);
1111
b1.value = 0;
1212
b2.value = (yield* thread.procedures["Znon warp recursion should yield %s"](8));
13-
if ((b1.value === 4)) {
13+
if (((+b1.value || 0) === 4)) {
1414
yield* executeInCompatibilityLayer({"MESSAGE":"pass non warp recursion yields",}, b0, false, false, "ao", null);
1515
}
1616
b1.value = 0;
@@ -20,7 +20,7 @@ yield* executeInCompatibilityLayer({"MESSAGE":"pass warp recursion does not yiel
2020
}
2121
b1.value = 0;
2222
b2.value = (yield* thread.procedures["Zfib %s"](7));
23-
if ((b1.value === 20)) {
23+
if (((+b1.value || 0) === 20)) {
2424
yield* executeInCompatibilityLayer({"MESSAGE":"pass non warp fib yielded",}, b0, false, false, "au", null);
2525
}
2626
yield* thread.procedures["Zrecursing yields between each %s"]("initial");

0 commit comments

Comments
 (0)