E1048: pattern does not fit the subject

View source

Every pattern of a case must fit the subject.

Every pattern of a case must fit the subject. A variant pattern must name a variant of the subject's own enum, and its payload must have the shape that the variant declares. A literal pattern must have the subject's type, so a Bool literal does not match an Int, an integer literal does not match a Bool, and an integer literal must fit the subject's integer type. The message names the expected and the found type. For a payload that has the wrong shape, it shows the pattern the variant declares and the pattern that was written, such as Shape.Circle(_) and Shape.Circle. The error points at the pattern.

Example

actus
enum Color {
    Red,
    Green,
}

enum Size {
    Big,
    Small,
}

verb name(abs c: Color) -> Int {
    return case c {
        Size.Big => 1,
        Color.Green => 2,
        Color.Red => 3,
    };
}

verb main() {
}
actus
verb name(abs v: u8) -> Int {
    return case v {
        300 => 1,
        _ => 0,
    };
}

verb main() {
}
actus
verb name(abs v: Int) -> Int {
    return case v {
        3000000000 => 1,
        _ => 0,
    };
}

verb main() {
}
actus
verb name(abs flag: Bool) -> Int {
    return case flag {
        1 => 1,
        _ => 0,
    };
}

verb main() {
}

Fix

Match with patterns of the subject's own type, and with literals that fit it.

actus
enum Color {
    Red,
    Green,
}

verb name(abs c: Color) -> Int {
    return case c {
        Color.Red => 1,
        Color.Green => 2,
    };
}

verb main() {
}
actus
verb name(abs v: u8) -> Int {
    return case v {
        200 => 1,
        _ => 0,
    };
}

verb main() {
}

Run actus explain E1048 in your terminal to read this entry offline. Browse Ownership & types or all error codes.