Home / Docs / Diagnostics

U3019: of clause that names a function type with its own uses or fails

Release v0.4.0

An of clause leaves the effects and failures of a parameter open: each call gives them by its argument (ADR 0062). A parameter whose type writes its own uses or fails, as in fn(Int) -> Unit uses @log: Log[write], fixes them already, so uses of or fails of on it is U3019. Remove the clauses from the parameter's type to make it open, or remove the of clause to keep the fixed effects.

The repair at a glance

src/demo.unadiff
  module demo

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

- pub apply_all(xs: List[Int], each: fn(Int) -> Unit uses @log: Log[write]) -> Unit
-   uses @log: Log[write]
+ pub apply_all(xs: List[Int], each: fn(Int) -> Unit) -> Unit
    uses of each
  =
    for x in xs
      each(x)

Failing example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"
src/demo.unauna
module demo

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

pub apply_all(xs: List[Int], each: fn(Int) -> Unit uses @log: Log[write]) -> Unit
  uses @log: Log[write]
  uses of each
=
  for x in xs
    each(x)

Fixed example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"
src/demo.unauna
module demo

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

pub apply_all(xs: List[Int], each: fn(Int) -> Unit) -> Unit
  uses of each
=
  for x in xs
    each(x)