Skip to content

Commit 90cdb69

Browse files
committed
Make holes more consistent and address review comments
1 parent 07dcca1 commit 90cdb69

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

compiler/src/dotty/tools/dotc/transform/Splicing.scala

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

tests/pos-macros/i16615.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ def bugImpl[T: Type, Q[_]: Type](using Quotes) =
1010
Type.of[p.Reader[T]]
1111
Type.of[Q[p.Reader[T]]]
1212
Type.of[p.Reader[Q[p.Reader[T]]]]
13+
Type.of[List[p.Reader[T]]]
14+
Type.of[p.Reader[List[p.Reader[T]]]]
15+
Type.of[p.Reader[List[T]]]
1316
Type.of[p.Reader[Q[T]]]
1417
Expr(1)
1518
}
16-
}
19+
}

0 commit comments

Comments
 (0)