RFR: 8343306: javac is failing to determine disjoint-ness between a class and a sealed interface [v2]
Vicente Romero
vromero at openjdk.org
Thu Oct 31 15:47:17 UTC 2024
> For code like:
>
>
> class Test {
> sealed interface I permits C1 {}
> non-sealed class C1 implements I {}
> class C2 extends C1 {}
> class C3 {}
> I m(int s, C3 c3) {
> I i = (I)c3;
> }
> }
>
> javac is failing to issue an error and accepts this code. The spec is clear stating that code like this should be rejected. See:
>
> 5.1.6.1 Allowed Narrowing Reference Conversion:
>
> • A class named C is disjoint from an interface named I if (i) it is not the case that
> C <: I , and (ii) one of the following cases applies:
> – C is freely extensible (§8.1.1.2), and I is sealed , and C is disjoint from all of
> the permitted direct subclasses and subinterfaces of I .
>
> and just below it continues:
> • A class named C is disjoint from another class named D if (i) it is not the case
> that C <: D , and (ii) it is not the case that D <: C .
>
> so here we have the `C3` is a freely extensible class and interface `I` is sealed and `C3` is disjoint from `C1` which is is the permitted subclass of interface `I`
>
> This PR should sync javac with the spec
>
> TIA
Vicente Romero has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:
- Merge branch 'master' into JDK-8343306
- 8343306: javac is failing to determine disjoint-ness between a class and a sealed interface
-------------
Changes:
- all: https://git.openjdk.org/jdk/pull/21794/files
- new: https://git.openjdk.org/jdk/pull/21794/files/38f0de17..9dd1430f
Webrevs:
- full: https://webrevs.openjdk.org/?repo=jdk&pr=21794&range=01
- incr: https://webrevs.openjdk.org/?repo=jdk&pr=21794&range=00-01
Stats: 2279 lines in 296 files changed: 932 ins; 369 del; 978 mod
Patch: https://git.openjdk.org/jdk/pull/21794.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/21794/head:pull/21794
PR: https://git.openjdk.org/jdk/pull/21794
More information about the compiler-dev
mailing list