E4197#
Compiler diagnostic name: cannot_match_struct_constr.
A constructor declared by a struct is a constructor function, not a pattern
constructor. It can be called to create a value, but it cannot be used in a
match pattern.
Erroneous example#
///|
priv struct Point {
x : Int
fn new(Int) -> Point
}
///|
fn Point::new(x : Int) -> Point {
{ x, }
}
///|
fn read(point : Point) -> Int {
match point {
Point(x) => x
}
}
///|
test {
let _ = read(Point(1))
}
Suggestion#
Read the struct fields directly, or use another pattern that does not call the constructor function.
///|
priv struct Point {
x : Int
fn new(Int) -> Point
}
///|
fn Point::new(x : Int) -> Point {
{ x, }
}
///|
fn read(point : Point) -> Int {
point.x
}
///|
test {
inspect(read(Point(3)), content="3")
}