RFR: JDK-8234899: Compiler reports AssertionError for conditional operator ? : and pattern matching for instanceof
Jan Lahoda
jan.lahoda at oracle.com
Tue Dec 3 16:37:16 UTC 2019
Hi,
Consider code like:
boolean result = t ? true : (!(o1 instanceof String a3));
When javac starts to generate "(!(o1 instanceof String a3))", there is
the "false" jump pending. The "!" operator is generating its operand in
the genCond mode. But, the handling for LetExpr (into which the pattern
matching is translated) will not explicitly resolve the pending jump
(i.e. terminate the jump right before the code for ("o1 instanceof
String a3"). But as the desugared code for "o1 instanceof String a3"
will create a new variable, the pending jump is resolved at the point
the variable is generated - but that is already too late. And hence an
AssertionError, or other trouble may happen.
The proposal is to resolve (terminate) the pending jumps before
generating a LetExpr in condition mode (as is done in non-condition mode).
A similar problem may happen for switch expressions, so the proposal is
to resolve the jumps for switch expressions as well.
Proposed webrev:
http://cr.openjdk.java.net/~jlahoda/8234899/webrev.00/
JBS:
https://bugs.openjdk.java.net/browse/JDK-8234899
How does this look?
Thanks,
Jan
More information about the compiler-dev
mailing list