Lyricdev
GitHub

LYR-SEM0167

an implementing member is less visible than its conformance

error · spec 04-modules

A method or constant that implements an interface member for a type is written with a visibility narrower than the conformance, which is as visible as the narrower of the type and the interface.

Explanation

A conformance is visible wherever both the type and the interface are, and through it any code there may call the member as Shape.area. A member written narrower — a private fn area in a package-wide conformance — would then be called where its own name is refused.

Write the member with the conformance's visibility: no word or internal for an internal conformance, pub for a public one.

Wrong

pub interface Shape {
    fn area(): int;
}

struct Square :: [Shape] {
    s: int,
    private fn area(): int {
        return this.s * this.s;
    }
}

fn main(): void {
    let _ = Square { s = 2 }.area();
}
pub interface Shape {
    fn area(): int;
}

struct Square :: [Shape] {
    s: int,
    fn area(): int {
        return this.s * this.s;
    }
}

fn main(): void {
    let _ = Square { s = 2 }.area();
}