RFR: 8295020: javac emits incorrect code for for-each on an intersection type. [v2]
Srikanth Adayapalam
sadayapalam at openjdk.org
Mon Oct 17 05:31:01 UTC 2022
On Fri, 14 Oct 2022 10:16:23 GMT, Srikanth Adayapalam <sadayapalam at openjdk.org> wrote:
>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Lower.java line 3521:
>>
>>> 3519: if (iterableType.getTypeArguments().nonEmpty())
>>> 3520: iteratorTarget = types.erasure(iterableType.getTypeArguments().head);
>>> 3521: tree.expr.type = types.erasure(types.skipTypeVars(tree.expr.type, false));
>>
>> Shouldn't types already be erased by now (Lower runs after TransTypes?)
>
> Perhaps (actually very likely). This transformation is just simplifying existing code.
> Shouldn't types already be erased by now (Lower runs after TransTypes?)
Consider this case:
<T extends A & B<String>>
void f(T t) {
for (String s : t) System.out.println(s);
}
and the line of code in Lower that reads:
tree.expr.type = types.erasure(types.skipTypeVars(tree.expr.type, false));
types.skipTypeVars(tree.expr.type, false) evaluates to:
java.lang.Object&A&B<java.lang.String>
and so the erasure call is required.
-------------
PR: https://git.openjdk.org/jdk/pull/10710
More information about the compiler-dev
mailing list