@@ -29,6 +29,8 @@ import util.SourceFile
29
29
import ast .{Trees , tpd , untpd }
30
30
import Trees ._
31
31
import Decorators ._
32
+ import transform .SymUtils ._
33
+ import cc .adaptFunctionType
32
34
33
35
import dotty .tools .tasty .{TastyBuffer , TastyReader }
34
36
import TastyBuffer ._
@@ -83,6 +85,9 @@ class TreeUnpickler(reader: TastyReader,
83
85
/** The root owner tree. See `OwnerTree` class definition. Set by `enterTopLevel`. */
84
86
private var ownerTree : OwnerTree = _
85
87
88
+ /** Was unpickled class compiled with -Ycc? */
89
+ private var wasCaptureChecked : Boolean = false
90
+
86
91
private def registerSym (addr : Addr , sym : Symbol ) =
87
92
symAtAddr(addr) = sym
88
93
@@ -353,7 +358,7 @@ class TreeUnpickler(reader: TastyReader,
353
358
// Note that the lambda "rt => ..." is not equivalent to a wildcard closure!
354
359
// Eta expansion of the latter puts readType() out of the expression.
355
360
case APPLIEDtype =>
356
- readType().appliedTo(until(end)(readType()))
361
+ postProcessFunction( readType().appliedTo(until(end)(readType() )))
357
362
case TYPEBOUNDS =>
358
363
val lo = readType()
359
364
if nothingButMods(end) then
@@ -466,6 +471,12 @@ class TreeUnpickler(reader: TastyReader,
466
471
def readTermRef ()(using Context ): TermRef =
467
472
readType().asInstanceOf [TermRef ]
468
473
474
+ /** Under -Ycc, map all function types to impure function types,
475
+ * unless the unpickled class was also compiled with -Ycc.
476
+ */
477
+ private def postProcessFunction (tp : Type )(using Context ): Type =
478
+ if wasCaptureChecked then tp else tp.adaptFunctionType
479
+
469
480
// ------ Reading definitions -----------------------------------------------------
470
481
471
482
private def nothingButMods (end : Addr ): Boolean =
@@ -601,6 +612,8 @@ class TreeUnpickler(reader: TastyReader,
601
612
}
602
613
registerSym(start, sym)
603
614
if (isClass) {
615
+ if sym.owner.is(Package ) && annots.exists(_.symbol == defn.CaptureCheckedAnnot ) then
616
+ wasCaptureChecked = true
604
617
sym.completer.withDecls(newScope)
605
618
forkAt(templateStart).indexTemplateParams()(using localContext(sym))
606
619
}
@@ -1261,7 +1274,7 @@ class TreeUnpickler(reader: TastyReader,
1261
1274
val args = until(end)(readTpt())
1262
1275
val tree = untpd.AppliedTypeTree (tycon, args)
1263
1276
val ownType = ctx.typeAssigner.processAppliedType(tree, tycon.tpe.safeAppliedTo(args.tpes))
1264
- tree.withType(ownType)
1277
+ tree.withType(postProcessFunction( ownType) )
1265
1278
case ANNOTATEDtpt =>
1266
1279
Annotated (readTpt(), readTerm())
1267
1280
case LAMBDAtpt =>
0 commit comments