Skip to content

Commit

Permalink
Add test for labeled blocks in constructor (#437)
Browse files Browse the repository at this point in the history
  • Loading branch information
Earthcomputer authored Dec 4, 2024
1 parent 3da350a commit af44be8
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 1 deletion.
4 changes: 3 additions & 1 deletion test/org/jetbrains/java/decompiler/SingleClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private void registerDefault() {
register(JAVA_8_NODEBUG, "TestArrayNull2");
register(JAVA_8, "TestArrayNullAccess");
register(JAVA_8, "TestArrayTernary");
// TODO: Do while loops become standard while loops
// TODO: Do while loops become standard while loops, and creates incorrect short-circuiting
register(JAVA_8, "TestAssignmentInDoWhile");
register(JAVA_8, "TestBooleanAssignment");
register(JAVA_8, "TestCastObjectToPrimitive");
Expand Down Expand Up @@ -520,6 +520,8 @@ private void registerDefault() {
registerRaw(CUSTOM, "TestHotjava");
registerRaw(CUSTOM, "TestJava1Synchronized");
register(JAVA_8, "TestLabeledBreaks");
// TODO: the super() call ends up inside the labeled block
register(JAVA_8, "TestLabeledBlockInConstructor");
// TODO: test9&10- for loop not created, loop extractor needs another pass
register(JAVA_8, "TestSwitchLoop");
register(JAVA_8, "TestSwitchFinally");
Expand Down
80 changes: 80 additions & 0 deletions testData/results/pkg/TestLabeledBlockInConstructor.dec
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package pkg;

public class TestLabeledBlockInConstructor {
public TestLabeledBlockInConstructor() {
boolean result;
label12: {
super();// 4
if (Math.random() < 0.5) {// 7
System.out.println(1);// 8
if (Math.random() < 0.5) {// 9
result = false;// 10
break label12;// 11
}
}

result = true;// 14
}

System.out.println(result);// 16
}// 17
}

class 'pkg/TestLabeledBlockInConstructor' {
method '<init> ()V' {
1 6
2 6
3 6
4 7
5 7
6 7
7 7
8 7
9 7
a 7
b 7
c 7
d 7
e 8
f 8
10 8
11 8
12 8
13 8
14 8
15 9
16 9
17 9
18 9
19 9
1a 9
1b 9
1c 9
1d 9
1e 9
1f 10
20 10
21 11
24 15
25 15
26 18
27 18
28 18
29 18
2a 18
2b 18
2c 18
2d 19
}
}

Lines mapping:
4 <-> 7
7 <-> 8
8 <-> 9
9 <-> 10
10 <-> 11
11 <-> 12
14 <-> 16
16 <-> 19
17 <-> 20
18 changes: 18 additions & 0 deletions testData/src/java8/pkg/TestLabeledBlockInConstructor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package pkg;

public class TestLabeledBlockInConstructor {
public TestLabeledBlockInConstructor() {
boolean result;
block: {
if (Math.random() < 0.5) {
System.out.println(1); // print statement to prevent simplification into ||
if (Math.random() < 0.5) {
result = false;
break block;
}
}
result = true;
}
System.out.println(result);
}
}

0 comments on commit af44be8

Please sign in to comment.