@@ -123,13 +123,13 @@ class ReifyQuotes extends MacroTransformWithImplicits {
123
123
* @param rctx the contex in the destination lifted lambda
124
124
*/
125
125
private class Reifier (inQuote : Boolean , val outer : Reifier , val level : Int , levels : LevelInfo ,
126
- val embedded : mutable.ListBuffer [Tree ], val rctx : Context ) extends ImplicitsTransformer {
126
+ val embedded : mutable.ListBuffer [( Symbol , Tree ) ], val rctx : Context ) extends ImplicitsTransformer {
127
127
import levels ._
128
128
assert(level >= - 1 )
129
129
130
130
/** A nested reifier for a quote (if `isQuote = true`) or a splice (if not) */
131
131
def nested (isQuote : Boolean )(implicit ctx : Context ): Reifier = {
132
- val nestedEmbedded = if (level > 1 || (level == 1 && isQuote)) embedded else new mutable.ListBuffer [Tree ]
132
+ val nestedEmbedded = if (level > 1 || (level == 1 && isQuote)) embedded else new mutable.ListBuffer [( Symbol , Tree ) ]
133
133
new Reifier (isQuote, this , if (isQuote) level + 1 else level - 1 , levels, nestedEmbedded, ctx)
134
134
}
135
135
@@ -423,7 +423,12 @@ class ReifyQuotes extends MacroTransformWithImplicits {
423
423
}
424
424
else if (level == 1 ) {
425
425
val (body1, quotes) = nested(isQuote = false ).split(splice.qualifier)
426
- makeHole(body1, quotes, splice.tpe).withPos(splice.pos)
426
+ // TODO improve code
427
+ val tpe = outer.embedded.toList.find(_._1 == splice.qualifier.symbol) match {
428
+ case Some ((_, tree)) => tree.tpe.widen
429
+ case _ => splice.tpe
430
+ }
431
+ makeHole(body1, quotes, tpe).withPos(splice.pos)
427
432
}
428
433
else if (enclosingInlineds.nonEmpty) { // level 0 in an inlined call
429
434
val spliceCtx = ctx.outer // drop the last `inlineContext`
@@ -478,14 +483,18 @@ class ReifyQuotes extends MacroTransformWithImplicits {
478
483
(captured : mutable.Map [Symbol , Tree ]) => {
479
484
(tree : Tree ) => {
480
485
def newCapture = {
481
- val tpw = tree.tpe.widen
486
+ val tpw = tree.tpe.widen match {
487
+ case tpw : MethodicType => tpw.toFunctionType()
488
+ case tpw => tpw
489
+ }
490
+ assert(tpw.isInstanceOf [ValueType ])
482
491
val argTpe =
483
492
if (tree.isType) defn.QuotedTypeType .appliedTo(tpw)
484
493
else defn.QuotedExprType .appliedTo(tpw)
485
494
val selectArg = arg.select(nme.apply).appliedTo(Literal (Constant (i))).asInstance(argTpe)
486
495
val capturedArg = SyntheticValDef (UniqueName .fresh(tree.symbol.name.toTermName).toTermName, selectArg)
487
496
i += 1
488
- embedded += tree
497
+ embedded += Tuple2 (capturedArg.symbol, tree)
489
498
captured.put(tree.symbol, capturedArg)
490
499
capturedArg
491
500
}
@@ -522,15 +531,15 @@ class ReifyQuotes extends MacroTransformWithImplicits {
522
531
*/
523
532
private def split (tree : Tree )(implicit ctx : Context ): (Tree , List [Tree ]) = {
524
533
val tree1 = if (inQuote) addTags(transform(tree)) else makeLambda(tree)
525
- (tree1, embedded.toList)
534
+ (tree1, embedded.toList.map(_._2) )
526
535
}
527
536
528
537
/** Register `body` as an `embedded` quote or splice
529
538
* and return a hole with `splices` as arguments and the given type `tpe`.
530
539
*/
531
540
private def makeHole (body : Tree , splices : List [Tree ], tpe : Type )(implicit ctx : Context ): Hole = {
532
541
val idx = embedded.length
533
- embedded += body
542
+ embedded += Tuple2 ( NoSymbol , body)
534
543
Hole (idx, splices).withType(tpe).asInstanceOf [Hole ]
535
544
}
536
545
0 commit comments