@@ -90,7 +90,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
9090 if (ctx.compilationUnit.containsQuotesOrSplices) super .run
9191
9292 protected def newTransformer (implicit ctx : Context ): Transformer =
93- new Reifier (inQuote = false , null , 0 , new LevelInfo , new mutable.ListBuffer [ Tree ] )
93+ new Reifier (inQuote = false , null , 0 , new LevelInfo , new mutable.ListBuffer , ctx )
9494
9595 private class LevelInfo {
9696 /** A map from locally defined symbols to the staging levels of their definitions */
@@ -120,16 +120,17 @@ class ReifyQuotes extends MacroTransformWithImplicits {
120120 * and `l == -1` is code inside a top level splice (in an inline method).
121121 * @param levels a stacked map from symbols to the levels in which they were defined
122122 * @param embedded a list of embedded quotes (if `inSplice = true`) or splices (if `inQuote = true`
123+ * @param rctx the contex in the destination lifted lambda
123124 */
124125 private class Reifier (inQuote : Boolean , val outer : Reifier , val level : Int , levels : LevelInfo ,
125- val embedded : mutable.ListBuffer [Tree ]) extends ImplicitsTransformer {
126+ val embedded : mutable.ListBuffer [Tree ], val rctx : Context ) extends ImplicitsTransformer {
126127 import levels ._
127128 assert(level >= - 1 )
128129
129130 /** A nested reifier for a quote (if `isQuote = true`) or a splice (if not) */
130- def nested (isQuote : Boolean ): Reifier = {
131+ def nested (isQuote : Boolean )( implicit ctx : Context ) : Reifier = {
131132 val nestedEmbedded = if (level > 1 || (level == 1 && isQuote)) embedded else new mutable.ListBuffer [Tree ]
132- new Reifier (isQuote, this , if (isQuote) level + 1 else level - 1 , levels, nestedEmbedded)
133+ new Reifier (isQuote, this , if (isQuote) level + 1 else level - 1 , levels, nestedEmbedded, ctx )
133134 }
134135
135136 /** We are in a `~(...)` context that is not shadowed by a nested `'(...)` */
@@ -494,7 +495,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
494495 )
495496 }
496497
497- val lambdaOwner = ctx.owner.ownersIterator.find(o => levelOf.getOrElse(o, level) == level).get
498+ val lambdaOwner = if ( level == - 1 ) ctx.owner else outer.rctx.owner
498499 val tpe = MethodType (defn.SeqType .appliedTo(defn.AnyType ) :: Nil , tree.tpe.widen)
499500 val meth = ctx.newSymbol(lambdaOwner, UniqueName .fresh(nme.ANON_FUN ), Synthetic | Method , tpe)
500501 Closure (meth, tss => body(tss.head.head)(ctx.withOwner(meth)).changeOwner(ctx.owner, meth))
0 commit comments