Lyricdev
GitHub

LYR-SEM0028

a type argument that does not satisfy its constraint

error · spec 05-interfaces

A type argument, written or inferred, does not conform to an interface its type parameter is constrained by.

Explanation

fn f<T :: [Show]>(…) accepts only types that conform to Show. The check runs where the generic is instantiated — at a call, a type written Cell<X>, or a function value f<X>.

Pass a type that conforms, or give the type the conformance (struct Count :: [Show] { … }).

Wrong

interface Show { fn show(): string; }
struct Count { n: int }

fn shown<T :: [Show]>(x: T): T { return x; }

fn main(): void {
    let _ = shown(Count { n = 1 });
}
interface Show { fn show(): string; }
struct Count :: [Show] {
    n: int,
    fn show(): string { return "num"; }
}

fn shown<T :: [Show]>(x: T): T { return x; }

fn main(): void {
    let _ = shown(Count { n = 1 });
}