Lyricdev
GitHub

LYR-SEM0043

one member defaulted by two interfaces

error ยท spec 05-interfaces

A type conforms to two interfaces that both provide a default for a member of one name, and the type implements the member itself nowhere.

Explanation

A type has one function of a name. When two of its interfaces each bring a default, neither is preferred: the type decides by writing the member, which then serves both interfaces.

Implement the member on the type.

Wrong

interface A { fn tag(): int { return 1; } }
interface B { fn tag(): int { return 2; } }

struct V :: [A, B] { x: int }

fn main(): void {
    let _ = V { x = 0 }.x;
}
interface A { fn tag(): int { return 1; } }
interface B { fn tag(): int { return 2; } }

struct V :: [A, B] {
    x: int,
    fn tag(): int { return 3; }
}

fn main(): void {
    let _ = V { x = 0 }.x;
}