Created
September 18, 2022 19:33
-
-
Save eed3si9n/6fc1e89f9a730f0e827327af0c268cb1 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
// 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