@@ -244,12 +244,14 @@ class Splicing extends MacroTransform:
244
244
cpy.Apply (tree)(cpy.Select (sel)(cpy.Apply (app)(fn, newArgs), nme.apply), quotesArgs)
245
245
case Apply (TypeApply (typeof, List (tpt)), List (quotes))
246
246
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
+ }
251
253
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)
253
255
case CapturedApplication (fn, argss) =>
254
256
transformCapturedApplication(tree, fn, argss)
255
257
case _ =>
@@ -354,9 +356,9 @@ class Splicing extends MacroTransform:
354
356
.getOrElseUpdate(tree.symbol, (TypeTree (tree.tpe), newQuotedTypeClassBinding(tpe)))._2
355
357
bindingSym
356
358
357
- private def capturedBlockPartTypes ( block : Block )(using Context ): Tree =
359
+ private def capturedPartTypes ( tpt : Tree )(using Context ): Tree =
358
360
val old = healedTypes
359
- healedTypes = PCPCheckAndHeal .QuoteTypeTags (block .span)
361
+ healedTypes = PCPCheckAndHeal .QuoteTypeTags (tpt .span)
360
362
val capturePartTypes = new TypeMap {
361
363
def apply (tp : Type ) = tp match {
362
364
case typeRef @ TypeRef (prefix, _) if isCaptured(prefix.typeSymbol) || isCaptured(prefix.termSymbol) =>
@@ -368,10 +370,17 @@ class Splicing extends MacroTransform:
368
370
mapOver(tp)
369
371
}
370
372
}
371
- val captured = capturePartTypes(block .tpe.widenTermRefExpr)
373
+ val captured = capturePartTypes(tpt .tpe.widenTermRefExpr)
372
374
val newHealedTypes = healedTypes.nn.getTypeTags
373
375
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
375
384
376
385
private def getTagRefFor (tree : Tree )(using Context ): Tree =
377
386
val capturedTypeSym = capturedType(tree)
0 commit comments