Lyricdev
GitHub

LYR-SEM0231

a static member of an interface called through the interface

error ยท spec 05-interfaces

A static member of an interface is called on the interface's name, Make.make<Item>(s): the interface has no value to call it for.

Explanation

A static member of an interface is answered by each type that conforms, and is called for one of them: on the type, Item.make(s), or in generic code through a type parameter the interface bounds, T.make(s) in fn build<T :: [Make]>(s: string): T. The interface's name says which member, never which type's answer, and a type argument written after it does not make it one.

Call it on the type, or write the generic function.

Wrong

interface Make {
    static fn make(s: string): Self;
}

struct Item :: [Make] {
    name: string,

    static fn make(s: string): Item {
        return Item { name = s };
    }
}

fn main(): void {
    let _ = Make.make<Item>("x");
}
interface Make {
    static fn make(s: string): Self;
}

struct Item :: [Make] {
    name: string,

    static fn make(s: string): Item {
        return Item { name = s };
    }
}

fn build<T :: [Make]>(s: string): T {
    return T.make(s);
}

fn main(): void {
    let _ = Item.make("x");
    let _: Item = build("y");
}