E4213

E4213#

Compiler diagnostic name: constr_for_non_struct.

Constructor methods can only be defined for struct types.

MoonBit's Type::Type constructor mechanism belongs to structs. Enums, newtypes, and other type forms already have their own construction syntax, so a constructor method for those types is rejected.

Erroneous example#

pub enum Status {
  Ready
}

pub fn Status::Status() -> Status {
  Ready
}

Status is an enum, not a struct, so Status::Status cannot be used as a struct constructor.

Suggestion#

Use the enum constructor directly, or change the type to a struct if you need a custom constructor method.

pub struct Status {}

pub fn Status::Status() -> Status {
  Status::{  }
}