E4200#
编译器诊断名称:struct_constr_incorrect_return_type。
结构体构造器必须返回结构体自身的类型。如果构造器签名返回其他类型,这个声明就不能作为该结构体的构造器使用。
错误示例#
///|
priv struct Point {
x : Int
}
///|
fn Point::Point(_: Int) -> String {
""
}
建议#
Make the constructor return the struct type and implement the matching
Type::Type function.
///|
priv struct Point {
x : Int
}
///|
fn Point::Point(x : Int) -> Point {
{ x, }
}
///|
test {
let point = Point(1)
inspect(point.x, content="1")
}