RFR: 8295020: javac emits incorrect code for for-each on an intersection type.
Srikanth Adayapalam
sadayapalam at openjdk.org
Fri Oct 14 04:32:00 UTC 2022
On Fri, 14 Oct 2022 04:16:33 GMT, Srikanth Adayapalam <sadayapalam at openjdk.org> wrote:
> Eliminate needless casts and ensure invoked method is looked up against the appropriate receiver type
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java line 3523:
> 3521: Type eType = types.skipTypeVars(tree.expr.type, false);
> 3522: tree.expr.type = types.erasure(eType);
> 3523: if (eType.isCompound())
This check can needlessly insert casts - it should be irrelevant whether tree.expr.type is a compond type. A cast should be required only when the erased tree.expr.type is not an Iterable.
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java line 3531:
> 3529: VarSymbol itvar = new VarSymbol(SYNTHETIC, names.fromString("i" + target.syntheticNameChar()),
> 3530: types.erasure(syms.iteratorType),
> 3531: currentMethodSym);
The original code seems to be a convoluted way of declaring an Iterator. Replace with a simpler more direct expression
-------------
PR: https://git.openjdk.org/jdk/pull/10710
More information about the compiler-dev
mailing list