Skip to content

Instantly share code, notes, and snippets.

@yilinwei
Last active August 5, 2023 08:55
Show Gist options
  • Save yilinwei/e06de1a38b03a3ba8e2e955ea59578b7 to your computer and use it in GitHub Desktop.
Save yilinwei/e06de1a38b03a3ba8e2e955ea59578b7 to your computer and use it in GitHub Desktop.
import scala.quoted.*
trait Bar {
type X
}
object Foo {
def makeImpl[A : Type](a: Expr[A])(using Quotes): Expr[Any] = {
import quotes.reflect.*
val tree = TypeSelect(a.asTerm, "A").tpe.asType match {
case '[t] => '{
new Bar {
type X = t
}
}
}
println(tree.show)
tree
}
inline transparent def make[A](a: A): Any = ${ makeImpl[A]('a) }
}
trait Baz {
type A
}
def smth(baz: Baz): Bar = {
Foo.make(baz)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment