fix: #26132 unsound Nothing cast in Mirror.fromProduct for F-bounded case class#26268
Open
halotukozak wants to merge 2 commits into
Open
fix: #26132 unsound Nothing cast in Mirror.fromProduct for F-bounded case class#26268halotukozak wants to merge 2 commits into
halotukozak wants to merge 2 commits into
Conversation
…sses For an F-bounded case class such as `case class FB[T <: B[T]](v: T)`, the synthesized `fromProduct` reconstructed the constructor type arguments by instantiating the type variables to their solved bounds. The constraint solver picks `Nothing` as the solution because the parameter occurs in its own upper bound, so the generated body cast product elements to `Nothing` and crashed at runtime with a ClassCastException. When the solved instance is `Nothing` and the parameter is genuinely F-bounded, fall back to the declared upper bound with self-references substituted by `Nothing` (e.g. `B[T]` becomes `B[Nothing]`), which erases to a sound cast for every legal instantiation. Fixes scala#26132. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Fixes #26132
How much have you relied on LLM-based tools in this contribution?
Extensively, for finding the root cause. Self-reviewed before the PR.
How was the solution tested?
New automated tests
i26132.scalaadded