@@ -90,7 +90,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
90
90
if (ctx.compilationUnit.containsQuotesOrSplices) super .run
91
91
92
92
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 )
94
94
95
95
private class LevelInfo {
96
96
/** A map from locally defined symbols to the staging levels of their definitions */
@@ -120,16 +120,17 @@ class ReifyQuotes extends MacroTransformWithImplicits {
120
120
* and `l == -1` is code inside a top level splice (in an inline method).
121
121
* @param levels a stacked map from symbols to the levels in which they were defined
122
122
* @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
123
124
*/
124
125
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 {
126
127
import levels ._
127
128
assert(level >= - 1 )
128
129
129
130
/** 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 = {
131
132
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 )
133
134
}
134
135
135
136
/** We are in a `~(...)` context that is not shadowed by a nested `'(...)` */
@@ -493,8 +494,12 @@ class ReifyQuotes extends MacroTransformWithImplicits {
493
494
}
494
495
)
495
496
}
497
+ /* Lambdas are generated outside the quote that is beeing reified (i.e. in outer.rctx.owner).
498
+ * In case the case that level == -1 the code is not in a quote, it is in an inline method,
499
+ * hence we should take that as owner directly.
500
+ */
501
+ val lambdaOwner = if (level == - 1 ) ctx.owner else outer.rctx.owner
496
502
497
- val lambdaOwner = ctx.owner.ownersIterator.find(o => levelOf.getOrElse(o, level) == level).get
498
503
val tpe = MethodType (defn.SeqType .appliedTo(defn.AnyType ) :: Nil , tree.tpe.widen)
499
504
val meth = ctx.newSymbol(lambdaOwner, UniqueName .fresh(nme.ANON_FUN ), Synthetic | Method , tpe)
500
505
Closure (meth, tss => body(tss.head.head)(ctx.withOwner(meth)).changeOwner(ctx.owner, meth))
0 commit comments