Sisu
E0124

match on a type it cannot take

Error

Built from the repository at commit a8614dc.

match takes an enum, an optional, an integer, a bool, a char or a string. A class, an array or an f64 is not one of them.

Why

A pattern names a variant or a value that the program can compare exactly. A class has no variants, and an f64 does not compare exactly. Read the class's fields.

Broken

class Point {
    x: i64
    y: i64
}

fn main() {
    let p = Point(x: 1, y: 2)
    let n = match p {
        _ => 0
    }
    print(n)
}

What sisu says

error[E0124]: cannot `match` on `Point`
 --> E0124.sisu:8:19
  |
8 |     let n = match p {
  |                   ^
  |
  = help: `match` takes enums, optionals, integers, `bool`, `char` and `string`

sisu: 1 error
sisu: for more on a code, run `sisu explain <code>`: E0124

Fixed

class Point {
    x: i64
    y: i64
}

fn main() {
    let p = Point(x: 1, y: 2)
    let n = match p.x {
        1 => p.y
        _ => 0
    }
    print(n)
}