Home / Docs / Diagnostics

U2025: A type argument does not satisfy the constraint of its parameter

Release v0.4.0

A type argument does not satisfy the constraint of its type parameter.

Why Una rejects it

A type parameter written with a constraint, as T: Ord, can only be instantiated with a type that satisfies it (spec/20 §1, §3 rule 3).

A type parameter of the caller satisfies the constraint written on it, so a generic caller writes the constraint its callees need.

How to fix it

The repair at a glance

src/demo.unadiff
  module demo

  pub kind Box
    size: Int

- pub largest(a: Box, b: Box) -> Box = max(a, b: b)
+ pub largest(a: Box, b: Box) -> Int = max(a.size, b: b.size)

Failing example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"
src/demo.unauna
module demo

pub kind Box
  size: Int

pub largest(a: Box, b: Box) -> Box = max(a, b: b)

Fixed example

una.tomltoml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"
src/demo.unauna
module demo

pub kind Box
  size: Int

pub largest(a: Box, b: Box) -> Int = max(a.size, b: b.size)