Preserve Java enum semantics for explicit java.lang.Enum inheritance#25658
Open
zielinsky wants to merge 6 commits intoscala:mainfrom
Open
Preserve Java enum semantics for explicit java.lang.Enum inheritance#25658zielinsky wants to merge 6 commits intoscala:mainfrom
zielinsky wants to merge 6 commits intoscala:mainfrom
Conversation
2199230 to
e5c9626
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Scala currently accepts some explicit
java.lang.Enum[...]usages that are not consistent with Java enum semantics. In particular, F-bound checking alone is not sufficient here: it can accept programs where the type argument satisfiesE <: Enum[E], but does not actually match the enum class.This leads to problematic cases such as
enum E extends Enum[Nothing] { case X }(i11252)These cases may compile, but can break the expected Java enum behavior, especially around reflection and runtime consistency.
After discussion during the Scala Core meeting (01.04.2026), we decided that when code explicitly uses
extends java.lang.Enum[...], Scala should preserve Java enum semantics more strictly.This means we require:
java.lang.Enumtype argument to refer to the enum class itselfThis rejects examples such as:
enum E extends Enum[Nothing]enum E[A] extends Enum[E[?]]Fixes #11252
Fixes #11253
Typo in the error message has also been fixed (
paramerized->parameterized)