Skip to content

Commit ec8d119

Browse files
committed
Turn off withCapAsRoot exception for box adaptation
TODO: Check that the new error in box-adapt-contra makes sense TODO: error messages need to be improved
1 parent d27f2bb commit ec8d119

File tree

4 files changed

+23
-12
lines changed

4 files changed

+23
-12
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ class CheckCaptures extends Recheck, SymTransformer:
14531453
val cs = actual.captureSet
14541454
if covariant then cs ++ leaked
14551455
else
1456-
if CCState.withCapAsRoot: // Not sure this is OK, actually
1456+
if // CCState.withCapAsRoot: // Not sure withCapAsRoot is OK here, actually
14571457
!leaked.subCaptures(cs).isOK
14581458
then
14591459
report.error(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- Error: tests/neg-custom-args/captures/box-adapt-contra.scala:9:52 ---------------------------------------------------
2+
9 | val f: (Cap^{c} -> Unit) -> Unit = useCap[Cap^{c}](c) // error
3+
| ^^^^^^^^^^^^^^^^^^
4+
| Cap^{c} -> Unit cannot be box-converted to box Cap^{c} ->{c} Unit
5+
| since the additional capture set {c} resulted from box conversion is not allowed in box Cap^{c} -> Unit
6+
-- Error: tests/neg-custom-args/captures/box-adapt-contra.scala:13:57 --------------------------------------------------
7+
13 | val f1: (Cap^{c} => Unit) ->{c} Unit = useCap1[Cap^{c}](c) // error, was ok when cap was a root
8+
| ^^^^^^^^^^^^^^^^^^^
9+
| Cap^{c} => Unit cannot be box-converted to box Cap^{c} ->{cap, c} Unit
10+
| since the additional capture set {c} resulted from box conversion is not allowed in box Cap^{c} => Unit
11+
-- Error: tests/neg-custom-args/captures/box-adapt-contra.scala:19:54 --------------------------------------------------
12+
19 | val f3: (Cap^{c} -> Unit) => Unit = useCap3[Cap^{c}](c) // error
13+
| ^^^^^^^^^^^^^^^^^^^
14+
| Cap^{c} -> Unit cannot be box-converted to box Cap^{c} ->{d, c} Unit
15+
| since the additional capture set {c} resulted from box conversion is not allowed in box Cap^{c} ->{d} Unit

tests/neg-custom-args/captures/box-adapt-contra.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def test1(c: Cap^): Unit =
1010

1111
def test2(@consume c: Cap^, d: Cap^): Unit =
1212
def useCap1[X](x: X): (X => Unit) -> Unit = ???
13-
val f1: (Cap^{c} => Unit) ->{c} Unit = useCap1[Cap^{c}](c) // ok
13+
val f1: (Cap^{c} => Unit) ->{c} Unit = useCap1[Cap^{c}](c) // error, was ok when cap was a root
1414

1515
def useCap2[X](x: X): (X ->{c} Unit) -> Unit = ???
1616
val f2: (Cap^{c} -> Unit) ->{c} Unit = useCap2[Cap^{c}](c) // ok

tests/neg-custom-args/captures/i15772.check

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,21 @@
33
| ^
44
| reference (x : C^) is not included in the allowed capture set {}
55
| of an enclosing function literal with expected type () -> Int
6-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:22:46 ---------------------------------------
6+
-- Error: tests/neg-custom-args/captures/i15772.scala:22:46 ------------------------------------------------------------
77
22 | val boxed1 : ((C^) => Unit) -> Unit = box1(c) // error
88
| ^^^^^^^
9-
| Found: (C{val arg: C^}^{c} => Unit) ->{c} Unit
10-
| Required: (C^ => Unit) -> Unit
11-
|
12-
| longer explanation available when compiling with `-explain`
9+
|C^ => Unit cannot be box-converted to box C{val arg: C^}^{c} ->{cap, c} Unit
10+
|since the additional capture set {c} resulted from box conversion is not allowed in box C{val arg: C^}^{c} => Unit
1311
-- Error: tests/neg-custom-args/captures/i15772.scala:28:26 ------------------------------------------------------------
1412
28 | val c : C^{x} = new C(x) // error
1513
| ^
1614
| reference (x : C^) is not included in the allowed capture set {}
1715
| of an enclosing function literal with expected type () -> Int
18-
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:29:35 ---------------------------------------
16+
-- Error: tests/neg-custom-args/captures/i15772.scala:29:35 ------------------------------------------------------------
1917
29 | val boxed2 : Observe[C^] = box2(c) // error
2018
| ^^^^^^^
21-
| Found: (C{val arg: C^}^{c} => Unit) ->{c} Unit
22-
| Required: (C^ => Unit) -> Unit
23-
|
24-
| longer explanation available when compiling with `-explain`
19+
|C^ => Unit cannot be box-converted to box C{val arg: C^}^{c} ->{cap, c} Unit
20+
|since the additional capture set {c} resulted from box conversion is not allowed in box C{val arg: C^}^{c} => Unit
2521
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/i15772.scala:35:34 ---------------------------------------
2622
35 | val boxed2 : Observe[C]^ = box2(c) // error
2723
| ^

0 commit comments

Comments
 (0)