Integrated: 8294550: Sealed check for casts isn't applied to array components
Jan Lahoda
jlahoda at openjdk.org
Thu Oct 20 13:03:52 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!
This pull request has now been integrated.
Changeset: 78dc4977
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.org/jdk/commit/78dc4977863a92f990b355f6b4d2609a674ab19b
Stats: 26 lines in 2 files changed: 24 ins; 0 del; 2 mod
8294550: Sealed check for casts isn't applied to array components
Reviewed-by: vromero
-------------
PR: https://git.openjdk.org/jdk/pull/10490
More information about the compiler-dev
mailing list