Skip to content

Commit 2668951

Browse files
committed
Turn on type-based avoidance
1 parent 2e24bea commit 2668951

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ class CheckCaptures extends Recheck, SymTransformer:
548548
val included = cs.filter: c =>
549549
val isVisible = isVisibleFromEnv(c.pathOwner, env)
550550
if !isVisible then
551-
if ccConfig.deferredReaches
551+
if ccConfig.deferredReaches || ccConfig.caplessLike
552552
then avoidLocalCapability(c, env, lastEnv)
553553
else avoidLocalReachCapability(c, env)
554554
isVisible
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/capless-strawman3.scala:5:23 ------------------------------
2+
5 | val t2: () -> Unit = () => op()() // error
3+
| ^^^^^^^^^^^^
4+
| Found: () ->{io1} Unit
5+
| Required: () -> Unit
6+
|
7+
| Note that capability io1 is not included in capture set {}.
8+
|
9+
| longer explanation available when compiling with `-explain`
10+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/capless-strawman3.scala:7:23 ------------------------------
11+
7 | val t3: () -> Unit = () => op()()() // error
12+
| ^^^^^^^^^^^^^^
13+
| Found: () ->{io1, io2} Unit
14+
| Required: () -> Unit
15+
|
16+
| Note that capability io1 is not included in capture set {}.
17+
|
18+
| longer explanation available when compiling with `-explain`
19+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/capless-strawman3.scala:8:29 ------------------------------
20+
8 | val t3a: () ->{io2} Unit = () => op()()() // error
21+
| ^^^^^^^^^^^^^^
22+
| Found: () ->{io1, io2} Unit
23+
| Required: () ->{io2} Unit
24+
|
25+
| Note that capability io1 is not included in capture set {io2}.
26+
|
27+
| longer explanation available when compiling with `-explain`
28+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/capless-strawman3.scala:11:23 -----------------------------
29+
11 | val t1: () -> Unit = () => // error
30+
| ^
31+
| Found: () ->{io1} Unit
32+
| Required: () -> Unit
33+
|
34+
| Note that capability io1 is not included in capture set {}.
35+
12 | val f = op()
36+
13 | f()
37+
|
38+
| longer explanation available when compiling with `-explain`
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import language.experimental.captureChecking
2+
trait IO { def println(msg: String): Unit }
3+
def test1(io1: IO^, io2: IO^, op: () -> () ->{io1} () ->{io2} Unit): Unit =
4+
val t1: () -> Unit = () => op()
5+
val t2: () -> Unit = () => op()() // error
6+
val t2a: () ->{io1} Unit = () => op()()
7+
val t3: () -> Unit = () => op()()() // error
8+
val t3a: () ->{io2} Unit = () => op()()() // error
9+
val t3b: () ->{io1, io2} Unit = () => op()()()
10+
def test2(io1: IO^, io2: IO^, op: () -> () ->{io1} () ->{io2} Unit): Unit =
11+
val t1: () -> Unit = () => // error
12+
val f = op()
13+
f()

0 commit comments

Comments
 (0)