@@ -118,7 +118,15 @@ trait CaptureRef extends TypeProxy, ValueType:
118118 case info : SingletonCaptureRef => test(info)
119119 case info : AndType => viaInfo(info.tp1)(test) || viaInfo(info.tp2)(test)
120120 case info : OrType => viaInfo(info.tp1)(test) && viaInfo(info.tp2)(test)
121- case info @ CapturingType (_,_) if this .derivesFrom(defn.Caps_CapSet ) => test(info)
121+ case info @ CapturingType (_,_) if this .derivesFrom(defn.Caps_CapSet ) =>
122+ /*
123+ If `this` is a capture set variable `C^`, then it is possible that it can be
124+ reached from term variables in a reachability chain through the context.
125+ For instance, in `def test[C^](src: Foo^{C^}) = { val x: Foo^{src} = src; val y: Foo^{x} = x; y }`
126+ we expect that `C^` subsumes `x` and `y` in the body of the method
127+ (cf. test case cc-poly-varargs.scala for a more involved example).
128+ */
129+ test(info)
122130 case _ => false
123131
124132 (this eq y)
@@ -150,6 +158,10 @@ trait CaptureRef extends TypeProxy, ValueType:
150158 case TypeBounds (_, hi : CaptureRef ) => this .subsumes(hi)
151159 case _ => y.captureSetOfInfo.elems.forall(this .subsumes)
152160 case CapturingType (parent, refs) if parent.derivesFrom(defn.Caps_CapSet ) || this .derivesFrom(defn.Caps_CapSet ) =>
161+ /* The second condition in the guard is for `this` being a `CapSet^{a,b...}` and etablishing a
162+ potential reachability chain through `y`'s capture to a binding with
163+ `this`'s capture set (cf. `CapturingType` case in `def viaInfo` above for more context).
164+ */
153165 refs.elems.forall(this .subsumes)
154166 case _ => false
155167 || this .match
0 commit comments