error bad-init
What it means#
A named constructor init name(params) -> Self | E is an associated function whose return type MUST be Self or a union that contains Self (§4.3). Errors may be added to the union; other result types are not constructors.
Example#
data Account { id: u64 }
impl Account {
init open(id: u64) -> u64 => id // <- bad-init
}error
bad-init
How to fix#
data Account { id: u64 }
impl Account {
init open(id: u64) -> Self => Self{ id }
}Return Self (or Self | SomeError). If the function is not a constructor, declare it with static fn instead.