Skip to content

Commit 25b23c1

Browse files
committed
Fix capture sets of applied types
A substitution was missing for type parameters that appear in the capture set of the constructor.
1 parent 3cf68e3 commit 25b23c1

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

compiler/src/dotty/tools/dotc/core/CaptureSet.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@ case class CaptureSet private (elems: CaptureSet.Refs) extends Showable:
5454
def <:< (that: CaptureSet)(using Context): Boolean =
5555
elems.isEmpty || elems.forall(that.accountsFor)
5656

57+
def flatMap(f: CaptureRef => CaptureSet)(using Context): CaptureSet =
58+
(empty /: elems)((cs, ref) => cs ++ f(ref))
59+
60+
def substParams(tl: BindingType, to: List[Type])(using Context) =
61+
flatMap {
62+
case ref: ParamRef if ref.binder eq tl => to(ref.paramNum).captureSet
63+
case ref => ref.singletonCaptureSet
64+
}
65+
5766
override def toString = elems.toString
5867

5968
override def toText(printer: Printer): Text =
@@ -98,6 +107,11 @@ object CaptureSet:
98107
tp.captureSet
99108
case CapturingType(parent, ref) =>
100109
recur(parent) + ref
110+
case AppliedType(tycon, args) =>
111+
val cs = recur(tycon)
112+
tycon.typeParams match
113+
case tparams @ (LambdaParam(tl, _) :: _) => cs.substParams(tl, args)
114+
case _ => cs
101115
case tp: TypeProxy =>
102116
recur(tp.underlying)
103117
case AndType(tp1, tp2) =>

0 commit comments

Comments
 (0)