Cast back to Object in advance of returning, to ensure the test doesn't mask a shortcoming of type pruning by pruning at the return site

This commit is contained in:
Chris Smowton
2023-11-21 14:47:00 +00:00
parent f0144d6a3d
commit 47e3d7d8a5

View File

@@ -3,15 +3,15 @@ public class Test {
public static Object testFlowThroughSwitchStmt(String s, Integer i, boolean unknown) {
Object o = unknown ? s : i;
switch (o) {
case Integer i2 -> { return i2; }
case Integer i2 -> { return (Object)i2; }
default -> { return null; }
}
}
public static Object testFlowThroughSwitchExpr(String s, Integer i, boolean unknown) {
Object o = unknown ? s : i;
Integer toRet = switch (o) {
case Integer i2 -> i2;
Object toRet = switch (o) {
case Integer i2 -> (Object)i2;
default -> null;
};
return toRet;
@@ -20,7 +20,7 @@ public class Test {
public static Object testFlowThroughBindingInstanceOf(String s, Integer i, boolean unknown) {
Object o = unknown ? s : i;
if (o instanceof Integer i2)
return i2;
return (Object)i2;
else
return null;
}