E4200#
Compiler diagnostic name: struct_constr_incorrect_return_type.
A struct constructor must return the struct type itself. If the constructor signature returns another type, the declaration cannot be used as that struct's constructor.
Erroneous example#
///|
priv struct Point {
x : Int
fn new(Int) -> String
}
Suggestion#
Make the constructor return the struct type and implement the matching
Type::new method.
///|
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")
}