Lyricdev
GitHub

LYR-SEM0128

an associated type that is not answered or not declared

error · spec 05-interfaces

A conformance does not say what an interface's associated type is, or a type path or a fixation ('Iterator<Item = int>') names an associated type that the type, the interface or the bound does not declare.

Explanation

An interface with type Item; asks each conformer to answer it with type Item = …; (unless the interface gives a default). The other direction: T.Item, A.Iter.Count and I<Item = int> name an associated type, and only one the interface or the constraint declares can be named; an interface by itself (Source.Item) names the type of no conformer in particular.

Answer the associated type in the conforming type or block, or name one that the bound declares — constraining the type parameter by an interface that has it.

Wrong

interface Source {
    type Item;
    fn first(): Self.Item;
}

struct Ones :: [Source] {
    n: int,
    fn first(): int { return 1; }
}

fn main(): void {
}
interface Source {
    type Item;
    fn first(): Self.Item;
}

struct Ones :: [Source] {
    type Item = int;
    n: int,
    fn first(): int { return 1; }
}

fn main(): void {
    let _ = Ones { n = 0 }.first();
}