---
title: "U3016: Second-class type used as a type argument"
url: https://una-lang.org/en/docs/errors/U3016/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/crates/una-explain/explain/U3016.md
---

# U3016: Second-class type used as a type argument

A function type with `uses` or `fails` instantiates a type parameter. U3016 points at the written type argument, or at the value whose type instantiates the type parameter.

## Why Una rejects it

A function type with `uses` or `fails` is second-class (`spec/05 §6`, ADR 0038 D2). It may be the type of a parameter, so an effectful or failing function can be passed directly as a call argument and called there. But it can never instantiate a type parameter:

- not as a written type argument, such as `List[fn() -> Unit uses @log: Log[write]]` or `Option[fn(Int) -> Int fails Boom]`;
- not by inference, such as `id(note)` for a generic `id[T](x: T) -> T` and a function `note` with `uses`.

A value of type `T` can be bound, stored or returned, so a second-class type in its place would carry authority out of the `with` scope where it was created.

## How to fix it

Pass the function directly to the function that calls it, with a parameter of function type.

## The repair at a glance

```diff
  module demo

  capability Log
    op write(line: Text) -> Unit

- id[T](x: T) -> T = x
-
  note(line: Text) -> Unit
    uses @log: Log[write]
  =
    @log.write(line)

  run(write: fn(Text) -> Unit uses @log: Log[write]) -> Unit
    uses @log: Log[write]
  =
    write("hello")

  pub main() -> Unit
    uses @log: Log[write]
  =
-   run(id(note))
+   run(note)
```

## Failing example

```una
module demo

capability Log
  op write(line: Text) -> Unit

id[T](x: T) -> T = x

note(line: Text) -> Unit
  uses @log: Log[write]
=
  @log.write(line)

run(write: fn(Text) -> Unit uses @log: Log[write]) -> Unit
  uses @log: Log[write]
=
  write("hello")

pub main() -> Unit
  uses @log: Log[write]
=
  run(id(note))
```

## Fixed example

```una
module demo

capability Log
  op write(line: Text) -> Unit

note(line: Text) -> Unit
  uses @log: Log[write]
=
  @log.write(line)

run(write: fn(Text) -> Unit uses @log: Log[write]) -> Unit
  uses @log: Log[write]
=
  write("hello")

pub main() -> Unit
  uses @log: Log[write]
=
  run(note)
```
