Home / Docs / Diagnostics
U3002: Operation not permitted by capability type
Release v0.4.0
The code uses an operation that the capability type of the binding in scope does not permit.
Why Una rejects it
A binding @x: C[ops] permits only the operations listed in brackets; without brackets it permits all of them (spec/05 §3). U3002 reports:
- an operation that the binding in scope does not permit;
- a call whose callee needs more operations of
@xthan the caller holds, since passing a capability attenuates it but never widens it (spec/05 §4).
How to fix it
- When another binding in scope permits the operation, use it, or rebind the callee's reference to it with
with. The code keeps its authority. - Adding the operation to the
usesclause, or dropping the brackets to permit every operation, widens the header: every caller must then permit it too. That repair is marked as a widening in--jsonand ranks after the ones that keep authority (ADR 0097).
The repair at a glance
diff
module demo
capability Log
op write(line: Text) -> Unit
op flush() -> Unit
pub finish() -> Unit
- uses @log: Log[write]
+ uses @log: Log[write, flush]
=
@log.flush()Failing example
una
module demo
capability Log
op write(line: Text) -> Unit
op flush() -> Unit
pub finish() -> Unit
uses @log: Log[write]
=
@log.flush()Fixed example
una
module demo
capability Log
op write(line: Text) -> Unit
op flush() -> Unit
pub finish() -> Unit
uses @log: Log[write, flush]
=
@log.flush()