@@ -187,13 +187,10 @@ class ReifyQuotes extends MacroTransform {
187187 * and make a hole from these parts. Otherwise issue an error, unless we
188188 * are in the body of an inline method.
189189 */
190- protected def transformSplice (body : Tree , splice : Tree )(using Context ): Tree =
190+ protected def transformSplice (body : Tree , splice : Apply )(using Context ): Tree =
191191 if (level > 1 ) {
192192 val body1 = nested(isQuote = false ).transform(body)(using spliceContext)
193- splice match {
194- case splice : Apply => cpy.Apply (splice)(splice.fun, body1 :: Nil )
195- case splice : Select => cpy.Select (splice)(body1, splice.name)
196- }
193+ cpy.Apply (splice)(splice.fun, body1 :: Nil )
197194 }
198195 else {
199196 assert(level == 1 , " unexpected top splice outside quote" )
@@ -204,10 +201,26 @@ class ReifyQuotes extends MacroTransform {
204201 // enclosing quote. Any intemediate splice will add it's own Inlined node and cancel it before splicig the lifted tree.
205202 // Note that lifted trees are not necessarily expressions and that Inlined nodes are expected to be expressions.
206203 // For example we can have a lifted tree containing the LHS of an assignment (see tests/run-with-compiler/quote-var.scala).
207- if (splice.isType || outer.embedded.isLiftedSymbol(body.symbol)) hole
204+ if (outer.embedded.isLiftedSymbol(body.symbol)) hole
208205 else Inlined (EmptyTree , Nil , hole).withSpan(splice.span)
209206 }
210207
208+ /** If inside a quote, split the body of the splice into a core and a list of embedded quotes
209+ * and make a hole from these parts. Otherwise issue an error, unless we
210+ * are in the body of an inline method.
211+ */
212+ protected def transformSpliceType (body : Tree , splice : Select )(using Context ): Tree =
213+ if (level > 1 ) {
214+ val body1 = nested(isQuote = false ).transform(body)(using spliceContext)
215+ cpy.Select (splice)(body1, splice.name)
216+ }
217+ else {
218+ assert(level == 1 , " unexpected top splice outside quote" )
219+ val (body1, quotes) = nested(isQuote = false ).splitSplice(body)(using spliceContext)
220+ val tpe = outer.embedded.getHoleType(body, splice)
221+ makeHole(splice.isTerm, body1, quotes, tpe).withSpan(splice.span)
222+ }
223+
211224 /** Transforms the contents of a nested splice
212225 * Assuming
213226 * '{
@@ -356,11 +369,11 @@ class ReifyQuotes extends MacroTransform {
356369 capturers(body.symbol)(body)
357370 case tree : RefTree if isCaptured(tree.symbol, level) =>
358371 val body = capturers(tree.symbol).apply(tree)
359- val splice : Tree =
360- if (tree.isType) body.select(tpnme.splice )
361- else ref(defn. InternalQuoted_exprSplice ).appliedToType(tree.tpe).appliedTo(body)
362-
363- transformSplice(body, splice)
372+ if (tree.isType)
373+ transformSpliceType(body, body.select(tpnme.spliceType) )
374+ else
375+ val splice = ref(defn. InternalQuoted_exprSplice ).appliedToType(tree.tpe).appliedTo(body)
376+ transformSplice(body, splice)
364377
365378 case tree : DefDef if tree.symbol.is(Macro ) && level == 0 =>
366379 // Shrink size of the tree. The methods have already been inlined.
0 commit comments