Skip to content

Commit b6132d9

Browse files
committed
Make caps.cap a given for caps.Root
1 parent 5e09178 commit b6132d9

File tree

3 files changed

+49
-21
lines changed

3 files changed

+49
-21
lines changed

library/src/scala/caps.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import annotation.experimental
1313
/** The universal capture reference */
1414
val cap: Root = ()
1515

16+
given Root = cap
17+
1618
object unsafe:
1719

1820
extension [T](x: T)
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
-- Error: tests/neg-custom-args/captures/levels.scala:15:11 ------------------------------------------------------------
1+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/levels.scala:15:11 ---------------------------------------
22
15 | r.setV(g) // error
33
| ^
4-
| reference (cap3 : CC^) is not included in the allowed capture set ?
5-
| of an enclosing function literal with expected type box (x$0: String) ->? String
4+
| Found: box (x: String) ->{cap3} String
5+
| Required: box (x$0: String) ->? String
66
|
77
| Note that reference (cap3 : CC^), defined at level 2
88
| cannot be included in outer capture set ?, defined at level 1 in method test
9+
|
10+
| longer explanation available when compiling with `-explain`
Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,50 @@
1-
-- Error: tests/neg-custom-args/captures/vars.scala:13:6 ---------------------------------------------------------------
2-
13 | var a: String => String = f // error
3-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
4-
| Mutable variable a cannot have type box String => String since
5-
| that type captures the root capability `cap`.
6-
| This restriction serves to prevent local capabilities from escaping the scope where they are defined.
7-
-- Error: tests/neg-custom-args/captures/vars.scala:14:6 ---------------------------------------------------------------
8-
14 | var b: List[String => String] = Nil // error
9-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
10-
| Mutable variable b cannot have type List[String => String] since
11-
| the part String => String of that type captures the root capability `cap`.
12-
| This restriction serves to prevent local capabilities from escaping the scope where they are defined.
131
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars.scala:11:24 -----------------------------------------
142
11 | val z2c: () -> Unit = z2 // error
153
| ^^
164
| Found: () ->{z2} Unit
175
| Required: () -> Unit
186
|
197
| longer explanation available when compiling with `-explain`
20-
-- Error: tests/neg-custom-args/captures/vars.scala:32:2 ---------------------------------------------------------------
21-
32 | local { cap3 => // error
8+
-- Error: tests/neg-custom-args/captures/vars.scala:23:14 --------------------------------------------------------------
9+
23 | a = x => g(x) // error
10+
| ^^^^
11+
| reference (cap3 : CC^) is not included in the allowed capture set {cap[test]}
12+
| of an enclosing function literal with expected type box String ->{cap[test]} String
13+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars.scala:24:8 ------------------------------------------
14+
24 | a = g // error
15+
| ^
16+
| Found: box (x: String) ->{cap3} String
17+
| Required: box (x$0: String) ->{cap[test]} String
18+
|
19+
| longer explanation available when compiling with `-explain`
20+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars.scala:26:12 -----------------------------------------
21+
26 | b = List(g) // error
22+
| ^^^^^^^
23+
| Found: List[box (x$0: String) ->{cap3} String]
24+
| Required: List[String ->{cap[test]} String]
25+
|
26+
| longer explanation available when compiling with `-explain`
27+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars.scala:30:10 -----------------------------------------
28+
30 | val s = scope // error (but should be OK, we need to allow poly-captures)
29+
| ^^^^^
30+
| Found: (x$0: String) ->{cap[scope]} String
31+
| Required: (x$0: String) ->? String
32+
|
33+
| Note that reference (cap[scope] : caps.Root), defined at level 2
34+
| cannot be included in outer capture set ?, defined at level 1 in method test
35+
|
36+
| longer explanation available when compiling with `-explain`
37+
-- [E007] Type Mismatch Error: tests/neg-custom-args/captures/vars.scala:31:29 -----------------------------------------
38+
31 | val sc: String => String = scope // error (but should also be OK)
39+
| ^^^^^
40+
| Found: (x$0: String) ->{cap[scope]} String
41+
| Required: String => String
42+
|
43+
| Note that reference (cap[scope] : caps.Root), defined at level 2
44+
| cannot be included in outer capture set ?, defined at level 1 in method test
45+
|
46+
| longer explanation available when compiling with `-explain`
47+
-- Error: tests/neg-custom-args/captures/vars.scala:35:2 ---------------------------------------------------------------
48+
35 | local { root => cap3 => // error
2249
| ^^^^^
23-
| Sealed type variable T cannot be instantiated to box (x$0: String) => String since
24-
| that type captures the root capability `cap`.
25-
| This is often caused by a local capability in an argument of method local
26-
| leaking as part of its result.
50+
| escaping local reference root.type

0 commit comments

Comments
 (0)