Lyricdev
GitHub

LYR-SEM0133

two conformances of one type to one interface

error ยท spec 05-interfaces

A type conforms to the same interface twice in the whole program: in two blocks, in its own list and a block, or through a blanket block that reaches a type which also conforms on its own or through another block.

Explanation

There is one conformance per type and interface in the whole program, and no specialization: a more specific block does not override a general one. With two, a call through the interface would have two implementations to choose between, and which one wins would depend on what is imported.

Keep one conformance; narrow a blanket block's constraints so they exclude the type that conforms on its own.

Wrong

interface Named { fn name(): string; }

struct Dog { n: int }

extend Dog :: [Named] { fn name(): string { return "dog"; } }
extend Dog :: [Named] { fn name(): string { return "hound"; } }

fn main(): void {
}
interface Named { fn name(): string; }

struct Dog { n: int }

extend Dog :: [Named] { fn name(): string { return "dog"; } }

fn main(): void {
    let _ = Dog { n = 0 }.name();
}