Skip to content

fix: #26132 unsound Nothing cast in Mirror.fromProduct for F-bounded case class#26268

Open
halotukozak wants to merge 2 commits into
scala:mainfrom
halotukozak:fix/i26132-fromproduct-nothing-cast
Open

fix: #26132 unsound Nothing cast in Mirror.fromProduct for F-bounded case class#26268
halotukozak wants to merge 2 commits into
scala:mainfrom
halotukozak:fix/i26132-fromproduct-nothing-cast

Conversation

@halotukozak

Copy link
Copy Markdown
Contributor

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.scala added

halotukozak and others added 2 commits June 8, 2026 16:46
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Mirror.Product.fromProduct on F-bounded case class casts element to Nothing

1 participant