RFR: 8294550: Sealed check for casts isn't applied to array components
Vicente Romero
vromero at openjdk.org
Fri Sep 30 16:30:30 UTC 2022
On Thu, 29 Sep 2022 14:24:18 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> 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!
looks sensible
-------------
Marked as reviewed by vromero (Reviewer).
PR: https://git.openjdk.org/jdk/pull/10490
More information about the compiler-dev
mailing list