E3024

E3024#

Legacy constructor functions declared inside a struct must have name new.

This error happens when a constructor function declared inside a struct is not named new. MoonBit treats new as the constructor entry point for the struct.

Erroneous example#

pub struct S {
  x : Int
  fn constr(x : Int) -> S
}

fn S::constr(x : Int) -> S {
  { x, }
}

Suggestion#

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)
}