E4197#
编译器诊断名称:cannot_match_struct_constr。
A struct constructor is a function, not a pattern constructor. It can be called
to create a value, but it cannot be used in a match pattern.
错误示例#
///|
priv struct Point {
x : Int
}
///|
fn Point::Point(x : Int) -> Point {
{ x, }
}
///|
fn read(point : Point) -> Int {
match point {
Point(x) => x
}
}
///|
test {
let _ = read(Point(1))
}
建议#
直接读取结构体字段,或使用另一种不会调用构造函数的模式。
///|
priv struct Point {
x : Int
}
///|
fn Point::Point(x : Int) -> Point {
{ x, }
}
///|
fn read(point : Point) -> Int {
point.x
}
///|
test {
inspect(read(Point(3)), content="3")
}