Home / Docs / Diagnostics

U2035: first of with fewer than two branches, or a line that is not an expression; start outside the block of a tasks, inside a task within it, or with a with clause

Release v0.4.0

A first of or a start is written in a form or a place that is an error.

Why Una rejects it

In edition 0.4, first of races its branches: each line of its body is a branch, an expression with its with bindings, its deadline and its handling clauses, and each branch runs as a task (spec/27 §6, ADR 0117 rule 6). The first branch to return gives the value, and the others are canceled. It is an error:

start starts a task in the block of a tasks statement, which waits for every task it starts (spec/27 §7, ADR 0117 rule 7). It is an error:

How to fix it

For first of:

For start with a with clause, install the handler around the call of the function that holds the tasks statement, or inside the started function.

The repair at a glance

src/demo.unadiff
  module demo

  primary(n: Int) -> Int = n + 1

+ replica(n: Int) -> Int = n + 1
+
  pub quote(n: Int) -> Int
  =
    let price = first of
      primary(n)
+     replica(n)
    price

Failing example

ita.unauna
ita demo
  version 0.1.0
  edition 0.4
ita.lockuna
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
src/demo.unauna
module demo

primary(n: Int) -> Int = n + 1

pub quote(n: Int) -> Int
=
  let price = first of
    primary(n)
  price

Fixed example

ita.unauna
ita demo
  version 0.1.0
  edition 0.4
ita.lockuna
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
src/demo.unauna
module demo

primary(n: Int) -> Int = n + 1

replica(n: Int) -> Int = n + 1

pub quote(n: Int) -> Int
=
  let price = first of
    primary(n)
    replica(n)
  price