@@ -373,7 +373,7 @@ object Types {
373373 case tp : AndOrType => tp.tp1.unusableForInference || tp.tp2.unusableForInference
374374 case tp : LambdaType => tp.resultType.unusableForInference || tp.paramInfos.exists(_.unusableForInference)
375375 case WildcardType (optBounds) => optBounds.unusableForInference
376- case CapturingType (parent, ref) => parent.unusableForInference || ref.unusableForInference
376+ case CapturingType (parent, ref) => parent.unusableForInference
377377 case _ : ErrorType => true
378378 case _ => false
379379
@@ -1385,7 +1385,7 @@ object Types {
13851385 val tp1 = tp.parent.dealias1(keep)
13861386 if keep(tp) then tp.derivedAnnotatedType(tp1, tp.annot) else tp1
13871387 case tp : CapturingType =>
1388- tp.derivedCapturingType(tp.parent.dealias1(keep), tp.ref )
1388+ tp.derivedCapturingType(tp.parent.dealias1(keep), tp.refs )
13891389 case tp : LazyRef =>
13901390 tp.ref.dealias1(keep)
13911391 case _ => this
@@ -1838,10 +1838,12 @@ object Types {
18381838 }
18391839
18401840 def capturing (ref : CaptureRef )(using Context ): Type =
1841- if captureSet.accountsFor(ref) then this else CapturingType (this , ref)
1841+ if captureSet.accountsFor(ref) then this
1842+ else CapturingType (this , ref.singletonCaptureSet)
18421843
18431844 def capturing (cs : CaptureSet )(using Context ): Type =
1844- (this /: cs.elems)(_.capturing(_))
1845+ val cs1 = cs -- captureSet
1846+ if cs1.isEmpty then this else CapturingType (this , cs)
18451847
18461848 /** The set of distinct symbols referred to by this type, after all aliases are expanded */
18471849 def coveringSet (using Context ): Set [Symbol ] =
@@ -3620,9 +3622,10 @@ object Types {
36203622 case tp : TermParamRef if tp.binder eq thisLambdaType => TrueDeps
36213623 case tp : CapturingType =>
36223624 val status1 = compute(status, tp.parent, theAcc)
3623- tp.ref.stripTypeVar match
3624- case tp : TermParamRef if tp.binder eq thisLambdaType => combine(status1, CaptureDeps )
3625- case _ => status1
3625+ (status1 /: tp.refs.elems)((s, ref) => ref.stripTypeVar match
3626+ case tp : TermParamRef if tp.binder eq thisLambdaType => combine(s, CaptureDeps )
3627+ case _ => s
3628+ )
36263629 case _ : ThisType | _ : BoundType | NoPrefix => status
36273630 case _ =>
36283631 (if theAcc != null then theAcc else DepAcc ()).foldOver(status, tp)
@@ -5162,39 +5165,38 @@ object Types {
51625165 unique(CachedAnnotatedType (parent, annot))
51635166 end AnnotatedType
51645167
5165- abstract case class CapturingType (parent : Type , ref : CaptureRef ) extends AnnotOrCaptType :
5168+ abstract case class CapturingType (parent : Type , refs : CaptureSet ) extends AnnotOrCaptType :
51665169 override def underlying (using Context ): Type = parent
51675170
5168- def derivedCapturingType (parent : Type , ref : CaptureRef )(using Context ): CapturingType =
5169- if (parent eq this .parent) && (ref eq this .ref) then this
5170- else CapturingType (parent, ref)
5171-
5172- def derivedCapturing (parent : Type , capt : Type )(using Context ): Type =
5173- if (parent eq this .parent) && (capt eq this .ref) then this
5174- else parent.capturing(capt.captureSet)
5171+ def derivedCapturingType (parent : Type , refs : CaptureSet )(using Context ): CapturingType =
5172+ if (parent eq this .parent) && (refs eq this .refs) then this
5173+ else CapturingType (parent, refs)
51755174
51765175 // equals comes from case class; no matching override is needed
51775176
51785177 override def computeHash (bs : Binders ): Int =
5179- doHash(bs, parent, ref )
5178+ doHash(bs, refs, parent )
51805179 override def hashIsStable : Boolean =
5181- parent.hashIsStable && ref. hashIsStable
5180+ parent.hashIsStable && refs.elems.forall(_. hashIsStable)
51825181
51835182 override def eql (that : Type ): Boolean = that match
5184- case that : CapturingType => (parent eq that.parent) && (ref eq that.ref )
5183+ case that : CapturingType => (parent eq that.parent) && refs.equals( that.refs )
51855184 case _ => false
51865185
51875186 override def iso (that : Any , bs : BinderPairs ): Boolean = that match
5188- case that : CapturingType => parent.equals(that.parent, bs) && ref .equals(that.ref, bs )
5187+ case that : CapturingType => parent.equals(that.parent, bs) && refs .equals(that.refs )
51895188 case _ => false
51905189
5191- class CachedCapturingType (parent : Type , ref : CaptureRef ) extends CapturingType (parent, ref )
5190+ class CachedCapturingType (parent : Type , refs : CaptureSet ) extends CapturingType (parent, refs )
51925191
51935192 object CapturingType :
5194- def apply (parent : Type , ref : CaptureRef )(using Context ): CapturingType =
5195- unique(CachedCapturingType (parent, ref.normalizedRef))
5196- def checked (parent : Type , ref : Type )(using Context ): CapturingType = ref match
5197- case ref : CaptureRef => apply(parent, ref)
5193+ def apply (parent : Type , refs : CaptureSet )(using Context ): CapturingType =
5194+ unique(CachedCapturingType (parent, refs.map(_.normalizedRef)))
5195+ def checked (parent : Type , tps : Type * )(using Context ): CapturingType =
5196+ val refs : Seq [CaptureRef ] = tps map {
5197+ case ref : CaptureRef => ref
5198+ }
5199+ apply(parent, CaptureSet (refs* ))
51985200 end CapturingType
51995201
52005202 // Special type objects and classes -----------------------------------------------------
@@ -5458,8 +5460,8 @@ object Types {
54585460 tp.derivedMatchType(bound, scrutinee, cases)
54595461 protected def derivedAnnotatedType (tp : AnnotatedType , underlying : Type , annot : Annotation ): Type =
54605462 tp.derivedAnnotatedType(underlying, annot)
5461- protected def derivedCapturing (tp : CapturingType , parent : Type , capt : Type ): Type =
5462- tp.derivedCapturing (parent, capt )
5463+ protected def derivedCapturingType (tp : CapturingType , parent : Type , cs : CaptureSet ): Type =
5464+ tp.derivedCapturingType (parent, cs )
54635465 protected def derivedWildcardType (tp : WildcardType , bounds : Type ): Type =
54645466 tp.derivedWildcardType(bounds)
54655467 protected def derivedSkolemType (tp : SkolemType , info : Type ): Type =
@@ -5539,8 +5541,8 @@ object Types {
55395541 if (underlying1 eq underlying) tp
55405542 else derivedAnnotatedType(tp, underlying1, mapOver(annot))
55415543
5542- case tp @ CapturingType (parent, ref ) =>
5543- derivedCapturing (tp, this (parent), this (ref ))
5544+ case tp @ CapturingType (parent, refs ) =>
5545+ derivedCapturingType (tp, this (parent), refs.flatMap( this (_).captureSet ))
55445546
55455547 case _ : ThisType
55465548 | _ : BoundType
@@ -5861,15 +5863,12 @@ object Types {
58615863 if (underlying.isExactlyNothing) underlying
58625864 else tp.derivedAnnotatedType(underlying, annot)
58635865 }
5864- override protected def derivedCapturing (tp : CapturingType , parent : Type , capt : Type ): Type =
5865- capt match
5866+ override protected def derivedCapturingType (tp : CapturingType , parent : Type , cs : CaptureSet ): Type =
5867+ parent match
58665868 case Range (lo, hi) =>
5867- range(derivedCapturing(tp, parent, hi), derivedCapturing(tp, parent, lo))
5868- case _ => parent match
5869- case Range (lo, hi) =>
5870- range(derivedCapturing(tp, lo, capt), derivedCapturing(tp, hi, capt))
5871- case _ =>
5872- tp.derivedCapturing(parent, capt)
5869+ range(derivedCapturingType(tp, lo, cs), derivedCapturingType(tp, hi, cs))
5870+ case _ =>
5871+ tp.derivedCapturingType(parent, cs)
58735872
58745873 override protected def derivedWildcardType (tp : WildcardType , bounds : Type ): WildcardType =
58755874 tp.derivedWildcardType(rangeToBounds(bounds))
@@ -6010,8 +6009,8 @@ object Types {
60106009 case AnnotatedType (underlying, annot) =>
60116010 this (applyToAnnot(x, annot), underlying)
60126011
6013- case CapturingType (parent, ref ) =>
6014- this (this (x, parent), ref )
6012+ case CapturingType (parent, refs ) =>
6013+ (this (x, parent) /: refs.elems)( this )
60156014
60166015 case tp : ProtoType =>
60176016 tp.fold(x, this )
0 commit comments