Skip to content

Commit 5de1cc3

Browse files
authored
Fix pattern matching instanceof not being detected inside loops (#450)
1 parent d63fc67 commit 5de1cc3

File tree

3 files changed

+63
-2
lines changed

3 files changed

+63
-2
lines changed

src/org/jetbrains/java/decompiler/modules/decompiler/IfPatternMatchProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private static void findVarsInPredecessors(List<VarVersionPair> vvs, Statement r
226226
for (StatEdge pred : st.getAllPredecessorEdges()) {
227227
Statement stat = pred.getSource();
228228
stack.add(stat);
229-
if (stat == root) {
229+
if (root.containsStatement(stat)) {
230230
continue;
231231
}
232232

testData/results/pkg/TestPatternMatching17.dec

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ public class TestPatternMatching17 {
175175
public String multiCombo(Object o, String s) {
176176
return o instanceof String s2 && !s.isEmpty() ? s2 + s : s;// 175 176 178
177177
}
178+
179+
public void testInLoop(Object[] a) {
180+
for (Object o : a) {// 182
181+
if (o instanceof String s && !s.isEmpty()) {// 183
182+
System.out.println(s);// 184
183+
}
184+
}
185+
}// 187
178186
}
179187

180188
class 'pkg/TestPatternMatching17' {
@@ -848,6 +856,47 @@ class 'pkg/TestPatternMatching17' {
848856
19 175
849857
1b 175
850858
}
859+
860+
method 'testInLoop ([Ljava/lang/Object;)V' {
861+
0 179
862+
1 179
863+
2 179
864+
4 179
865+
6 179
866+
7 179
867+
12 179
868+
13 179
869+
14 180
870+
15 180
871+
16 180
872+
17 180
873+
18 180
874+
19 180
875+
1a 180
876+
1b 180
877+
21 180
878+
22 180
879+
23 180
880+
24 180
881+
25 180
882+
26 180
883+
27 180
884+
28 180
885+
29 180
886+
2a 180
887+
2b 181
888+
2c 181
889+
2d 181
890+
2e 181
891+
2f 181
892+
30 181
893+
31 181
894+
32 181
895+
33 179
896+
34 179
897+
35 179
898+
39 184
899+
}
851900
}
852901

853902
Lines mapping:
@@ -943,6 +992,10 @@ Lines mapping:
943992
175 <-> 176
944993
176 <-> 176
945994
178 <-> 176
995+
182 <-> 180
996+
183 <-> 181
997+
184 <-> 182
998+
187 <-> 185
946999
Not mapped:
9471000
42
948-
49
1001+
49

testData/src/java17/pkg/TestPatternMatching17.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,4 +177,12 @@ public String multiCombo(Object o, String s) {
177177
}
178178
return s;
179179
}
180+
181+
public void testInLoop(Object[] a) {
182+
for (Object o : a) {
183+
if (o instanceof String s && !s.isEmpty()) {
184+
System.out.println(s);
185+
}
186+
}
187+
}
180188
}

0 commit comments

Comments
 (0)