Skip to content

Instantly share code, notes, and snippets.

@eed3si9n
Created September 18, 2022 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eed3si9n/6fc1e89f9a730f0e827327af0c268cb1 to your computer and use it in GitHub Desktop.
Save eed3si9n/6fc1e89f9a730f0e827327af0c268cb1 to your computer and use it in GitHub Desktop.
// 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 http://creativecommons.org/publicdomain/zero/1.0/.
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 _ =>
super.transformStatement(tree)(owner)
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
refTransformer.transformTerm(tree)(Symbol.spliceOwner)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment