Lyricdev
GitHub

LYR-PAR0066

several interfaces after '::' without brackets

error · spec 05-interfaces

Several interfaces follow :: — of a struct, class, enum, interface or extend block, or of an associated type's bound — without brackets around them. One interface stands without them, several in them.

Explanation

After :: one interface may stand alone, struct User :: Named, and several stand in brackets, struct User :: [Named, Shown] — the list rule, the same as for throws and catch. Without the brackets the , after the first would leave it open what the list holds.

Put the interfaces in brackets. In a type parameter's constraint a , after one interface begins the next parameter: <T :: Named, U> has the parameters T and U; <T :: [Named, Shown]> constrains T twice.

Wrong

interface Named {
    fn name(): string;
}

interface Shown {
    fn show(): string;
}

struct User :: Named, Shown {
    fn name(): string { return "u"; }
    fn show(): string { return "U"; }
}

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

interface Shown {
    fn show(): string;
}

struct User :: [Named, Shown] {
    fn name(): string { return "u"; }
    fn show(): string { return "U"; }
}

fn main(): void {
    let u = User { };
    let _ = u.name() + u.show();
}