RFR: 8298184: Incorrect record component type in record patterns
Vicente Romero
vromero at openjdk.org
Tue Dec 6 23:21:05 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
looks sensible
-------------
Marked as reviewed by vromero (Reviewer).
PR: https://git.openjdk.org/jdk/pull/11543
More information about the compiler-dev
mailing list