Home / Docs / Diagnostics

U3004: Capability used in a pure function

Release v0.4.0

A pure function uses a capability.

Why Una rejects it

A function without uses is pure: it cannot contain any @ (spec/04 §2 rule 4). This holds for:

A private function without uses is not pure: its uses are inferred (spec/04 §5).

How to fix it

Declare the capability in the header, or in the function type the lambda is written for. The repair is marked as a widening of authority (ADR 0097).

The repair at a glance

diff
  module demo

  capability Log
    op write(line: Text) -> Unit

- pub report() -> Unit = @log.write("done")
+ pub report() -> Unit
+   uses @log: Log[write]
+ =
+   @log.write("done")

Failing example

una
module demo

capability Log
  op write(line: Text) -> Unit

pub report() -> Unit = @log.write("done")

Fixed example

una
module demo

capability Log
  op write(line: Text) -> Unit

pub report() -> Unit
  uses @log: Log[write]
=
  @log.write("done")