Skip to content

Commit dddd6bc

Browse files
committed
Drop checkReachCapsIsolated restriction
1 parent 29d01c2 commit dddd6bc

File tree

6 files changed

+34
-10
lines changed

6 files changed

+34
-10
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class CheckCaptures extends Recheck, SymTransformer:
259259
ctx.printer.toTextCaptureRef(ref).show
260260

261261
// Uses 4-space indent as a trial
262-
def checkReachCapsIsolated(tpe: Type, pos: SrcPos)(using Context): Unit =
262+
private def checkReachCapsIsolated(tpe: Type, pos: SrcPos)(using Context): Unit =
263263

264264
object checker extends TypeTraverser:
265265
var refVariances: Map[Boolean, Int] = Map.empty
@@ -854,7 +854,8 @@ class CheckCaptures extends Recheck, SymTransformer:
854854
tree.tpe
855855
finally curEnv = saved
856856
if tree.isTerm then
857-
checkReachCapsIsolated(res.widen, tree.srcPos)
857+
if !ccConfig.useExistentials then
858+
checkReachCapsIsolated(res.widen, tree.srcPos)
858859
if !pt.isBoxedCapturing then
859860
markFree(res.boxedCaptureSet, tree.srcPos)
860861
res

tests/neg-custom-args/captures/unsound-reach.check

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
-- Error: tests/neg-custom-args/captures/unsound-reach.scala:18:13 -----------------------------------------------------
2-
18 | boom.use(f): (f1: File^{backdoor*}) => // error
3-
| ^^^^^^^^
4-
| Reach capability backdoor* and universal capability cap cannot both
5-
| appear in the type (x: File^)(op: box File^{backdoor*} => Unit): Unit of this expression
61
-- [E164] Declaration Error: tests/neg-custom-args/captures/unsound-reach.scala:10:8 -----------------------------------
72
10 | def use(x: File^)(op: File^ => Unit): Unit = op(x) // error, was OK using sealed checking
83
| ^

tests/neg-custom-args/captures/unsound-reach.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@ def bad(): Unit =
1515

1616
var escaped: File^{backdoor*} = null
1717
withFile("hello.txt"): f =>
18-
boom.use(f): (f1: File^{backdoor*}) => // error
18+
boom.use(f): (f1: File^{backdoor*}) => // was error before existentials
1919
escaped = f1
2020

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/widen-reach.scala:13:26 ----------------------------------
2+
13 | val y2: IO^ -> IO^ = y1.foo // error
3+
| ^^^^^^
4+
| Found: IO^ ->{x*} IO^{x*}
5+
| Required: IO^ -> (ex$6: caps.Exists) -> IO^{ex$6}
6+
|
7+
| longer explanation available when compiling with `-explain`
8+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/widen-reach.scala:14:30 ----------------------------------
9+
14 | val y3: IO^ -> IO^{x*} = y1.foo // error
10+
| ^^^^^^
11+
| Found: IO^ ->{x*} IO^{x*}
12+
| Required: IO^ -> IO^{x*}
13+
|
14+
| longer explanation available when compiling with `-explain`
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import language.experimental.captureChecking
2+
3+
trait IO
4+
5+
trait Foo[+T]:
6+
val foo: IO^ -> T
7+
8+
trait Bar extends Foo[IO^]:
9+
val foo: IO^ -> IO^ = x => x
10+
11+
def test(x: Foo[IO^]): Unit =
12+
val y1: Foo[IO^{x*}] = x
13+
val y2: IO^ -> IO^ = y1.foo // error
14+
val y3: IO^ -> IO^{x*} = y1.foo // error

tests/neg/i20503.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ class List[+A]:
99

1010
def runOps(ops: List[() => Unit]): Unit =
1111
// See i20156, due to limitation in expressiveness of current system,
12-
// we cannot map over the list of impure elements.
13-
ops.foreach(op => op()) // error
12+
// we could map over the list of impure elements. OK with existentials.
13+
ops.foreach(op => op())
1414

1515
def main(): Unit =
1616
val f: List[() => Unit] -> Unit = runOps // error

0 commit comments

Comments
 (0)