RFR: 8361499: Intersection type cast causes javac crash with -Xjcov [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Wed Jul 9 21:09:43 UTC 2025


On Wed, 9 Jul 2025 17:40:58 GMT, Vicente Romero <vromero at openjdk.org> wrote:

>> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java line 1145:
>> 
>>> 1143: 
>>> 1144:     public void visitTypeIntersection(JCTypeIntersection tree) {
>>> 1145:         result = translate(tree.bounds, null).head;
>> 
>> Are we 100% sure that the type of the new result is the same as the old one? I'm trying to locate what `erasure(tree.type)` might have done -- but I can't see any code in `Types.erasure` that deals with intersections??
>
> The way the compiler deals with the erasure of intersections is a bit convoluted. Basically when the class symbol representing the intersection is created, its erasure is preset to its first explicit bound, provided that it is not a type variable, but this would be an erroneous case anyways. The code is at `Types::makeIntersectionType`. Later on, if `Types::erasure` is invoked on the intersection type, this already erased type is just read and returned, see method `visitClassType` at the erasure visitor in `Types`. Pasted below for quick access:
> 
>            public Type visitClassType(ClassType t, Boolean recurse) {
>                 Type erased = t.tsym.erasure(Types.this);
>                 if (recurse) {
>                     erased = new ErasedClassType(erased.getEnclosingType(),erased.tsym,
>                             t.dropMetadata(Annotations.class).getMetadata());
>                     return erased;
>                 } else {
>                     return combineMetadata(erased, t);
>                 }
>             }

Ok, so the erasure of the intersection seems to be set at the erasure of its "first explicit bound", which should be equivalent to the new code (since it projects the intersection to its first component -- and given that all the components in an intersection type AST _are_ explicit).

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/26203#discussion_r2195974388


More information about the compiler-dev mailing list