Skip to content

Commit 9fa2f19

Browse files
committed
Add test for guards in the presence of fall-through between pattern and constant cases
1 parent c48e64e commit 9fa2f19

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

java/ql/test/library-tests/guards12/PrintAst.expected

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,23 @@ Test.java:
8282
# 24| 0: [StringLiteral] "g"
8383
# 25| 3: [DefaultCase] default
8484
# 25| -1: [BlockStmt] { ... }
85+
# 27| 5: [SwitchStmt] switch (...)
86+
# 27| -1: [VarAccess] s
87+
# 28| 0: [ConstCase] case ...
88+
# 28| 0: [StringLiteral] "h"
89+
# 29| 1: [PatternCase] case <Pattern>
90+
# 29| -3: [EQExpr] ... == ...
91+
# 29| 0: [VarAccess] len
92+
# 29| 1: [IntegerLiteral] 4
93+
#-----| 0: (Pattern case declaration)
94+
# 29| 0: [TypeAccess] String
95+
# 29| 1: [LocalVariableDeclExpr] <anonymous local variable>
96+
# 30| 2: [ConstCase] case ...
97+
# 30| 0: [StringLiteral] "i"
98+
# 31| 3: [LocalVariableDeclStmt] var ...;
99+
# 31| 0: [TypeAccess] String
100+
# 31| 1: [LocalVariableDeclExpr] target
101+
# 31| 0: [StringLiteral] "Shouldn't be controlled by any of those tests"
102+
# 32| 4: [BreakStmt] break
103+
# 33| 5: [DefaultCase] default
104+
# 34| 6: [BreakStmt] break

java/ql/test/library-tests/guards12/Test.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,14 @@ void foo(String s, boolean unknown) {
2424
case "g" -> { }
2525
default -> { }
2626
}
27+
switch (s) {
28+
case "h":
29+
case String _ when len == 4:
30+
case "i":
31+
String target = "Shouldn't be controlled by any of those tests";
32+
break;
33+
default:
34+
break;
35+
}
2736
}
2837
}

java/ql/test/library-tests/guards12/guard.expected

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
hasBranchEdge
2-
| Test.java:4:7:4:22 | case ... | Test.java:2:39:27:3 | { ... } | Test.java:4:7:4:22 | case ... | true |
3-
| Test.java:5:7:5:17 | case ... | Test.java:2:39:27:3 | { ... } | Test.java:5:7:5:17 | case ... | true |
4-
| Test.java:6:7:6:17 | case ... | Test.java:2:39:27:3 | { ... } | Test.java:6:7:6:17 | case ... | true |
5-
| Test.java:7:7:7:16 | default | Test.java:2:39:27:3 | { ... } | Test.java:7:7:7:16 | default | true |
2+
| Test.java:4:7:4:22 | case ... | Test.java:2:39:36:3 | { ... } | Test.java:4:7:4:22 | case ... | true |
3+
| Test.java:5:7:5:17 | case ... | Test.java:2:39:36:3 | { ... } | Test.java:5:7:5:17 | case ... | true |
4+
| Test.java:6:7:6:17 | case ... | Test.java:2:39:36:3 | { ... } | Test.java:6:7:6:17 | case ... | true |
5+
| Test.java:7:7:7:16 | default | Test.java:2:39:36:3 | { ... } | Test.java:7:7:7:16 | default | true |
66
| Test.java:10:7:10:22 | case ... | Test.java:3:9:3:21 | x | Test.java:10:7:10:22 | case ... | true |
77
| Test.java:11:7:11:17 | case ... | Test.java:3:9:3:21 | x | Test.java:11:7:11:17 | case ... | true |
88
| Test.java:12:7:12:17 | case ... | Test.java:3:9:3:21 | x | Test.java:12:7:12:17 | case ... | true |
@@ -31,6 +31,16 @@ hasBranchEdge
3131
| Test.java:24:7:24:17 | case ... | Test.java:23:19:23:20 | s2 | Test.java:24:7:24:17 | case ... | true |
3232
| Test.java:25:7:25:16 | default | Test.java:23:7:23:37 | case <Pattern> | Test.java:25:7:25:16 | default | true |
3333
| Test.java:25:7:25:16 | default | Test.java:23:19:23:20 | s2 | Test.java:25:7:25:16 | default | true |
34+
| Test.java:28:7:28:15 | case ... | Test.java:27:5:27:14 | switch (...) | Test.java:28:7:28:15 | case ... | true |
35+
| Test.java:29:7:29:34 | case <Pattern> | Test.java:29:7:29:34 | case <Pattern> | Test.java:29:19:29:19 | <anonymous local variable> | true |
36+
| Test.java:29:7:29:34 | case <Pattern> | Test.java:29:7:29:34 | case <Pattern> | Test.java:30:7:30:15 | case ... | false |
37+
| Test.java:29:7:29:34 | case <Pattern> | Test.java:29:7:29:34 | case <Pattern> | Test.java:33:7:33:14 | default | false |
38+
| Test.java:29:26:29:33 | ... == ... | Test.java:29:19:29:19 | <anonymous local variable> | Test.java:30:7:30:15 | case ... | false |
39+
| Test.java:29:26:29:33 | ... == ... | Test.java:29:19:29:19 | <anonymous local variable> | Test.java:30:7:30:15 | case ... | true |
40+
| Test.java:29:26:29:33 | ... == ... | Test.java:29:19:29:19 | <anonymous local variable> | Test.java:33:7:33:14 | default | false |
41+
| Test.java:30:7:30:15 | case ... | Test.java:29:7:29:34 | case <Pattern> | Test.java:30:7:30:15 | case ... | true |
42+
| Test.java:33:7:33:14 | default | Test.java:29:7:29:34 | case <Pattern> | Test.java:33:7:33:14 | default | true |
43+
| Test.java:33:7:33:14 | default | Test.java:29:19:29:19 | <anonymous local variable> | Test.java:33:7:33:14 | default | true |
3444
#select
3545
| Test.java:5:7:5:17 | case ... | Test.java:3:20:3:20 | s | Test.java:5:12:5:14 | "c" | true | false | Test.java:7:7:7:16 | default |
3646
| Test.java:5:7:5:17 | case ... | Test.java:3:20:3:20 | s | Test.java:5:12:5:14 | "c" | true | true | Test.java:5:7:5:17 | case ... |
@@ -48,3 +58,6 @@ hasBranchEdge
4858
| Test.java:23:27:23:34 | ... == ... | Test.java:23:27:23:29 | len | Test.java:23:34:23:34 | 4 | true | true | Test.java:23:39:23:41 | { ... } |
4959
| Test.java:24:7:24:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:24:12:24:14 | "g" | true | false | Test.java:25:7:25:16 | default |
5060
| Test.java:24:7:24:17 | case ... | Test.java:21:13:21:41 | ...?...:... | Test.java:24:12:24:14 | "g" | true | true | Test.java:24:7:24:17 | case ... |
61+
| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | false | Test.java:33:7:33:14 | default |
62+
| Test.java:28:7:28:15 | case ... | Test.java:27:13:27:13 | s | Test.java:28:12:28:14 | "h" | true | true | Test.java:28:7:28:15 | case ... |
63+
| Test.java:30:7:30:15 | case ... | Test.java:27:13:27:13 | s | Test.java:30:12:30:14 | "i" | true | false | Test.java:33:7:33:14 | default |

0 commit comments

Comments
 (0)