Skip to content

Commit f66e902

Browse files
committed
Pickling and unpickling of capturing types
1 parent bbe65e2 commit f66e902

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,13 @@ class TreePickler(pickler: TastyPickler) {
288288
pickleType(tpe.scrutinee)
289289
tpe.cases.foreach(pickleType(_))
290290
}
291+
case tp: CapturingType =>
292+
writeByte(APPLIEDtype)
293+
withLength {
294+
pickleType(defn.Predef_retainsType.typeRef)
295+
pickleType(tp.parent)
296+
pickleType(tp.ref)
297+
}
291298
case tpe: PolyType if richTypes =>
292299
pickleMethodic(POLYtype, tpe, EmptyFlags)
293300
case tpe: MethodType if richTypes =>

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

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,13 @@ class TreeUnpickler(reader: TastyReader,
357357
// Note that the lambda "rt => ..." is not equivalent to a wildcard closure!
358358
// Eta expansion of the latter puts readType() out of the expression.
359359
case APPLIEDtype =>
360-
readType().appliedTo(until(end)(readType()))
360+
val tycon = readType()
361+
val args = until(end)(readType())
362+
tycon match
363+
case tycon: TypeRef if tycon.symbol == defn.Predef_retainsType =>
364+
CapturingType.checked(args(0), args(1))
365+
case _ =>
366+
tycon.appliedTo(args)
361367
case TYPEBOUNDS =>
362368
val lo = readType()
363369
if nothingButMods(end) then
@@ -821,7 +827,7 @@ class TreeUnpickler(reader: TastyReader,
821827
def TypeDef(rhs: Tree) =
822828
ta.assignType(untpd.TypeDef(sym.name.asTypeName, rhs), sym)
823829

824-
def ta = ctx.typeAssigner
830+
def ta = ctx.typeAssigner
825831

826832
val name = readName()
827833
pickling.println(s"reading def of $name at $start")
@@ -1255,11 +1261,9 @@ class TreeUnpickler(reader: TastyReader,
12551261
// types. This came up in #137 of collection strawman.
12561262
val tycon = readTpt()
12571263
val args = until(end)(readTpt())
1258-
val ownType =
1259-
if (tycon.symbol == defn.andType) AndType(args(0).tpe, args(1).tpe)
1260-
else if (tycon.symbol == defn.orType) OrType(args(0).tpe, args(1).tpe, soft = false)
1261-
else tycon.tpe.safeAppliedTo(args.tpes)
1262-
untpd.AppliedTypeTree(tycon, args).withType(ownType)
1264+
val tree = untpd.AppliedTypeTree(tycon, args)
1265+
val ownType = ctx.typeAssigner.processAppliedType(tree, tycon.tpe.safeAppliedTo(args.tpes))
1266+
tree.withType(ownType)
12631267
case ANNOTATEDtpt =>
12641268
Annotated(readTpt(), readTerm())
12651269
case LAMBDAtpt =>

0 commit comments

Comments
 (0)