Lyricdev
GitHub

LYR-SEM0042

an implementation that does not match the interface's signature

error · spec 05-interfaces

A method or static that implements an interface member differs from the member's declaration: in parameters, return type, mut, static, place parameters, the errors it throws, or the answer it gives an associated type the interface fixes.

Explanation

An implementation stands in for the interface's member wherever the interface is used, so it has the member's signature as the interface reads it for the conforming type — Self and associated types replaced by their answers. It may throw less than the member declares, never more.

Write the implementation with the signature the interface declares.

Wrong

interface Sized { fn size(): int; }

struct Tag :: [Sized] {
    fn size(): string { return "one"; }
}

fn main(): void {
    let _ = Tag { }.size();
}
interface Sized { fn size(): int; }

struct Tag :: [Sized] {
    fn size(): int { return 1; }
}

fn main(): void {
    let _ = Tag { }.size();
}