---
title: "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"
url: https://una-lang.org/en/docs/errors/U2035/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/crates/una-explain/explain/U2035.md
---

# 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

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 a `when`.

`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 `tasks` statement, where nothing would wait for the task;
- inside a task within that block, a branch of `together` or `first of` or the body of a `together for`, or inside a lambda, since the task could then outlive what waits for it;
- with a `with` clause, since a `with` scopes 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`

```diff
  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.una`

```una
ita demo
  version 0.1.0
  edition 0.4
```

`ita.lock`

```una
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
```

`src/demo.una`

```una
module demo

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

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

## Fixed example

`ita.una`

```una
ita demo
  version 0.1.0
  edition 0.4
```

`ita.lock`

```una
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
```

`src/demo.una`

```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
```
