Add test ensuring read steps via record patterns lead to type filtering

This commit is contained in:
Chris Smowton
2023-11-21 19:23:49 +00:00
parent 087be2cca8
commit 419d530a06
2 changed files with 39 additions and 3 deletions

View File

@@ -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) { }
}

View File

@@ -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(...) |