Skip to content

Commit ef138de

Browse files
committed
Add test for broken pattern matching before loops
1 parent 6281238 commit ef138de

File tree

4 files changed

+137
-2
lines changed

4 files changed

+137
-2
lines changed

src/org/jetbrains/java/decompiler/util/DotExporter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ private static String statToDot(Statement stat, String name, Map<Statement, Stri
177177

178178
String edgeType = getEdgeType(edge);
179179

180-
buffer.append(sourceId + "->" + destId + "[color=blue" + (edgeType != null ? ",fontcolor=blue,label=\"" + edgeType + "\"" : "") + "];\r\n");
180+
buffer.append(sourceId + "->" + destId + "[color=pink" + (edgeType != null ? ",fontcolor=blue,label=\"" + edgeType + "\"" : "") + "];\r\n");
181181

182182
referenced.add(edge.getSource().id);
183183

@@ -776,7 +776,7 @@ public static void errorToDotFile(Statement stat, String name) {
776776
}
777777
}
778778

779-
public static void toDotFile(VarVersionsGraph graph, StructMethod mt, String suffix, HashMap<VarVersionPair, VarVersionPair> varAssignmentMap) {
779+
public static void toDotFile(VarVersionsGraph graph, StructMethod mt, String suffix, Map<VarVersionPair, VarVersionPair> varAssignmentMap) {
780780
if (!DUMP_DOTS)
781781
return;
782782
try{

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,8 @@ private void registerDefault() {
708708
register(JAVA_21, "TestCastIntersectionJ21");
709709
register(JAVA_16, "TestRecordLocal");
710710
register(JAVA_8, "TestAnonymousClassToLambda");
711+
// TODO: broken stack processing, deleted ternary!
712+
register(JAVA_17, "TestPatternMatchingLoops");
711713
}
712714

713715
private void registerEntireClassPath() {
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package pkg;
2+
3+
import java.util.List;
4+
5+
public class TestPatternMatchingLoops {
6+
// $VF: One or more variable merging failures!
7+
// $VF: Could not properly define all variable types!
8+
public void test(TestPatternMatchingLoops.I i) {
9+
System.out.println(i);// 20
10+
if (i != null) {// 22
11+
<unknown> var10000;
12+
for (TestPatternMatchingLoops l : var10000_1) {// 28
13+
if (l != null) {// 29
14+
System.out.println(l);// 33
15+
}
16+
}
17+
}
18+
}// 23 35
19+
20+
public static class Holder implements TestPatternMatchingLoops.I {
21+
public List<TestPatternMatchingLoops> list;
22+
23+
@Override
24+
public List<TestPatternMatchingLoops> get() {
25+
return List.of();// 15
26+
}
27+
}
28+
29+
public interface I {
30+
List<TestPatternMatchingLoops> get();
31+
}
32+
}
33+
34+
class 'pkg/TestPatternMatchingLoops' {
35+
method 'test (Lpkg/TestPatternMatchingLoops$I;)V' {
36+
0 8
37+
1 8
38+
2 8
39+
3 8
40+
4 8
41+
5 8
42+
6 8
43+
7 9
44+
8 9
45+
9 9
46+
a 9
47+
b 17
48+
36 11
49+
37 11
50+
38 11
51+
39 11
52+
3a 11
53+
3b 11
54+
3c 11
55+
3d 11
56+
3e 11
57+
3f 11
58+
40 11
59+
41 12
60+
42 12
61+
43 12
62+
44 12
63+
45 12
64+
49 13
65+
4a 13
66+
4b 13
67+
4c 13
68+
4d 13
69+
4e 13
70+
4f 13
71+
50 13
72+
54 17
73+
}
74+
}
75+
76+
class 'pkg/TestPatternMatchingLoops$Holder' {
77+
method 'get ()Ljava/util/List;' {
78+
0 24
79+
1 24
80+
2 24
81+
3 24
82+
}
83+
}
84+
85+
Lines mapping:
86+
15 <-> 25
87+
20 <-> 9
88+
22 <-> 10
89+
23 <-> 18
90+
28 <-> 12
91+
29 <-> 13
92+
33 <-> 14
93+
35 <-> 18
94+
Not mapped:
95+
26
96+
30
97+
34
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package pkg;
2+
3+
import java.util.List;
4+
5+
public class TestPatternMatchingLoops {
6+
public interface I {
7+
List<TestPatternMatchingLoops> get();
8+
}
9+
10+
public static class Holder implements I {
11+
public List<TestPatternMatchingLoops> list;
12+
13+
@Override
14+
public List<TestPatternMatchingLoops> get() {
15+
return List.of();
16+
}
17+
}
18+
19+
public void test(I i) {
20+
System.out.println(i);
21+
22+
if (i == null) {
23+
return;
24+
}
25+
26+
List<TestPatternMatchingLoops> list = i instanceof Holder holder ? holder.list : i.get();
27+
28+
for (TestPatternMatchingLoops l : list) {
29+
if (l == null) {
30+
continue;
31+
}
32+
33+
System.out.println(l);
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)