@@ -244,12 +244,14 @@ class Splicing extends MacroTransform:
244244 cpy.Apply (tree)(cpy.Select (sel)(cpy.Apply (app)(fn, newArgs), nme.apply), quotesArgs)
245245 case Apply (TypeApply (typeof, List (tpt)), List (quotes))
246246 if tree.symbol == defn.QuotedTypeModule_of && containsCapturedType(tpt.tpe) =>
247- tpt match
248- case block : Block =>
249- val newBlock = capturedBlockPartTypes(block)
250- Apply (TypeApply (typeof, List (newBlock)), List (quotes)).withSpan(tree.span)
247+ val newContent = capturedPartTypes(tpt)
248+ newContent match
249+ case block : Block =>
250+ inContext(ctx.withSource(tree.source)) {
251+ Apply (TypeApply (typeof, List (newContent)), List (quotes)).withSpan(tree.span)
252+ }
251253 case _ =>
252- ref(capturedType(tpt ))(using ctx.withSource(tree.source)).withSpan(tree.span)
254+ ref(capturedType(newContent ))(using ctx.withSource(tree.source)).withSpan(tree.span)
253255 case CapturedApplication (fn, argss) =>
254256 transformCapturedApplication(tree, fn, argss)
255257 case _ =>
@@ -354,9 +356,9 @@ class Splicing extends MacroTransform:
354356 .getOrElseUpdate(tree.symbol, (TypeTree (tree.tpe), newQuotedTypeClassBinding(tpe)))._2
355357 bindingSym
356358
357- private def capturedBlockPartTypes ( block : Block )(using Context ): Tree =
359+ private def capturedPartTypes ( tpt : Tree )(using Context ): Tree =
358360 val old = healedTypes
359- healedTypes = PCPCheckAndHeal .QuoteTypeTags (block .span)
361+ healedTypes = PCPCheckAndHeal .QuoteTypeTags (tpt .span)
360362 val capturePartTypes = new TypeMap {
361363 def apply (tp : Type ) = tp match {
362364 case typeRef @ TypeRef (prefix, _) if isCaptured(prefix.typeSymbol) || isCaptured(prefix.termSymbol) =>
@@ -368,10 +370,17 @@ class Splicing extends MacroTransform:
368370 mapOver(tp)
369371 }
370372 }
371- val captured = capturePartTypes(block .tpe.widenTermRefExpr)
373+ val captured = capturePartTypes(tpt .tpe.widenTermRefExpr)
372374 val newHealedTypes = healedTypes.nn.getTypeTags
373375 healedTypes = old
374- Block (newHealedTypes ::: block.stats, TypeTree (captured))
376+ tpt match
377+ case block : Block =>
378+ cpy.Block (block)(newHealedTypes ::: block.stats, TypeTree (captured))
379+ case _ =>
380+ if newHealedTypes.nonEmpty then
381+ cpy.Block (tpt)(newHealedTypes, TypeTree (captured))
382+ else
383+ tpt
375384
376385 private def getTagRefFor (tree : Tree )(using Context ): Tree =
377386 val capturedTypeSym = capturedType(tree)
0 commit comments