mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Add test ensuring read steps via record patterns lead to type filtering
This commit is contained in:
@@ -25,6 +25,31 @@ public class Test {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object testFlowThroughSwitchStmtWrapper(Wrapper s, Wrapper i, boolean unknown) {
|
||||
Wrapper o = unknown ? s : i;
|
||||
switch (o) {
|
||||
case Wrapper(Integer i2) -> { return (Object)i2; }
|
||||
default -> { return null; }
|
||||
}
|
||||
}
|
||||
|
||||
public static Object testFlowThroughSwitchExprWrapper(Wrapper s, Wrapper i, boolean unknown) {
|
||||
Wrapper o = unknown ? s : i;
|
||||
Object toRet = switch (o) {
|
||||
case Wrapper(Integer i2) -> (Object)i2;
|
||||
default -> null;
|
||||
};
|
||||
return toRet;
|
||||
}
|
||||
|
||||
public static Object testFlowThroughBindingInstanceOfWrapper(Wrapper s, Wrapper i, boolean unknown) {
|
||||
Wrapper o = unknown ? s : i;
|
||||
if (o instanceof Wrapper(Integer i2))
|
||||
return (Object)i2;
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
public static <T> T source() { return null; }
|
||||
|
||||
public static void sink(Object o) { }
|
||||
@@ -37,6 +62,14 @@ public class Test {
|
||||
sink(testFlowThroughSwitchExpr(source1, source2, unknown));
|
||||
sink(testFlowThroughBindingInstanceOf(source1, source2, unknown));
|
||||
|
||||
Wrapper source1Wrapper = new Wrapper((String)source());
|
||||
Wrapper source2Wrapper = new Wrapper((Integer)source());
|
||||
sink(testFlowThroughSwitchStmtWrapper(source1Wrapper, source2Wrapper, unknown));
|
||||
sink(testFlowThroughSwitchExprWrapper(source1Wrapper, source2Wrapper, unknown));
|
||||
sink(testFlowThroughBindingInstanceOfWrapper(source1Wrapper, source2Wrapper, unknown));
|
||||
|
||||
}
|
||||
|
||||
record Wrapper(Object o) { }
|
||||
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
| Test.java:35:23:35:30 | source(...) | Test.java:36:10:36:61 | testFlowThroughSwitchStmt(...) |
|
||||
| Test.java:35:23:35:30 | source(...) | Test.java:37:10:37:61 | testFlowThroughSwitchExpr(...) |
|
||||
| Test.java:35:23:35:30 | source(...) | Test.java:38:10:38:68 | testFlowThroughBindingInstanceOf(...) |
|
||||
| Test.java:60:23:60:30 | source(...) | Test.java:61:10:61:61 | testFlowThroughSwitchStmt(...) |
|
||||
| Test.java:60:23:60:30 | source(...) | Test.java:62:10:62:61 | testFlowThroughSwitchExpr(...) |
|
||||
| Test.java:60:23:60:30 | source(...) | Test.java:63:10:63:68 | testFlowThroughBindingInstanceOf(...) |
|
||||
| Test.java:66:51:66:58 | source(...) | Test.java:67:10:67:82 | testFlowThroughSwitchStmtWrapper(...) |
|
||||
| Test.java:66:51:66:58 | source(...) | Test.java:68:10:68:82 | testFlowThroughSwitchExprWrapper(...) |
|
||||
| Test.java:66:51:66:58 | source(...) | Test.java:69:10:69:89 | testFlowThroughBindingInstanceOfWrapper(...) |
|
||||
|
||||
Reference in New Issue
Block a user