Home / Docs / Diagnostics
U3005: Capability reference used as a value
Release v0.4.0
Capability references are not values (spec/05 §6). A bare @c, not followed by .op(...), appears only on either side of a with binding and after given @x = (spec/02 §8); it cannot be bound with let, passed as an argument, returned, stored in a kind, compared or interpolated. Authority moves only downward along calls, by name: the callee declares the capability with uses, and the caller passes it under that name or rebinds it with with.
The repair at a glance
diff
module demo
capability Log
op write(line: Text) -> Unit
- pub run() -> Unit
+ pub note(line: Text) -> Unit
uses @log: Log[write]
=
- let sink = @log
- unit
+ @log.write(line)
+
+ pub run() -> Unit
+ uses @sink: Log[write]
+ =
+ note("done") with @log = @sinkFailing example
una
module demo
capability Log
op write(line: Text) -> Unit
pub run() -> Unit
uses @log: Log[write]
=
let sink = @log
unitFixed example
una
module demo
capability Log
op write(line: Text) -> Unit
pub note(line: Text) -> Unit
uses @log: Log[write]
=
@log.write(line)
pub run() -> Unit
uses @sink: Log[write]
=
note("done") with @log = @sink