Skip to content

Commit ff519dc

Browse files
committed
Keep hole types in TASTy
1 parent 6cd3a9d commit ff519dc

File tree

4 files changed

+21
-3
lines changed

4 files changed

+21
-3
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

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

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

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

12911291
def readHole(end: Addr, isType: Boolean)(implicit ctx: Context): Tree = {
12921292
val idx = readNat()
1293+
val tpe = readType()
12931294
val args = until(end)(readTerm())
12941295
val splice = splices(idx)
12951296
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 =

tasty/src/dotty/tools/tasty/TastyFormat.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ Standard Section: "Comments" Comment*
254254
object TastyFormat {
255255

256256
final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
257-
val MajorVersion: Int = 20
257+
val MajorVersion: Int = 21
258258
val MinorVersion: Int = 0
259259

260260
/** Tags used to serialize names, should update [[nameTagToString]] if a new constant is added */

0 commit comments

Comments
 (0)