RFR: 8298184: Incorrect record component type in record patterns
Jan Lahoda
jlahoda at openjdk.org
Tue Dec 6 17:05:50 UTC 2022
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
-------------
Commit messages:
- 8298184: Incorrect record component type in record patterns
Changes: https://git.openjdk.org/jdk/pull/11543/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=11543&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8298184
Stats: 14 lines in 2 files changed: 12 ins; 0 del; 2 mod
Patch: https://git.openjdk.org/jdk/pull/11543.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/11543/head:pull/11543
PR: https://git.openjdk.org/jdk/pull/11543
More information about the compiler-dev
mailing list