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:
- when the body has fewer than two branches, since there is nothing to race;
- when a line of the body is not an expression, such as a
let, a loop or awhen.
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:
- outside the block of a
tasksstatement, where nothing would wait for the task; - inside a task within that block, a branch of
togetherorfirst ofor the body of atogether for, or inside a lambda, since the task could then outlive what waits for it; - with a
withclause, since awithscopes over its statement and the task outlives the statement.
How to fix it
For first of:
- With one branch, write the expression alone.
- For more steps in a branch, put them in a function and call it from the branch.
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.una
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)
priceFailing example
ita.una
ita demo
version 0.1.0
edition 0.4ita.lock
lock 1
solver
encoding "una-smt-1"
name "z3"
version "5.1.0"
logic "QF_UFLIA"
steps 5000000
seed 0src/demo.una
module demo
primary(n: Int) -> Int = n + 1
pub quote(n: Int) -> Int
=
let price = first of
primary(n)
priceFixed example
ita.una
ita demo
version 0.1.0
edition 0.4ita.lock
lock 1
solver
encoding "una-smt-1"
name "z3"
version "5.1.0"
logic "QF_UFLIA"
steps 5000000
seed 0src/demo.una
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