E4007#
When constructing an enum, the arguments passed to the constructor cannot be unit
()
. MoonBit does not allow constructors to take unit as an argument because it
would be redundant - a constructor without arguments already represents a
singleton value.
错误示例#
enum Status {
Done
Pending
}
fn main {
let status = Done() // Error: constructor can't take unit as argument
}
建议#
Remove the unit argument from the constructor since it adds no value:
// ...
fn main {
let status = Done
}
If you really need the constructor to take a unit arguments, explicitly use
Unit
as its argument
enum Status {
Done(Unit)
Pending
}
fn main {
let status = Done(())
}