Skip to content

Instantly share code, notes, and snippets.

Created September 18, 2022 19:33
What would you like to do?
// To the extent possible under law, the author(s) have dedicated all copyright and related
// and neighboring rights to this snippet to the public domain worldwide.
// This snippet is distributed without any warranty.
// See
import scala.quoted.*
import scala.collection.mutable
// import qctx.reflect.*
def inlineExtensionProxy(tree: Term): Term =
val rhss: mutable.Map[String, Term] = mutable.Map.empty
object refTransformer extends TreeMap:
override def transformStatement(tree: Statement)(owner: Symbol): Statement =
tree match
case ValDef(name, tpe, Some(body)) if name.contains("$proxy") =>
rhss(name) = body
ValDef.copy(tree)(name, tpe, None)
case _ =>
override def transformTerm(tree: Term)(owner: Symbol): Term =
tree match
case Ident(name) if rhss.contains(name) => rhss(name)
case _ => super.transformTerm(tree)(owner)
end refTransformer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment