Lyricdev
GitHub

LYR-SEM0211

a conformance of another package's type to another package's interface

warning · spec 05-interfaces · lint foreign-conformance, group correctness, warn unless said

A conformance block is written for a type of another package to an interface of another package (std among them).

Explanation

A conformance holds for the whole program, and there is no rule that gives it to one package: two packages that both write the block for the same type and interface would both claim it.

Conform in the package of the type or of the interface — a wrapper type of your own conforms where it is declared.

Wrong

//- lyric.toml
[package]
name = "app"
version = "0.1.0"

[dependencies]
geo = { path = "deps/geo" }
//- deps/geo/lyric.toml
[package]
name = "geo"
version = "0.1.0"
//- deps/geo/src/lib.lyr
pub struct Point {
    pub x: int,
}
//- src/main.lyr
import geo { Point };
import std.io { println };

extend Point :: [Display] {
    fn show(): string {
        return f"({this.x})";
    }
}

fn main(): void {
    println(Point { x = 1 });
}
//- lyric.toml
[package]
name = "app"
version = "0.1.0"

[dependencies]
geo = { path = "deps/geo" }
//- deps/geo/lyric.toml
[package]
name = "geo"
version = "0.1.0"
//- deps/geo/src/lib.lyr
pub struct Point {
    pub x: int,
}
//- src/main.lyr
import geo { Point };
import std.io { println };

struct Shown :: [Display] {
    point: Point,

    fn show(): string {
        return f"({this.point.x})";
    }
}

fn main(): void {
    println(Shown { point = Point { x = 1 } });
}