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