@@ -1064,7 +1064,7 @@ object CaptureSet:
10641064    case  ref : (TermRef  |  TermParamRef ) if  ref.isMaxCapability => 
10651065      if  ref.isTrackableRef then  ref.singletonCaptureSet
10661066      else  CaptureSet .universal
1067-     case  ReachCapability (ref1) =>  deepCaptureSet( ref1.widen) 
1067+     case  ReachCapability (ref1) =>  ref1.widen.deepCaptureSet 
10681068      .showing(i " Deep capture set of  $ref:  ${ref1.widen} =  $result" , capt)
10691069    case  _ =>  ofType(ref.underlying, followResult =  true )
10701070
@@ -1115,17 +1115,25 @@ object CaptureSet:
11151115
11161116  /**  The deep capture set of a type is the union of all covariant occurrences of 
11171117   *  capture sets. Nested existential sets are approximated with `cap`. 
1118+    *  NOTE: The traversal logic needs to be in sync with narrowCaps in CaptureOps, which 
1119+    *  replaces caps with reach capabilties. 
11181120   */  
11191121  def  ofTypeDeeply (tp : Type )(using  Context ):  CaptureSet  = 
11201122    val  collect  =  new  TypeAccumulator [CaptureSet ]: 
1121-       def  apply (cs : CaptureSet , t : Type ) =  t.dealias match 
1122-         case  t @  CapturingType (p, cs1) => 
1123-           val  cs2  =  apply(cs, p)
1124-           if  variance >  0  then  cs2 ++  cs1 else  cs2
1125-         case  t @  Existential (_, _) => 
1126-           apply(cs, Existential .toCap(t))
1127-         case  _ => 
1128-           foldOver(cs, t)
1123+       def  apply (cs : CaptureSet , t : Type ) = 
1124+         if  variance <=  0  then  cs
1125+         else  t.dealias match 
1126+           case  t @  CapturingType (p, cs1) => 
1127+             this (cs, p) ++  cs1
1128+           case  t @  AnnotatedType (parent, ann) => 
1129+             this (cs, parent)
1130+           case  t @  FunctionOrMethod (args, res @  Existential (_, _))
1131+           if  args.forall(_.isAlwaysPure) => 
1132+             this (cs, Existential .toCap(res))
1133+           case  t @  Existential (_, _) => 
1134+             cs
1135+           case  _ => 
1136+             foldOver(cs, t)
11291137    collect(CaptureSet .empty, tp)
11301138
11311139  type  AssumedContains  =  immutable.Map [TypeRef , SimpleIdentitySet [CaptureRef ]]
0 commit comments