switch expression type with 'null' return expression
Anna Kozlova
anna.kozlova at jetbrains.com
Wed Sep 30 09:50:09 UTC 2020
Hi all,
The following code doesn't compile (infers i_ to Object)
interface I {
void m();
}
interface I1 extends I {}
interface I2 extends I {}
static void n(I1 i1, I2 i2, int s) {
var i_ = switch (s) {
case 1 -> i1;
case 2 -> null;
default -> i2;
};
if (i_ != null) {
i_.m(); //cannot find symbol m()
}
}
If you permute "case 1" and "case 2" switch rules, the code starts to
compile (infers i_ to I).
Looks like a bug?
Thanks,
Anna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20200930/a98cc808/attachment.htm>
More information about the compiler-dev
mailing list