You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/_docs/reference/experimental/cc.md
+6-4Lines changed: 6 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -43,10 +43,12 @@ followed by `^`. We'll see that this turns the parameter into a _capability_ who
43
43
44
44
If we now try to define the problematic value `later`, we get a static error:
45
45
```
46
-
| val later = usingLogFile { f => () => f.write(0) }
47
-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48
-
|The expression's type () => Unit is not allowed to capture the root capability `cap`.
49
-
|This usually means that a capability persists longer than its allowed lifetime.
46
+
|val later = usingLogFile { f => () => f.write(0) } // error
47
+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
48
+
|Found: (f: java.io.FileOutputStream^?) ->? () ->{f} Unit
49
+
|Required: java.io.FileOutputStream^ => () ->? Unit
50
+
|
51
+
|Note that capability f cannot be included in outer capture set ?.
50
52
```
51
53
In this case, it was easy to see that the `logFile` capability escapes in the closure passed to `usingLogFile`. But capture checking also works for more complex cases.
52
54
For instance, capture checking is able to distinguish between the following safe code:
0 commit comments