WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Discussion options

You must be logged in to vote

to do this, you can get the prefix of the type of the companion object, then use select on the prefix with the case class symbol, you need to explicitly refine the type of the anonymous class also to extract a usable CC type from the returned value (I use aux pattern also, but unnecessary):

import scala.quoted.*

trait CaseClass[Companion <: AnyRef]:
  type CC <: Product

object CaseClass:

  type Aux[Companion <: AnyRef, Case <: Product] = CaseClass[Companion] { type CC = Case }

  transparent inline given [Comp <: AnyRef]: CaseClass[Comp] = ${
    macroImpl[Comp]
  }
  def macroImpl[Comp <: AnyRef](using
      Quotes,
      Type[Comp]
  ): Expr[CaseClass[Comp]] =
    import quotes.reflect.

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by soronpo
Comment options

soronpo
Dec 21, 2021
Collaborator Author

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants