Skip to content

Commit d84d597

Browse files
committed
Keep hole types in TASTy
1 parent 3eafc18 commit d84d597

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ object TreePickler {
2626
override def isTerm: Boolean = isTermHole
2727
override def isType: Boolean = !isTermHole
2828
override def fallbackToText(printer: Printer): Text =
29-
s"[[$idx|" ~~ printer.toTextGlobal(args, ", ") ~~ "]]"
29+
s"[[$idx|" ~~ printer.toTextGlobal(tpe) ~~ "|" ~~ printer.toTextGlobal(args, ", ") ~~ "]]"
3030
}
3131
}
3232

@@ -603,6 +603,7 @@ class TreePickler(pickler: TastyPickler) {
603603
writeByte(HOLE)
604604
withLength {
605605
writeNat(idx)
606+
pickleType(tree.tpe, richTypes = true)
606607
args.foreach(pickleTree)
607608
}
608609
}

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,6 +1301,7 @@ class TreeUnpickler(reader: TastyReader,
13011301

13021302
def readHole(end: Addr, isType: Boolean)(implicit ctx: Context): Tree = {
13031303
val idx = readNat()
1304+
val tpe = readType()
13041305
val args = until(end)(readTerm())
13051306
val splice = splices(idx)
13061307
def wrap(arg: Tree) =

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,23 @@ class ReifyQuotes extends MacroTransform {
331331
*/
332332
private def makeHole(isTermHole: Boolean, body: Tree, splices: List[Tree], tpe: Type)(implicit ctx: Context): Hole = {
333333
val idx = embedded.addTree(body, NoSymbol)
334-
Hole(isTermHole, idx, splices).withType(tpe).asInstanceOf[Hole]
334+
val holeType = getHoleType(tpe)
335+
Hole(isTermHole, idx, splices).withType(holeType).asInstanceOf[Hole]
336+
}
337+
338+
private def getHoleType(using ctx: Context) = new TypeMap() {
339+
override def apply(tp: Type): Type = tp match
340+
case tp: TypeRef if tp.typeSymbol.isSplice =>
341+
apply(tp.dealias)
342+
case tp @ TypeRef(pre, _) if pre == NoPrefix || pre.termSymbol.isLocal =>
343+
val hiBound = tp.typeSymbol.info match
344+
case info @ ClassInfo(_, _, classParents, _, _) => classParents.reduce(_ & _)
345+
case info => info.hiBound
346+
apply(hiBound)
347+
case tp @ TermRef(NoPrefix, _) =>
348+
apply(tp.widenTermRefExpr)
349+
case tp =>
350+
mapOver(tp)
335351
}
336352

337353
override def transform(tree: Tree)(implicit ctx: Context): Tree =

0 commit comments

Comments
 (0)