LYR-SEM0134
a member of a constrained block on a type that fails its constraints
A member added by a generic extend block ('extend<T :: [Display]> Slice
Explanation
A generic block adds its members only to the instances its constraints admit: shown() above exists on Slice<int>, whose element is Display, but not on a slice of a type that is not. An array reaches the members of its view's blocks under the same constraints.
Make the element type conform to the constraint, or call the member on an instance that satisfies it.
Wrong
struct Opaque { n: int }
extend<T :: [Display]> Slice<T> {
fn shown(): string { return f"{this[0]}"; }
}
fn main(): void {
let xs = [Opaque { n = 1 }];
let _ = xs.shown();
}
Right
extend<T :: [Display]> Slice<T> {
fn shown(): string { return f"{this[0]}"; }
}
fn main(): void {
let xs = [1, 2];
let _ = xs.shown();
}