E4200#
编译器诊断名称:struct_constr_incorrect_return_type。
结构体构造器必须返回结构体自身的类型。如果构造器签名返回其他类型,这个声明就不能作为该结构体的构造器使用。
错误示例#
///|
priv struct Point {
x : Int
fn new(Int) -> String
}
建议#
让构造器返回结构体类型,并实现匹配的 Type::new 方法。
///|
priv struct Point {
x : Int
fn new(Int) -> Point
}
///|
fn Point::new(x : Int) -> Point {
{ x, }
}
///|
test {
let point = Point(1)
inspect(point.x, content="1")
}