Lyricdev
GitHub

LYR-SEM0150

a visibility word on a conformance or its methods

error · spec 04-modules

An 'extend … :: [Interface]' block carries 'pub', 'internal' or 'private', or one of its methods does.

Explanation

A conformance is visible wherever both its type and its interface are: two conformances of one type to Hashable, one hidden in a package, would give one Set two hash functions. So a conformance block takes no visibility word, and its methods are as visible as the conformance. An inherent extend block (without an interface) keeps its word, which is the default for its methods.

Drop the word.

Wrong

interface Shape { fn area(): int; }

struct Square { side: int }

private extend Square :: [Shape] {
    fn area(): int { return this.side * this.side; }
}

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

struct Square { side: int }

extend Square :: [Shape] {
    fn area(): int { return this.side * this.side; }
}

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