E1047: pattern repeated in a case

View source

Two branches of one case have the same pattern.

Two branches of one case have the same pattern. The second one can never run, because the first one always matches first. Most often one of them was meant to be another variant or value. The message shows the pattern, and the error points at the second branch. Repeating a field name inside one pattern is the same error.

Example

actus
enum Color {
    Red,
    Green,
}

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

verb main() {
}

Fix

Remove the repeated branch, or change it to the pattern it was meant to be.

actus check --format json offers this as a fix: remove the repeated arm, with its trailing comma and the line break before it (a review fix, because it deletes code).

actus
enum Color {
    Red,
    Green,
}

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

verb main() {
}

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