@@ -31,6 +31,8 @@ import util.{SourceFile, Property}
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
@@ -371,7 +376,7 @@ class TreeUnpickler(reader: TastyReader,
371
376
// Note that the lambda "rt => ..." is not equivalent to a wildcard closure!
372
377
// Eta expansion of the latter puts readType() out of the expression.
373
378
case APPLIEDtype =>
374
- readType().appliedTo(until(end)(readType()))
379
+ postProcessFunction( readType().appliedTo(until(end)(readType() )))
375
380
case TYPEBOUNDS =>
376
381
val lo = readType()
377
382
if nothingButMods(end) then
@@ -484,6 +489,12 @@ class TreeUnpickler(reader: TastyReader,
484
489
def readTermRef ()(using Context ): TermRef =
485
490
readType().asInstanceOf [TermRef ]
486
491
492
+ /** Under -Ycc, map all function types to impure function types,
493
+ * unless the unpickled class was also compiled with -Ycc.
494
+ */
495
+ private def postProcessFunction (tp : Type )(using Context ): Type =
496
+ if wasCaptureChecked then tp else tp.adaptFunctionType
497
+
487
498
// ------ Reading definitions -----------------------------------------------------
488
499
489
500
private def nothingButMods (end : Addr ): Boolean =
@@ -631,6 +642,8 @@ class TreeUnpickler(reader: TastyReader,
631
642
}
632
643
registerSym(start, sym)
633
644
if (isClass) {
645
+ if sym.owner.is(Package ) && annots.exists(_.symbol == defn.CaptureCheckedAnnot ) then
646
+ wasCaptureChecked = true
634
647
sym.completer.withDecls(newScope)
635
648
forkAt(templateStart).indexTemplateParams()(using localContext(sym))
636
649
}
@@ -1339,7 +1352,7 @@ class TreeUnpickler(reader: TastyReader,
1339
1352
val args = until(end)(readTpt())
1340
1353
val tree = untpd.AppliedTypeTree (tycon, args)
1341
1354
val ownType = ctx.typeAssigner.processAppliedType(tree, tycon.tpe.safeAppliedTo(args.tpes))
1342
- tree.withType(ownType)
1355
+ tree.withType(postProcessFunction( ownType) )
1343
1356
case ANNOTATEDtpt =>
1344
1357
Annotated (readTpt(), readTerm())
1345
1358
case LAMBDAtpt =>
0 commit comments