Home / Docs / Diagnostics
U3006: Effectful or failing lambda escapes
Release v0.4.0
A lambda or a function with uses or fails is bound with let, returned or stored.
Why Una rejects it
A lambda whose function type has uses or fails is second-class: it may be passed directly as a call argument, and nothing else (spec/05 §6, spec/10 §9). It cannot be bound with let, returned or stored, so that the authority it carries never outlives the call.
The same holds for a function with uses or fails used as a value. A kind cannot have a field of such a function type.
How to fix it
Pass the lambda or the function directly where it is called.
The repair at a glance
diff
module demo
capability Log
op write(line: Text) -> Unit
pub each(lines: List[Text], write: fn(Text) -> Unit uses @log: Log[write]) -> Unit
uses @log: Log[write]
=
unit
pub run(lines: List[Text]) -> Unit
uses @log: Log[write]
=
- let write: fn(Text) -> Unit uses @log: Log[write] = fn(line) -> @log.write(line)
- each(lines, write)
+ each(lines, write: fn(line) -> @log.write(line))Failing example
una
module demo
capability Log
op write(line: Text) -> Unit
pub each(lines: List[Text], write: fn(Text) -> Unit uses @log: Log[write]) -> Unit
uses @log: Log[write]
=
unit
pub run(lines: List[Text]) -> Unit
uses @log: Log[write]
=
let write: fn(Text) -> Unit uses @log: Log[write] = fn(line) -> @log.write(line)
each(lines, write)Fixed example
una
module demo
capability Log
op write(line: Text) -> Unit
pub each(lines: List[Text], write: fn(Text) -> Unit uses @log: Log[write]) -> Unit
uses @log: Log[write]
=
unit
pub run(lines: List[Text]) -> Unit
uses @log: Log[write]
=
each(lines, write: fn(line) -> @log.write(line))