Home / Docs / Diagnostics

U3008: if error pass with a different error kind

Release v0.4.0

An if error pass passes a failure whose error kind is not the error kind of the current function.

Why Una rejects it

if error pass propagates a failure unchanged, so the error kind of the expression must equal the error kind of the current function (spec/06 §3): a function has at most one error kind (spec/06 §1).

A function without fails cannot pass a failure at all, except a private one, whose error kind is inferred from its first failure in source order (spec/04 §5 rule 3, ADR 0099): a pass of another kind is reported here.

How to fix it

The repair at a glance

diff
  module demo

  kind StoreError = Timeout | Corrupted

  kind LookupError = Missing | Unavailable

  capability Store
    op find(key: Int) -> Option[Int]
      fails StoreError

  pub lookup(key: Int) -> Option[Int]
    uses @store: Store[find]
    fails LookupError
  =
    @store.find(key)
-     if error pass
+     if error fail Unavailable

Failing example

una
module demo

kind StoreError = Timeout | Corrupted

kind LookupError = Missing | Unavailable

capability Store
  op find(key: Int) -> Option[Int]
    fails StoreError

pub lookup(key: Int) -> Option[Int]
  uses @store: Store[find]
  fails LookupError
=
  @store.find(key)
    if error pass

Fixed example

una
module demo

kind StoreError = Timeout | Corrupted

kind LookupError = Missing | Unavailable

capability Store
  op find(key: Int) -> Option[Int]
    fails StoreError

pub lookup(key: Int) -> Option[Int]
  uses @store: Store[find]
  fails LookupError
=
  @store.find(key)
    if error fail Unavailable