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).
Eqtakes every type whose values hold no functions.OrdtakesInt, the fixed-width integer types,Textand sums whose variants have no payload.IntegertakesIntand the fixed-width integer types.
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
- Pass a value of a type that satisfies the constraint.
- Or compare by a field that does.
The repair at a glance
src/demo.una
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.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"src/demo.una
module demo
pub kind Box
size: Int
pub largest(a: Box, b: Box) -> Box = max(a, b: b)Fixed example
una.toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.2"src/demo.una
module demo
pub kind Box
size: Int
pub largest(a: Box, b: Box) -> Int = max(a.size, b: b.size)