RFR: JDK-8214113: Switch expressions may have constant type and may be skipped during write

Jan Lahoda jan.lahoda at oracle.com
Wed Nov 21 12:41:27 UTC 2018


Hi,

Consider switch expression produces only a single constant value, like:
switch (expr) {
     default:
         counter++;
         break 1;
}

Then Attr.condType returns the type of the given constant value, and if 
that is a constant type, the type of the whole switch expression is a 
constant type. And Gen may then elide the whole switch expression, which 
is wrong, as it may contain side-effects, or all the other arms may the 
throwing an exception.

The solution would be to simply call .baseType() on the result, but 
simply deleting the special case for a single output value should work 
as well, as the following condition should handle the single output 
value case well.

Bug: https://bugs.openjdk.java.net/browse/JDK-8214113
Webrev: http://cr.openjdk.java.net/~jlahoda/8214113/webrev.00/

How does this look?

Thanks,
     Jan


More information about the compiler-dev mailing list