LYR-SEM0082
a member replacing a generic default of a generic interface
A conformer declares its own version of a generic method that a generic interface provides as a default.
Explanation
A generic method has no slot in a method table, and a default of a generic interface that calls it on this would reach the interface's version, not the conformer's. Until that is possible, a conformer may not stand in place of such a default.
Give the conformer's method another name.
Wrong
interface Source<T> {
fn get(): T;
fn pick<U>(u: U): U { return u; }
}
struct G :: [Source<int>] {
n: int,
fn get(): int { return this.n; }
fn pick<U>(u: U): U { return u; }
}
fn main(): void {
let _ = G { n = 1 }.get();
}
Right
interface Source<T> {
fn get(): T;
fn pick<U>(u: U): U { return u; }
}
struct G :: [Source<int>] {
n: int,
fn get(): int { return this.n; }
fn choose<U>(u: U): U { return u; }
}
fn main(): void {
let _ = G { n = 1 }.get();
}