E3024#
Legacy constructor functions declared inside a struct must have name new.
当在 struct 内声明的构造函数没有命名为 new 时,会发生此错误。MoonBit 将 new 视为该结构体的构造入口。
错误示例#
pub struct S {
x : Int
fn constr(x : Int) -> S
}
fn S::constr(x : Int) -> S {
{ x, }
}
建议#
Define the constructor with the current top-level Type::Type form:
pub struct S {
x : Int
}
fn S::S(x : Int) -> S {
{ x, }
}
pub fn make(x : Int) -> S {
S(x)
}