RFR: 8254286: Wrong inference in switch expression with "null" arm

Maurizio Cimadamore mcimadamore at openjdk.java.net
Mon Oct 12 10:28:08 UTC 2020


On Fri, 9 Oct 2020 17:08:36 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Basically, for code like:
> 
>         var t1 = switch (s) {
>             case 1 -> i1;
>             case 2 -> null;
>             default -> i2;
>         };
> 
> Attr.condType is currently passing <type-of-i1>, BOT, <type-of-i2> to Types.lub. But Types.lub needs the list without
> BOT, so filtering BOT(s) out of the list.

The fix looks fine. Note that in method inference we also skip the erroneous case:

@Override
        public boolean accepts(Type t) {
            return !t.isErroneous() && !inferenceContext.free(t) &&
                    !t.hasTag(BOT);
        }

Not sure whether this applies here too - maybe erroneous types are already skipped earlier?

-------------

Marked as reviewed by mcimadamore (Reviewer).

PR: https://git.openjdk.java.net/jdk/pull/583


More information about the compiler-dev mailing list