Home / Docs / Diagnostics
U3001: Capability not in scope
Release v0.4.0
The code refers to a capability that no binding in scope holds.
Why Una rejects it
A capability operation @c.op(...) acts through the binding @c of the current capability context (spec/05 §1, §3):
- a
usesclause of the header; - a
withbinding of the statement; - a
givenline of an example; - the
usesof the function type a lambda is written for.
U3001 reports a reference that no binding in scope holds. It also reports:
- a call whose callee needs
@x: C[ops]when the caller holds no@x, or holds a capability other thanCunder that name (spec/05 §4); - a
doline that needs a capability nogivenline binds (spec/08 §2); - a private function whose inferred reference cannot be given one capability, because no caller binds it or callers bind it to different capabilities (spec/04 §5).
How to fix it
- Bind it with
withfrom a binding in scope, or install a handler withgiven. These keep the code's authority. - Declaring the capability with
useswidens the header, and its repair says so (ADR 0097).
The repair at a glance
diff
module demo
capability Log
op write(line: Text) -> Unit
pub note(line: Text) -> Unit
- uses @journal: Log[write]
+ uses @log: Log[write]
=
@log.write(line)Failing example
una
module demo
capability Log
op write(line: Text) -> Unit
pub note(line: Text) -> Unit
uses @journal: Log[write]
=
@log.write(line)Fixed example
una
module demo
capability Log
op write(line: Text) -> Unit
pub note(line: Text) -> Unit
uses @log: Log[write]
=
@log.write(line)