Skip to content

Commit 1e0766d

Browse files
committed
Add tests for case statement type test dominance against anonymous labels and fall-through
1 parent f2ff6c4 commit 1e0766d

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

java/ql/test/library-tests/switch-default-impossible-dispatch/Test.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,23 @@ case WrapperWrapper(Wrapper(String s)) -> { }
5858
case null: default: i.take(source()); // Can't call C1.take (but we don't currently notice)
5959
}
6060

61+
switch(i) {
62+
case C1 _, C2 _:
63+
i.take(source()); // Must be either C1.take or C2.take (but we don't currently notice, because neither dominates)
64+
break;
65+
default:
66+
i.take(source()); // Can't call C1.take or C2.take (but we don't currently notice, because a multi-pattern case isn't understood as a type test)
67+
}
68+
69+
switch(i) {
70+
case C1 _:
71+
case C2 _:
72+
i.take(source()); // Must be either C1.take or C2.take (but we don't currently notice, because neither dominates)
73+
break;
74+
default:
75+
i.take(source()); // Can't call C1.take or C2.take
76+
}
77+
6178
}
6279

6380
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
//semmle-extractor-options: --javac-args --release 21
1+
//semmle-extractor-options: --javac-args --release 22

java/ql/test/library-tests/switch-default-impossible-dispatch/test.expected

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,17 @@
3030
| Test.java:58:34:58:41 | source(...) | Test.java:8:65:8:65 | x |
3131
| Test.java:58:34:58:41 | source(...) | Test.java:9:74:9:74 | x |
3232
| Test.java:58:34:58:41 | source(...) | Test.java:10:82:10:82 | x |
33+
| Test.java:63:16:63:23 | source(...) | Test.java:7:65:7:65 | x |
34+
| Test.java:63:16:63:23 | source(...) | Test.java:8:65:8:65 | x |
35+
| Test.java:63:16:63:23 | source(...) | Test.java:9:74:9:74 | x |
36+
| Test.java:63:16:63:23 | source(...) | Test.java:10:82:10:82 | x |
37+
| Test.java:66:16:66:23 | source(...) | Test.java:7:65:7:65 | x |
38+
| Test.java:66:16:66:23 | source(...) | Test.java:8:65:8:65 | x |
39+
| Test.java:66:16:66:23 | source(...) | Test.java:9:74:9:74 | x |
40+
| Test.java:66:16:66:23 | source(...) | Test.java:10:82:10:82 | x |
41+
| Test.java:72:16:72:23 | source(...) | Test.java:7:65:7:65 | x |
42+
| Test.java:72:16:72:23 | source(...) | Test.java:8:65:8:65 | x |
43+
| Test.java:72:16:72:23 | source(...) | Test.java:9:74:9:74 | x |
44+
| Test.java:72:16:72:23 | source(...) | Test.java:10:82:10:82 | x |
45+
| Test.java:75:16:75:23 | source(...) | Test.java:9:74:9:74 | x |
46+
| Test.java:75:16:75:23 | source(...) | Test.java:10:82:10:82 | x |

0 commit comments

Comments
 (0)