Home / Docs / Diagnostics

U2026: An operation on a type parameter that its constraint does not allow

Release v0.4.0

On values of a type parameter, == and != need the constraint Eq, the orderings <, <=, > and >= need Ord, and x.to_int() needs Integer (spec/20 §3). A public function writes the constraint on the parameter, as [T: Ord]; a private one gets it inferred when none is written. Arithmetic is never defined on a type parameter: convert with to_int() under Integer (spec/20 §1 rule 6).

The repair at a glance

src/demo.unadiff
  module demo

- pub same[T](a: T, b: T) -> Bool = a == b
+ pub same[T: Eq](a: T, b: T) -> Bool = a == b

Failing example

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

pub same[T](a: T, b: T) -> Bool = a == b

Fixed example

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

pub same[T: Eq](a: T, b: T) -> Bool = a == b