Skip to content

Commit 66e12cf

Browse files
committed
fix breaking out of for..in loop inside a switch (case 489680)
1 parent b596306 commit 66e12cf

File tree

4 files changed

+58
-1
lines changed

4 files changed

+58
-1
lines changed

src/UnityScript.Tests/DuckyIntegrationTestFixture.boo

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,10 @@ class DuckyIntegrationTestFixture(AbstractIntegrationTestFixture):
358358
RunTestCase("tests/integration/for-continue-2.js")
359359

360360

361+
[Test] def for_in_switch_break():
362+
RunTestCase("tests/integration/for-in-switch-break.js")
363+
364+
361365
[Test] def for_over_null():
362366
RunTestCase("tests/integration/for-over-null.js")
363367

@@ -628,6 +632,8 @@ class DuckyIntegrationTestFixture(AbstractIntegrationTestFixture):
628632

629633
[Test] def yield_null():
630634
RunTestCase("tests/integration/yield-null.js")
635+
636+
631637
[Test] def Array_cast_to_native_array_of_struct():
632638
RunTestCase("tests/ducky/Array-cast-to-native-array-of-struct.js")
633639

src/UnityScript.Tests/StrictIntegrationTestFixture.Generated.boo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@ partial class StrictIntegrationTestFixture(AbstractIntegrationTestFixture):
356356
RunTestCase("tests/integration/for-continue-2.js")
357357

358358

359+
[Test] def for_in_switch_break():
360+
RunTestCase("tests/integration/for-in-switch-break.js")
361+
362+
359363
[Test] def for_over_null():
360364
RunTestCase("tests/integration/for-over-null.js")
361365

src/UnityScript/Macros/SwitchMacro.boo

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,14 @@ class GotoOnTopLevelBreak(DepthFirstTransformer):
9696
ReplaceCurrentNode(NewGoto(_label))
9797

9898
override def OnWhileStatement(node as WhileStatement):
99+
OnLoopBody node.Block
100+
101+
override def OnForStatement(node as ForStatement):
102+
OnLoopBody node.Block
103+
104+
def OnLoopBody(block as Block):
99105
++_level
100-
node.Block.Accept(self)
106+
block.Accept(self)
101107
--_level
102108

103109
def NewGoto(label as LabelStatement):
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
5
3+
4
4+
3
5+
2
6+
JS for: Boom
7+
5
8+
4
9+
3
10+
2
11+
JS for in: Boom
12+
*/
13+
function Start() {
14+
for (var a=1; a<=2; ++a) {
15+
switch (a) {
16+
case 1:
17+
for (var b=5; b>0; b--) {
18+
print(b);
19+
if (b == 2) {
20+
break;
21+
}
22+
}
23+
print("JS for: Boom");
24+
break;
25+
26+
case 2:
27+
var ts : int[] = [5,4,3,2,1,0];
28+
for (var t in ts) {
29+
print(t);
30+
if (t == 2) {
31+
break;
32+
}
33+
}
34+
print("JS for in: Boom");
35+
break;
36+
}
37+
}
38+
}
39+
40+
Start();
41+

0 commit comments

Comments
 (0)