Lyricdev
GitHub

LYR-SEM0050

a match that does not cover every value

error ยท spec 09-patterns

The arms of a match leave values of the scrutinee's type unmatched: a variant, null, a conformer of a sealed interface, a length class of an array, or the rest of an open type. The message names a missing pattern. Guarded arms do not count.

Explanation

A match is exhaustive: whatever value comes in, one arm takes it. For an enum every variant is covered, for an optional also null; types with unbounded values (numbers, strings, open interfaces) need a _ or binding arm. An arm with a guard may not match, so it covers nothing. An enum marked @NonExhaustive needs a _ arm outside its package, since later versions may add variants.

Add arms for the missing values, or a _ arm.

Wrong

enum Shape { Num(int), Rect { w: int, h: int }, Empty }

fn size(s: Shape): int {
    return match (s) {
        .Num(n) => n,
        .Empty => 0,
    };
}

fn main(): void {
    let _ = size(Shape.Empty);
}
enum Shape { Num(int), Rect { w: int, h: int }, Empty }

fn size(s: Shape): int {
    return match (s) {
        .Num(n) => n,
        .Rect { w, h } => w * h,
        .Empty => 0,
    };
}

fn main(): void {
    let _ = size(Shape.Empty);
}