Skip to content

Commit 419d530

Browse files
committed
Add test ensuring read steps via record patterns lead to type filtering
1 parent 087be2c commit 419d530

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

java/ql/test/library-tests/flow-through-binding/Test.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,31 @@ public static Object testFlowThroughBindingInstanceOf(String s, Integer i, boole
2525
return null;
2626
}
2727

28+
public static Object testFlowThroughSwitchStmtWrapper(Wrapper s, Wrapper i, boolean unknown) {
29+
Wrapper o = unknown ? s : i;
30+
switch (o) {
31+
case Wrapper(Integer i2) -> { return (Object)i2; }
32+
default -> { return null; }
33+
}
34+
}
35+
36+
public static Object testFlowThroughSwitchExprWrapper(Wrapper s, Wrapper i, boolean unknown) {
37+
Wrapper o = unknown ? s : i;
38+
Object toRet = switch (o) {
39+
case Wrapper(Integer i2) -> (Object)i2;
40+
default -> null;
41+
};
42+
return toRet;
43+
}
44+
45+
public static Object testFlowThroughBindingInstanceOfWrapper(Wrapper s, Wrapper i, boolean unknown) {
46+
Wrapper o = unknown ? s : i;
47+
if (o instanceof Wrapper(Integer i2))
48+
return (Object)i2;
49+
else
50+
return null;
51+
}
52+
2853
public static <T> T source() { return null; }
2954

3055
public static void sink(Object o) { }
@@ -37,6 +62,14 @@ public static void test(boolean unknown, boolean unknown2) {
3762
sink(testFlowThroughSwitchExpr(source1, source2, unknown));
3863
sink(testFlowThroughBindingInstanceOf(source1, source2, unknown));
3964

65+
Wrapper source1Wrapper = new Wrapper((String)source());
66+
Wrapper source2Wrapper = new Wrapper((Integer)source());
67+
sink(testFlowThroughSwitchStmtWrapper(source1Wrapper, source2Wrapper, unknown));
68+
sink(testFlowThroughSwitchExprWrapper(source1Wrapper, source2Wrapper, unknown));
69+
sink(testFlowThroughBindingInstanceOfWrapper(source1Wrapper, source2Wrapper, unknown));
70+
4071
}
4172

73+
record Wrapper(Object o) { }
74+
4275
}
Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
| Test.java:35:23:35:30 | source(...) | Test.java:36:10:36:61 | testFlowThroughSwitchStmt(...) |
2-
| Test.java:35:23:35:30 | source(...) | Test.java:37:10:37:61 | testFlowThroughSwitchExpr(...) |
3-
| Test.java:35:23:35:30 | source(...) | Test.java:38:10:38:68 | testFlowThroughBindingInstanceOf(...) |
1+
| Test.java:60:23:60:30 | source(...) | Test.java:61:10:61:61 | testFlowThroughSwitchStmt(...) |
2+
| Test.java:60:23:60:30 | source(...) | Test.java:62:10:62:61 | testFlowThroughSwitchExpr(...) |
3+
| Test.java:60:23:60:30 | source(...) | Test.java:63:10:63:68 | testFlowThroughBindingInstanceOf(...) |
4+
| Test.java:66:51:66:58 | source(...) | Test.java:67:10:67:82 | testFlowThroughSwitchStmtWrapper(...) |
5+
| Test.java:66:51:66:58 | source(...) | Test.java:68:10:68:82 | testFlowThroughSwitchExprWrapper(...) |
6+
| Test.java:66:51:66:58 | source(...) | Test.java:69:10:69:89 | testFlowThroughBindingInstanceOfWrapper(...) |

0 commit comments

Comments
 (0)