Skip to content

Commit e19328c

Browse files
committed
Fix noCaptures condition
1 parent 3bf9407 commit e19328c

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1514,7 +1514,14 @@ object Types {
15141514

15151515
def captureSet(using Context): CaptureSet = CaptureSet.ofType(this)
15161516
def noCaptures(using Context): Boolean =
1517-
ctx.mode.is(Mode.RelaxedCapturing) || captureSet.isEmpty
1517+
ctx.mode.is(Mode.RelaxedCapturing) || allCaptures.isEmpty
1518+
1519+
def allCaptures(using Context): CaptureSet = this match // ^^^^ optimize, relate with boxedCaptures?
1520+
case tp: CapturingType => tp.refs
1521+
case tp: TypeProxy => tp.superType.allCaptures
1522+
case tp: AndType => tp.tp1.allCaptures ++ tp.tp2.allCaptures
1523+
case tp: OrType => tp.tp1.allCaptures ** tp.tp2.allCaptures
1524+
case _ => CaptureSet.empty
15181525

15191526
// ----- Normalizing typerefs over refined types ----------------------------
15201527

tests/pos-custom-args/captures/boxmap-paper.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ type Cell[+T <: Top] = [K] => (T ==> K) => K
66
def cell[T <: Top](x: T): Cell[T] =
77
[K] => (k: T ==> K) => k(x)
88

9+
def identity[T <: Top](x: T): T = x
10+
911
def get[T <: Top](c: Cell[T]): T = c[T](identity)
1012

1113
def map[A <: Top, B <: Top](c: Cell[A])(f: A ==> B): Cell[B]

tests/pos-custom-args/captures/list-encoding.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ def foo(c: {*} Cap) =
1919
def f(x: String retains c.type, y: String retains c.type) =
2020
cons(x, cons(y, nil))
2121
def g(x: String retains c.type, y: Any) =
22-
cons(x, cons(y, nil))
22+
cons[{c} Any](x, cons[Any](y, nil)) // TODO: drop type arguments
2323
def h(x: String, y: Any retains c.type) =
2424
cons(x, cons(y, nil))

0 commit comments

Comments
 (0)