From 937e27ace7ad9ab071082f3dcdaa14f07437754a Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sat, 4 Nov 2017 18:12:21 -0700 Subject: Swap over to `typingTransformer` --- core/src/main/scala/forge/Target.scala | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'core/src/main') diff --git a/core/src/main/scala/forge/Target.scala b/core/src/main/scala/forge/Target.scala index 681d9d2f..635acb8e 100644 --- a/core/src/main/scala/forge/Target.scala +++ b/core/src/main/scala/forge/Target.scala @@ -53,22 +53,21 @@ object Target{ import c.universe._ val bound = collection.mutable.Buffer.empty[(c.Tree, Symbol)] val OptionGet = c.universe.typeOf[Target[_]].member(TermName("apply")) - object transformer extends c.universe.Transformer { - // Derived from @olafurpg's - // https://gist.github.com/olafurpg/596d62f87bf3360a29488b725fbc7608 - override def transform(tree: c.Tree): c.Tree = tree match { - case t @ q"$fun.apply()" if t.symbol == OptionGet => - val tempName = c.freshName(TermName("tmp")) - val tempSym = c.internal.newTermSymbol(c.internal.enclosingOwner, tempName) - c.internal.setInfo(tempSym, t.tpe) - val tempIdent = Ident(tempSym) - c.internal.setType(tempIdent, t.tpe) - bound.append((fun, tempSym)) - tempIdent - case _ => super.transform(tree) - } + // Derived from @olafurpg's + // https://gist.github.com/olafurpg/596d62f87bf3360a29488b725fbc7608 + + val transformed = c.internal.typingTransform(t.tree) { + case (t @ q"$fun.apply()", api) if t.symbol == OptionGet => + val tempName = c.freshName(TermName("tmp")) + val tempSym = c.internal.newTermSymbol(api.currentOwner, tempName) + c.internal.setInfo(tempSym, t.tpe) + val tempIdent = Ident(tempSym) + c.internal.setType(tempIdent, t.tpe) + bound.append((fun, tempSym)) + tempIdent + case (t, api) => api.default(t) } - val transformed = transformer.transform(t.tree) + val (exprs, symbols) = bound.unzip val bindings = symbols.map(c.internal.valDef(_)) -- cgit v1.2.3