RFR: 8294550: Sealed check for casts isn't applied to array components
Jan Lahoda
jlahoda at openjdk.org
Thu Sep 29 14:29:58 UTC 2022
For code like:
sealed interface I permits A {}
final class A implements I {}
interface J {}
J j = null;
I i = (I) j; //error reported here, as no instance of J can implement I
J[] jj = null;
I[] i = (I[]) jj; //incorrectly no error reported here, despite JLS saying there must be a narrowing conversion from J to I in this case, which there isn't as per the case above
The cause for this is that we check the sealed constraints at the end of `Types.isCastable`, and only for classes, not for arrays. It would be possible to enhance the check to include array types, but feels clearer and more reliable to recurse, and do a full castability check on the element types.
A sketch of a CSR is here:
https://bugs.openjdk.org/browse/JDK-8294586
Feedback is welcome!
-------------
Commit messages:
- 8294550: Sealed check for casts isn't applied to array components
Changes: https://git.openjdk.org/jdk/pull/10490/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=10490&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8294550
Stats: 26 lines in 2 files changed: 24 ins; 0 del; 2 mod
Patch: https://git.openjdk.org/jdk/pull/10490.diff
Fetch: git fetch https://git.openjdk.org/jdk pull/10490/head:pull/10490
PR: https://git.openjdk.org/jdk/pull/10490
More information about the compiler-dev
mailing list