RFR: 8301025: ClassCastException in switch with generic record [v2]

Aggelos Biboudis abimpoudis at openjdk.org
Thu Feb 2 13:00:10 UTC 2023


On Thu, 2 Feb 2023 12:08:08 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

>> Aggelos Biboudis has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   Address review
>
> src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransPatterns.java line 485:
> 
>> 483:                     cases.stream()
>> 484:                          .flatMap(c -> c.labels.stream())
>> 485:                          .map(l -> toLoadableConstant(l, seltype))
> 
> I believe it is a mistake to have non-erased types in the backend (after `TransTypes`). I.e. it is a mistake `TransPatterns` create a tree with non-erased type. Something like this might be a better solution:
> 
> diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransPatterns.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransPatterns.java
> index 57cd9671ca9..c928c7c75d1 100644
> --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransPatterns.java
> +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransPatterns.java
> @@ -334,7 +334,7 @@ public class TransPatterns extends TreeTranslator {
>              }
>              JCMethodInvocation componentAccessor =
>                      make.App(make.Select(convert(make.Ident(recordBinding), recordBinding.type), //TODO - cast needed????
> -                             component.accessor));
> +                             component.accessor)).setType(types.erasure(component.accessor.getReturnType()));
>              if (deconstructorCalls == null) {
>                  deconstructorCalls = Collections.newSetFromMap(new IdentityHashMap<>());
>              }

Ha, indeed we need to keep the invariant "it is a mistake to have non-erased types in the backend".

I am convinced. 

Thx!

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

PR: https://git.openjdk.org/jdk/pull/12200


More information about the compiler-dev mailing list