@@ -170,7 +170,7 @@ class ReifyQuotes extends MacroTransform {
170170 */
171171 override protected def transformQuotation (body : Tree , quote : Tree )(implicit ctx : Context ): Tree = {
172172 val isType = quote.symbol eq defn.InternalQuoted_typeQuote
173- assert(! body.symbol.isSplice)
173+ assert(! ( body.symbol.isSplice && (body. isInstanceOf [ GenericApply [_]] || body. isInstanceOf [ Select ])) )
174174 if (level > 0 ) {
175175 val body1 = nested(isQuote = true ).transform(body)(quoteContext)
176176 super .transformQuotation(body1, quote)
@@ -222,21 +222,24 @@ class ReifyQuotes extends MacroTransform {
222222 * and make a hole from these parts. Otherwise issue an error, unless we
223223 * are in the body of an inline method.
224224 */
225- protected def transformSplice (splice : Select )(implicit ctx : Context ): Tree = {
225+ protected def transformSplice (body : Tree , splice : Tree )(implicit ctx : Context ): Tree = {
226226 if (level > 1 ) {
227- val body1 = nested(isQuote = false ).transform(splice.qualifier)(spliceContext)
228- body1.select(splice.name)
227+ val body1 = nested(isQuote = false ).transform(body)(spliceContext)
228+ splice match {
229+ case splice : Apply => cpy.Apply (splice)(splice.fun, body1 :: Nil )
230+ case splice : Select => cpy.Select (splice)(body1, splice.name)
231+ }
229232 }
230233 else {
231234 assert(level == 1 , " unexpected top splice outside quote" )
232- val (body1, quotes) = nested(isQuote = false ).splitSplice(splice.qualifier )(spliceContext)
233- val tpe = outer.embedded.getHoleType(splice)
235+ val (body1, quotes) = nested(isQuote = false ).splitSplice(body )(spliceContext)
236+ val tpe = outer.embedded.getHoleType(body, splice)
234237 val hole = makeHole(body1, quotes, tpe).withSpan(splice.span)
235238 // We do not place add the inline marker for trees that where lifted as they come from the same file as their
236239 // enclosing quote. Any intemediate splice will add it's own Inlined node and cancel it before splicig the lifted tree.
237240 // Note that lifted trees are not necessarily expressions and that Inlined nodes are expected to be expressions.
238241 // For example we can have a lifted tree containing the LHS of an assignment (see tests/run-with-compiler/quote-var.scala).
239- if (splice.isType || outer.embedded.isLiftedSymbol(splice.qualifier .symbol)) hole
242+ if (splice.isType || outer.embedded.isLiftedSymbol(body .symbol)) hole
240243 else Inlined (EmptyTree , Nil , hole).withSpan(splice.span)
241244 }
242245 }
@@ -346,14 +349,13 @@ class ReifyQuotes extends MacroTransform {
346349 override def transform (tree : Tree )(implicit ctx : Context ): Tree =
347350 reporting.trace(i " Reifier.transform $tree at $level" , show = true ) {
348351 tree match {
349- case TypeApply (Select (spliceTree @ Spliced (_), _), tp) if tree.symbol.isTypeCast =>
350- // Splice term which should be in the form `${x}.asInstanceOf[T]` where T is an artifact of
351- // typer to allow pickling/unpickling phase consistent types
352- transformSplice(spliceTree)
353-
354352 case tree : RefTree if isCaptured(tree.symbol, level) =>
355- val t = capturers(tree.symbol).apply(tree)
356- transformSplice(t.select(if (tree.isTerm) nme.splice else tpnme.splice))
353+ val body = capturers(tree.symbol).apply(tree)
354+ val splice : Tree =
355+ if (tree.isType) body.select(tpnme.splice)
356+ else ref(defn.InternalQuoted_exprSplice ).appliedToType(tree.tpe).appliedTo(body)
357+
358+ transformSplice(body, splice)
357359
358360 case tree : DefDef if tree.symbol.is(Macro ) && level == 0 =>
359361 // Shrink size of the tree. The methods have already been inlined.
@@ -396,11 +398,11 @@ object ReifyQuotes {
396398 }
397399
398400 /** Type used for the hole that will replace this splice */
399- def getHoleType (splice : tpd.Select )(implicit ctx : Context ): Type = {
401+ def getHoleType (body : tpd. Tree , splice : tpd.Tree )(implicit ctx : Context ): Type = {
400402 // For most expressions the splice.tpe but there are some types that are lost by lifting
401403 // that can be recoverd from the original tree. Currently the cases are:
402404 // * Method types: the splice represents a method reference
403- map.get(splice.qualifier .symbol).map(_.tpe.widen).getOrElse(splice.tpe)
405+ map.get(body .symbol).map(_.tpe.widen).getOrElse(splice.tpe)
404406 }
405407
406408 def isLiftedSymbol (sym : Symbol )(implicit ctx : Context ): Boolean = map.contains(sym)
0 commit comments