Skip to content

Commit 692fdb3

Browse files
committed
Fix infinite regress in avoidance for captures
1 parent bb1b215 commit 692fdb3

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import TypeComparer.subsumesExistentially
1818
import util.common.alwaysTrue
1919
import scala.collection.{mutable, immutable}
2020
import CCState.*
21+
import dotty.tools.dotc.core.TypeOps.AvoidMap
2122

2223
/** A class for capture sets. Capture sets can be constants or variables.
2324
* Capture sets support inclusion constraints <:< where <:< is subcapturing.
@@ -297,6 +298,15 @@ sealed abstract class CaptureSet extends Showable:
297298
else BiMapped(asVar, tm, mappedElems)
298299
case tm: IdentityCaptRefMap =>
299300
this
301+
case av: AvoidMap =>
302+
val mapped = mapRefs(elems, ref => ref match
303+
case n: NamedType if av.toAvoid(n) => empty //TODO what about variance?
304+
case r => extrapolateCaptureRef(r, av, av.variance)
305+
)
306+
if isConst then
307+
if mapped.isConst && mapped.elems == elems && !mapped.keepAlways then this
308+
else mapped
309+
else Mapped(asVar, av, av.variance, mapped)
300310
case _ =>
301311
val mapped = mapRefs(elems, tm, tm.variance)
302312
if isConst then

tests/pos-custom-args/captures/cc-poly-varargs.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
abstract class Source[+T, Cap^]:
2-
def transformValuesWith[U](f: (T -> U)^{Cap^}): Source[U, Cap]^{this, f} = ???
1+
abstract class Source[+T, Cap^]
32

4-
// TODO: The extension version of `transformValuesWith` doesn't work currently.
5-
// extension[T, Cap^](src: Source[T, Cap]^)
6-
// def transformValuesWith[U](f: (T -> U)^{Cap^}): Source[U, Cap]^{src, f} = ???
3+
extension[T, Cap^](src: Source[T, Cap]^)
4+
def transformValuesWith[U](f: (T -> U)^{Cap^}): Source[U, Cap]^{src, f} = ???
75

86
def race[T, Cap^](sources: Source[T, Cap]^{Cap^}*): Source[T, Cap]^{Cap^} = ???
97

0 commit comments

Comments
 (0)