@@ -336,6 +336,20 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
336
336
def fail (msg : Message ) =
337
337
if ! tptToCheck.isEmpty then report.error(msg, tptToCheck.srcPos)
338
338
339
+ /** If C derives from Capability and we have a C^cs in source, we leave it as is
340
+ * instead of expanding it to C^{cap.rd}^cs. We do this by stripping capability-generated
341
+ * universal capture sets from the parent of a CapturingType.
342
+ */
343
+ def stripImpliedCaptureSet (tp : Type ): Type = tp match
344
+ case tp @ CapturingType (parent, refs)
345
+ if (refs eq CaptureSet .universalImpliedByCapability) && ! tp.isBoxedCapturing =>
346
+ parent
347
+ case tp : AliasingBounds =>
348
+ tp.derivedAlias(stripImpliedCaptureSet(tp.alias))
349
+ case tp : RealTypeBounds =>
350
+ tp.derivedTypeBounds(stripImpliedCaptureSet(tp.lo), stripImpliedCaptureSet(tp.hi))
351
+ case _ => tp
352
+
339
353
object toCapturing extends DeepTypeMap , SetupTypeMap :
340
354
override def toString = " transformExplicitType"
341
355
@@ -367,16 +381,6 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
367
381
CapturingType (fntpe, cs, boxed = false )
368
382
else fntpe
369
383
370
- /** If C derives from Capability and we have a C^cs in source, we leave it as is
371
- * instead of expanding it to C^{cap.rd}^cs. We do this by stripping capability-generated
372
- * universal capture sets from the parent of a CapturingType.
373
- */
374
- def stripImpliedCaptureSet (tp : Type ): Type = tp match
375
- case tp @ CapturingType (parent, refs)
376
- if (refs eq CaptureSet .universalImpliedByCapability) && ! tp.isBoxedCapturing =>
377
- parent
378
- case _ => tp
379
-
380
384
/** Check that types extending SharedCapability don't have a `cap` in their capture set.
381
385
* TODO This is not enough.
382
386
* We need to also track that we cannot get exclusive capabilities in paths
@@ -456,8 +460,11 @@ class Setup extends PreRecheck, SymTransformer, SetupAPI:
456
460
toCapturing.keepFunAliases = false
457
461
transform(tp1)
458
462
else tp1
459
- if freshen then root.capToFresh(tp2).tap(addOwnerAsHidden(_, sym))
460
- else tp2
463
+ val tp3 =
464
+ if sym.isType then stripImpliedCaptureSet(tp2)
465
+ else tp2
466
+ if freshen then root.capToFresh(tp3).tap(addOwnerAsHidden(_, sym))
467
+ else tp3
461
468
end transformExplicitType
462
469
463
470
/** Substitute parameter symbols in `from` to paramRefs in corresponding
0 commit comments