Created
April 26, 2021 22:12
-
-
Save erikerlandson/f28717dcc5909768000210bb133ecfef to your computer and use it in GitHub Desktop.
This file contains 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
object code: | |
import scala.quoted.* | |
trait Context[T]: | |
val t: Int | |
given Context[Int] with | |
val t = 7 | |
transparent inline def aMacro[T]: Int = ${ aMacroImpl[T] } | |
def aMacroImpl[T](using Type[T], Quotes): Expr[Int] = | |
import quotes.reflect.* | |
val tterm = Expr.summon[Context[T]].get.asTerm | |
val t = Select.unique(tterm, "t").asExprOf[Int].value | |
// would like 't' to be Some(integer) but is None | |
println(s"t= $t") | |
Expr(t.getOrElse(0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment