Hello!
On behalf of the JDT compiler team, I am pleased to share that over the last several weeks we have been busy on a project to significantly overhaul, cleanup, address key gaps in implementation and to polish ECJ’s implementation of JEP 409
- Sealed Classes (https://openjdk.org/jeps/409) and how that integrates with JEP 441 - Pattern Matching for switch
This effort is now complete and has been integrated into master/HEAD and is available via the I-Builds from the Eclipse download sites.
As a part of this project,
·
Every line of code of the implementation was studied, mapping it back to the JLS and aligning ECJ’s behavior with the JLS and the reference compiler, rewriting significant portions in the process
·
Every clause of the JLS mentioning sealed types was studied and was black box tested and white box tested mapping it to the implementation
·
Every actionable issue concerning sealed types in the compiler area in both Github tracker and Bugzilla was resolved.
·
Many defects in compiling enhanced switches and switch expressions that intersect with sealed types are also addressed. In particular, switch exhaustiveness analysis has been thoroughly revamped fixing several problems.
This doesn’t mean we won’t run into defects in future
😉- but this does mean that we are on a firm footing to be able to rapidly respond to and resolve any incoming issues in these functionalities.
As a matter of fact, this mail is to alert interested parties to engage in early testing, so we can address any remaining issues before 4.34 ships – We need, welcome, and appreciate your involvement here!
For the curious and the cognoscenti, here is an extract of the tickets resolved on Sealed types relative to the initial implementation: Critical, normal, trivial; Big, medium, small; Good, bad, ugly!
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2108 :
[Sealed classes] Inconsistent type hierarchy on sealed interface when used with other from different level in class hierarchy
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2093 :
[sealed types] ECJ complains of cycles in hierarchy where none exists bug
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3122 :
[Reconciler][Sealed types] Extra errors in editor that go away on file save
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3121 :
[Sealed types] Regression in instanceof check for sealed generic classes
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3111 :
[Sealed types] Discovery and wiring of implicitly permitted subtypes can be significantly simplified.
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3096 :
[Switch][Sealed types] Bad static analysis with the old switch syntax + an exhaustive pattern matching on a sealed type throws a MatchException bug compiler
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3039 :
[Sealed types] Broken program crashes the compiler
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3166 :
[Sealed types][Enhanced Switch] Exhaustiveness in pattern matching switch is wrong
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3038 :
[Sealed types] ParameterizedTypeBinding.permittedTypes() needs more rigor
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3035 :
[switch][sealed types] ECJ fails to signal a completely dominated case arm
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3031 :
[Switch][Sealed types] Incorrect exhaustiveness check leads to MatchException at runtime
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3009 :
A sealed interface with generic causes IllegalStateException and nothing can be done then
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2722 :
Switch pattern matching accepts invalid case
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2720 :
[Sealed Types + Enhanced Switch] Incorrect diagnostic about switch not being exhaustive
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2719 :
[Switch _expression_ + Sealed Types] Suspect diagnostic about switch _expression_ being inexhaustive
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2714 :
[Sealed types + switch _expression_] Internal inconsistency warning at compile time and verify error at runtime
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2709 :
[Sealed types] Disjointness behavior difference vis a vis javac
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2667 :
[Sealed Types] Failure to cast an Object to a generic sealed interface type bug compiler regression
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2652 :
[Sealed Types] Permits clause handling in grammar/parser is unnecessarily complicated
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2595 :
[sealed types] ECJ accepts a cast from a disjoint interface to a sealed interface
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2574 :
[Sealed types][selection] Can't navigate in files in 2nd level child
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2554 :
[sealed types] ECJ should not accept type annotations on permitted types
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2540 :
[Sealed types] Completion fails within the body of a permitted class regression
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2521 :
NPE on exhaustive pattern matching switch expressions with sealed interface (Java 21, 3.19.500.v20240601-0610).
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2513 :
[Enhanced switch] Unexpected MatchException thrown at runtime
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2508 :
[Switch _expression_] Compiler erroneously treats guarded case patterns as covering switch selector type
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2503 :
[Switch _expression_] Switching on sealed interface instance compiles even when the switch _expression_ does not cover all possible input values
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2146 :
Incorrect "should be a permitted subtype" error if sealed type is an inner type of record
https://github.com/eclipse-jdt/eclipse.jdt.core/pull/3123 :
Streamline error handling for sealed types
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1998 :
[Sealed classes] Incorrect Reconciler error: The type A that implements a sealed interface I should be a permitted subtype of I
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1808 :
[sealed-classes] Incorrect unused import warning
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1788 :
Inference issue between the diamond syntax and pattern matching (switch on objects)
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1735 :
[Sealed types][Switch] Pattern switch - ECJ accepts code rejected by javac
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/1725 :
[21] Wrongly needing a default case for a switch _expression_
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/581 :
Sealed classes permits clause
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/62 :
[Reconciler][Sealed types] Inconsistent type hierarchy with sealed classes compiler
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3144 :
[Sealed types] Diagnostic can be more direct when a @FunctionalInterface is declared sealed
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3100 :
[Sealed types] Duplicate diagnostics for illegal modifier combination
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3007 :
[Sealed types] Extra and spurious error messages with faulty type sealing
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2708 :
Error in JDT Core during AST creation when using exhaustive switch statement and @NotNull
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2707 :
[Sealed types] ECJ allows a class to be declared as both sealed and non-sealed
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2672 :
[Sealed Types] Strange error from ECJ: Syntax error on token "permits", permits expected
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2654 :
[Sealed Types] Compiler does not handle non-sealed contextual keyword correctly
https://github.com/eclipse-jdt/eclipse.jdt.core/issues/2017 :
[Patterns][internal] toString() output of AST nodes shows up with modifier sealed for pattern variables
https://bugs.eclipse.org/bugs/show_bug.cgi?id=576378 :
[compiler] Wrong rawtype warning and wrong compilation of generic type reference in permits clause
https://bugs.eclipse.org/bugs/show_bug.cgi?id=576471 :
Sealed type hierarchy doesn't compile if there are redundant type references
https://bugs.eclipse.org/bugs/show_bug.cgi?id=577787 :
[17] False positive error for explicitly permitted class extending a sealed class
https://bugs.eclipse.org/bugs/show_bug.cgi?id=577872 :
[17] Incremental builder problems with sealed types: Bogus error: The type C that implements a sealed interface Types.B should be a permitted subtype of Types.B
https://bugs.eclipse.org/bugs/show_bug.cgi?id=565234 :
[15] An exception occurred while getting the Javadoc for permit class
https://bugs.eclipse.org/bugs/show_bug.cgi?id=574573 :
[17] Invalid warning for parameterized sealed type
https://bugs.eclipse.org/bugs/show_bug.cgi?id=575388 :
[16] Hover on case shows sealed value while debugging
https://bugs.eclipse.org/bugs/show_bug.cgi?id=576374 :
Switch pattern matching exhaustiveness check false positive
https://bugs.eclipse.org/bugs/show_bug.cgi?id=576471 :
Sealed type hierarchy doesn't compile if there are redundant type references
https://bugs.eclipse.org/bugs/show_bug.cgi?id=574943 :
[17][compiler][sealed] Incorrect compile error when sealed class tries to permit an interface
Thanks and regards,
Srikanth