@@ -113,24 +113,39 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
113
113
def transformSym (symd : SymDenotation )(using Context ): SymDenotation =
114
114
if ! pastRecheck && Feature .ccEnabledSomewhere then
115
115
val sym = symd.symbol
116
+ def rootTarget =
117
+ if sym.isAliasType && sym.isStatic then NoSymbol else sym
116
118
def mappedInfo =
117
119
if toBeUpdated.contains(sym) then symd.info
118
- else transformExplicitType(symd.info, rootTarget = sym )
120
+ else transformExplicitType(symd.info, rootTarget)
119
121
// TODO if sym is class && level owner: add a capture root
120
122
if Synthetics .needsTransform(symd) then
121
123
Synthetics .transform(symd, mappedInfo)
122
124
else if isPreCC(sym) then
123
125
symd.copySymDenotation(info = fluidify(sym.info))
124
126
else if symd.owner.isTerm || symd.is(CaptureChecked ) || symd.owner.is(CaptureChecked ) then
125
127
val newFlags = newFlagsFor(symd)
126
- val newInfo = mappedInfo
128
+ var newInfo = mappedInfo
129
+ if sym.is(ModuleVal ) && ! sym.isStatic then
130
+ val selfType1 = transformSelfType(sym.moduleClass)
131
+ if selfType1.exists then
132
+ newInfo = newInfo.capturing(selfType1.captureSet)
133
+ sym.termRef.invalidateCaches()
134
+ if sym.isClass then
135
+ sym.thisType.asInstanceOf [ThisType ].invalidateCaches()
127
136
if newFlags != symd.flags || (newInfo ne sym.info)
128
137
then symd.copySymDenotation(initFlags = newFlags, info = newInfo)
129
138
else symd
130
139
else symd
131
140
else symd
132
141
end transformSym
133
142
143
+ def transformSelfType (sym : Symbol )(using Context ) = (sym.info: @ unchecked) match
144
+ case ClassInfo (_, cls, _, _, selfInfo : Type ) =>
145
+ inContext(ctx.withOwner(cls)):
146
+ transformExplicitType(selfInfo, rootTarget = ctx.owner)
147
+ case _ => NoType
148
+
134
149
/** If `tp` is an unboxed capturing type or a function returning an unboxed capturing type,
135
150
* convert it to be boxed.
136
151
*/
@@ -490,15 +505,12 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
490
505
postProcess(tree)
491
506
end traverse
492
507
493
- extension (sym : Symbol )(using Context ) def unlessStatic =
494
- val owner = sym.levelOwner
495
- if sym.isStaticOwner then NoSymbol else owner
496
-
497
508
def postProcess (tree : Tree )(using Context ): Unit = tree match
498
509
case tree : TypeTree =>
499
510
val lowner =
500
511
transformTT(tree, boxed = false , exact = false ,
501
- rootTarget = ctx.owner.unlessStatic // roots of other types in static locations are not mapped
512
+ rootTarget = if ctx.owner.isStaticOwner then NoSymbol else ctx.owner
513
+ // roots of other types in static locations are not mapped
502
514
)
503
515
case tree : ValOrDefDef =>
504
516
val sym = tree.symbol
@@ -594,22 +606,13 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
594
606
tree.symbol match
595
607
case cls : ClassSymbol =>
596
608
val cinfo @ ClassInfo (prefix, _, ps, decls, selfInfo) = cls.classInfo
597
- val newSelfType =
598
- if (selfInfo eq NoType ) || cls.is(ModuleClass ) && ! cls.isStatic then
599
- // add capture set to self type of nested classes if no self type is given explicitly.
600
- // It's unclear what the right level owner should be. A self type should
601
- // be able to mention class parameters, which are owned by the class; that's
602
- // why the class was picked as level owner. But self types should not be able
603
- // to mention other fields.
604
- CapturingType (cinfo.selfType, CaptureSet .Var (cls))
605
- else selfInfo match
606
- case selfInfo : Type =>
607
- val selfInfo1 = inContext(ctx.withOwner(cls)):
608
- transformExplicitType(selfInfo, rootTarget = ctx.owner)
609
- if selfInfo1 eq selfInfo then NoType else selfInfo1
610
- case _ =>
611
- NoType
612
- if newSelfType.exists then
609
+ if (selfInfo eq NoType ) || cls.is(ModuleClass ) && ! cls.isStatic then
610
+ // add capture set to self type of nested classes if no self type is given explicitly.
611
+ // It's unclear what the right level owner should be. A self type should
612
+ // be able to mention class parameters, which are owned by the class; that's
613
+ // why the class was picked as level owner. But self types should not be able
614
+ // to mention other fields.
615
+ val newSelfType = CapturingType (cinfo.selfType, CaptureSet .Var (cls))
613
616
ccSetup.println(i " mapped self type for $cls: $newSelfType, was $selfInfo" )
614
617
val ps1 = ps.mapConserve(transformExplicitType(_, rootTarget = ctx.owner))
615
618
val newInfo = ClassInfo (prefix, cls, ps1, decls, newSelfType)
@@ -621,11 +624,6 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
621
624
updateInfo(modul, CapturingType (modul.info, newSelfType.captureSet))
622
625
modul.termRef.invalidateCaches()
623
626
case _ =>
624
- val info = tree.symbol.info
625
- val newInfo = transformExplicitType(info, rootTarget = ctx.owner.unlessStatic)
626
- updateInfo(tree.symbol, newInfo)
627
- if newInfo ne info then
628
- ccSetup.println(i " update info of ${tree.symbol} from $info to $newInfo" )
629
627
case _ =>
630
628
end postProcess
631
629
end setupTraverser
0 commit comments