Skip to content

Instantly share code, notes, and snippets.

@erikerlandson
Created April 26, 2021 22:12
Show Gist options
  • Save erikerlandson/f28717dcc5909768000210bb133ecfef to your computer and use it in GitHub Desktop.
Save erikerlandson/f28717dcc5909768000210bb133ecfef to your computer and use it in GitHub Desktop.
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