Home / Docs / Diagnostics

U3018: of clause that names a parameter not of function type

Release v0.4.0

uses of p and fails of p give a function the effects and failures of the function that parameter p receives, so p MUST have a function type (ADR 0062). Naming a parameter of another type, such as a list or a number, is U3018. Name the parameter of function type instead.

The repair at a glance

src/demo.unadiff
  module demo

  pub apply_all(xs: List[Int], each: fn(Int) -> Unit) -> Unit
-   uses of xs
+   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 apply_all(xs: List[Int], each: fn(Int) -> Unit) -> Unit
  uses of xs
=
  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 apply_all(xs: List[Int], each: fn(Int) -> Unit) -> Unit
  uses of each
=
  for x in xs
    each(x)