Last active
August 5, 2023 08:55
-
-
Save yilinwei/e06de1a38b03a3ba8e2e955ea59578b7 to your computer and use it in GitHub Desktop.
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
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) } | |
} |
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
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