@@ -468,29 +468,23 @@ extension (tp: Type)
468
468
end CheckContraCaps
469
469
470
470
object narrowCaps extends TypeMap :
471
- /** Has the variance been flipped at this point? */
472
- private var isFlipped : Boolean = false
473
-
474
471
def apply (t : Type ) =
475
- val saved = isFlipped
476
- try
477
- if variance <= 0 then isFlipped = true
478
- t.dealias match
479
- case t1 @ CapturingType (p, cs) if cs.isUniversal && ! isFlipped =>
480
- t1.derivedCapturingType(apply(p), ref.reach.singletonCaptureSet)
481
- case t1 @ FunctionOrMethod (args, res @ Existential (_, _))
482
- if args.forall(_.isAlwaysPure) =>
483
- // Also map existentials in results to reach capabilities if all
484
- // preceding arguments are known to be always pure
485
- apply(t1.derivedFunctionOrMethod(args, Existential .toCap(res)))
486
- case Existential (_, _) =>
487
- t
488
- case _ => t match
489
- case t @ CapturingType (p, cs) =>
490
- t.derivedCapturingType(apply(p), cs) // don't map capture set variables
491
- case t =>
492
- mapOver(t)
493
- finally isFlipped = saved
472
+ if variance <= 0 then t
473
+ else t.dealiasKeepAnnots match
474
+ case t @ CapturingType (p, cs) if cs.isUniversal =>
475
+ t.derivedCapturingType(apply(p), ref.reach.singletonCaptureSet)
476
+ case t @ AnnotatedType (parent, ann) =>
477
+ // Don't map annotations, which includes capture sets
478
+ t.derivedAnnotatedType(this (parent), ann)
479
+ case t @ FunctionOrMethod (args, res @ Existential (_, _))
480
+ if args.forall(_.isAlwaysPure) =>
481
+ // Also map existentials in results to reach capabilities if all
482
+ // preceding arguments are known to be always pure
483
+ apply(t.derivedFunctionOrMethod(args, Existential .toCap(res)))
484
+ case Existential (_, _) =>
485
+ t
486
+ case _ =>
487
+ mapOver(t)
494
488
end narrowCaps
495
489
496
490
ref match
0 commit comments