RFR: 8371155: Type annotations on local variables are classified after the local var initializer has been type checked
Vicente Romero
vromero at openjdk.org
Thu Feb 26 19:08:54 UTC 2026
On Thu, 26 Feb 2026 17:51:40 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
>> src/jdk.compiler/share/classes/com/sun/tools/javac/code/TypeAnnotations.java line 490:
>>
>>> 488: alternatives.add(res);
>>> 489: alternatives.addAll(ut.alternatives_field.tail);
>>> 490: return new UnionClassType((ClassType) ut.getLub(), alternatives.toList());
>>
>> question: so the type of a union type could be different depending on the presence or not of type annotations?
>
> The idea is that the "unified" type would be the same (getting `ut.getLub()` from the original type), but the first alternative would be enhanced with the type annotation, as is done for ordinary `ClassType`.
>
> There's `type.tsym.type` conversions happening here (the `UnionClassType` will keep `type.tsym`, and `getLub` will do `tsym.type`), but given exceptions cannot be generic, it seems the type after this cascade should be the same as before it(?).
got it, thanks
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/29817#discussion_r2860811735
More information about the compiler-dev
mailing list