Skip to content

Commit af44be8

Browse files
Add test for labeled blocks in constructor (#437)
1 parent 3da350a commit af44be8

File tree

3 files changed

+101
-1
lines changed

3 files changed

+101
-1
lines changed

test/org/jetbrains/java/decompiler/SingleClassesTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ private void registerDefault() {
277277
register(JAVA_8_NODEBUG, "TestArrayNull2");
278278
register(JAVA_8, "TestArrayNullAccess");
279279
register(JAVA_8, "TestArrayTernary");
280-
// TODO: Do while loops become standard while loops
280+
// TODO: Do while loops become standard while loops, and creates incorrect short-circuiting
281281
register(JAVA_8, "TestAssignmentInDoWhile");
282282
register(JAVA_8, "TestBooleanAssignment");
283283
register(JAVA_8, "TestCastObjectToPrimitive");
@@ -520,6 +520,8 @@ private void registerDefault() {
520520
registerRaw(CUSTOM, "TestHotjava");
521521
registerRaw(CUSTOM, "TestJava1Synchronized");
522522
register(JAVA_8, "TestLabeledBreaks");
523+
// TODO: the super() call ends up inside the labeled block
524+
register(JAVA_8, "TestLabeledBlockInConstructor");
523525
// TODO: test9&10- for loop not created, loop extractor needs another pass
524526
register(JAVA_8, "TestSwitchLoop");
525527
register(JAVA_8, "TestSwitchFinally");
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package pkg;
2+
3+
public class TestLabeledBlockInConstructor {
4+
public TestLabeledBlockInConstructor() {
5+
boolean result;
6+
label12: {
7+
super();// 4
8+
if (Math.random() < 0.5) {// 7
9+
System.out.println(1);// 8
10+
if (Math.random() < 0.5) {// 9
11+
result = false;// 10
12+
break label12;// 11
13+
}
14+
}
15+
16+
result = true;// 14
17+
}
18+
19+
System.out.println(result);// 16
20+
}// 17
21+
}
22+
23+
class 'pkg/TestLabeledBlockInConstructor' {
24+
method '<init> ()V' {
25+
1 6
26+
2 6
27+
3 6
28+
4 7
29+
5 7
30+
6 7
31+
7 7
32+
8 7
33+
9 7
34+
a 7
35+
b 7
36+
c 7
37+
d 7
38+
e 8
39+
f 8
40+
10 8
41+
11 8
42+
12 8
43+
13 8
44+
14 8
45+
15 9
46+
16 9
47+
17 9
48+
18 9
49+
19 9
50+
1a 9
51+
1b 9
52+
1c 9
53+
1d 9
54+
1e 9
55+
1f 10
56+
20 10
57+
21 11
58+
24 15
59+
25 15
60+
26 18
61+
27 18
62+
28 18
63+
29 18
64+
2a 18
65+
2b 18
66+
2c 18
67+
2d 19
68+
}
69+
}
70+
71+
Lines mapping:
72+
4 <-> 7
73+
7 <-> 8
74+
8 <-> 9
75+
9 <-> 10
76+
10 <-> 11
77+
11 <-> 12
78+
14 <-> 16
79+
16 <-> 19
80+
17 <-> 20
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package pkg;
2+
3+
public class TestLabeledBlockInConstructor {
4+
public TestLabeledBlockInConstructor() {
5+
boolean result;
6+
block: {
7+
if (Math.random() < 0.5) {
8+
System.out.println(1); // print statement to prevent simplification into ||
9+
if (Math.random() < 0.5) {
10+
result = false;
11+
break block;
12+
}
13+
}
14+
result = true;
15+
}
16+
System.out.println(result);
17+
}
18+
}

0 commit comments

Comments
 (0)