Skip to content

Support derivation for self-based type classes - #26719

Open
halotukozak wants to merge 4 commits into
scala:mainfrom
halotukozak:support-self-type-class-derivation
Open

Support derivation for self-based type classes#26719
halotukozak wants to merge 4 commits into
scala:mainfrom
halotukozak:support-self-type-class-derivation

Conversation

@halotukozak

Copy link
Copy Markdown
Contributor

Self-based type classes, e.g.

trait TC:
  type Self
  def apply(): Self

given Int is TC = () => 42

doesn't support derivation

object TC:
  def derived[X]: X is TC = ???

  case class C() derives TC

error: type TC in derives clause of C has no type parameters

It can be achieved via

given C is TC = TC.derived

But imo, to make modularity changes comprehensive, derivation should be supported (similarly to the context bounds).

It works when modularity flag imported.

Have you relied on LLM-based tools in this contribution?

Yes, and I've verified the output.

How was the solution tested?

New automated tests

@halotukozak
halotukozak marked this pull request as ready for review August 5, 2026 18:01
@halotukozak

Copy link
Copy Markdown
Contributor Author

scalafmt failure seems unrelated to my changes (?)

@bishabosha
bishabosha requested review from bishabosha and a lite review from Copilot and removed request for Copilot August 11, 2026 20:19
@bishabosha bishabosha self-assigned this Aug 11, 2026
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.

2 participants