Integrated: 8298184: Incorrect record component type in record patterns

Jan Lahoda jlahoda at openjdk.org
Wed Dec 7 12:07:01 UTC 2022


On Tue, 6 Dec 2022 16:56:29 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> When a type of a record type is a generic type with wildcards, per specification[1] we should do upward projection on the component type. But the current code removes wildcards. As a consequence, for record type e.g. `Box<? super String>` the type of the record component is determined to be `String`, instead of `Object`, and as a consequence code like this:
> 
>     int runIfSuperBound(I<? super String> b) {
>         if (b instanceof Box(var v)) return 1;
>         return -1;
>     }
> 
> 
> will return `-1` for `new Box<>(new StringBuilder())`.
> 
> The proposed fix is to use upward projections as per specification to compute the type of the record components.
> 
> [1] http://cr.openjdk.java.net/~gbierman/jep432%2b433/jep432+433-20221115/specs/patterns-switch-record-patterns-jls.html#jls-14.30.1

This pull request has now been integrated.

Changeset: cf63f2e3
Author:    Jan Lahoda <jlahoda at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/cf63f2e3ea93cf339d08e2865034e128d683e515
Stats:     14 lines in 2 files changed: 12 ins; 0 del; 2 mod

8298184: Incorrect record component type in record patterns

Reviewed-by: vromero

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

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


More information about the compiler-dev mailing list