---
title: "U2017: Use of a binding after it was passed by `take`"
url: https://una-lang.org/en/docs/errors/U2017/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/crates/una-explain/explain/U2017.md
---

# U2017: Use of a binding after it was passed by `take`

The code uses a binding after it was passed by `take`.

## Why Una rejects it

In edition 0.2, a parameter declared `take` consumes its argument, and the caller writes `take a` (`spec/17 §3`). After `take a`, every use of `a` is U2017, until an assignment gives `a` a new value. Only a `let edit` binding can be reassigned.

A binding taken in one branch of an `if` or a `when` counts as taken after the construct.

## How to fix it

- Use the value before passing it.
- Keep a copy of what you need.
- Assign the binding again.

## The repair at a glance

`src/demo.una`

```diff
  module demo

  pub drain(take items: List[Int]) -> Int = items.len

  pub count() -> Int
  =
    let items = [1, 2, 3]
+   let size = items.len
    let n = drain(take items)
-   n + items.len
+   n + size
```

## Failing example

`una.toml`

```toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"
```

`src/demo.una`

```una
module demo

pub drain(take items: List[Int]) -> Int = items.len

pub count() -> Int
=
  let items = [1, 2, 3]
  let n = drain(take items)
  n + items.len
```

## Fixed example

`una.toml`

```toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"
```

`src/demo.una`

```una
module demo

pub drain(take items: List[Int]) -> Int = items.len

pub count() -> Int
=
  let items = [1, 2, 3]
  let size = items.len
  let n = drain(take items)
  n + size
```
