Home / Docs / Diagnostics

U3022: Labeled operation passed to code that reads it lower

Release v0.4.0

A call passes a binding whose operation gives more than the label at which the callee reads its answers.

Why Una rejects it

In edition 0.3, an operation listed in a header's uses brackets can carry gives and a label: uses @service_files: Files[owner gives internal[Service]] says that what owner answers through this binding, the value and whether it failed, belongs to the principal Service (ADR 0094, spec/05 §3). The answer then carries the label, and the flow rules of spec/07 keep it from reaching anyone below it.

A binding flows to a callee by name or with with, and its labels go with it. The callee reads the operation's answers at the label its own header writes, public when it writes none. A private function without uses clauses infers its labels instead, the join of what its callers pass, so the labeled binding reaches it and its body reads the answers at that label.

A binding whose operation gives more than that is refused at the call with U3022: the callee would read the answer below its label.

How to fix it

The repairs never lower a label:

The repair at a glance

src/demo.unadiff
  module demo

  pub capability Files
    op owner(file: Text) -> Text

- owner_seen(file: Text) -> Text
-   uses @files: Files[owner]
+ owner_seen(file: Text) -> internal[Service] Text
+   uses @files: Files[owner gives internal[Service]]
  =
    @files.owner(file)

  pub refusal(file: Text) -> internal[Service] Text
    uses @service_files: Files[owner gives internal[Service]]
  =
    let seen = owner_seen(file) with @files = @service_files
    seen

Failing example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"

[labels]
categories = ["Service"]
src/demo.unauna
module demo

pub capability Files
  op owner(file: Text) -> Text

owner_seen(file: Text) -> Text
  uses @files: Files[owner]
=
  @files.owner(file)

pub refusal(file: Text) -> internal[Service] Text
  uses @service_files: Files[owner gives internal[Service]]
=
  let seen = owner_seen(file) with @files = @service_files
  seen

Fixed example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.3"

[labels]
categories = ["Service"]
src/demo.unauna
module demo

pub capability Files
  op owner(file: Text) -> Text

owner_seen(file: Text) -> internal[Service] Text
  uses @files: Files[owner gives internal[Service]]
=
  @files.owner(file)

pub refusal(file: Text) -> internal[Service] Text
  uses @service_files: Files[owner gives internal[Service]]
=
  let seen = owner_seen(file) with @files = @service_files
  seen