E3023

E3023#

Compiler diagnostic name: invalid_grouped_impls.

Invalid grouped impl declaration.

MoonBit does not use Rust-style grouped impl blocks. Each trait implementation or method implementation is written as a single impl ... with method(...) { ... } declaration.

Erroneous example#

The following example tries to put a method body inside an impl ... { ... } block:

///|
pub trait Named {
  name(Self) -> String
}

///|
pub impl Named for Int {
  name(_self) { "user" }
}

MoonBit will report an error.

Suggestion#

Move the method name and body into the with clause of the impl declaration:

///|
pub trait Named {
  name(Self) -> String
}

///|
pub impl Named for Int with name(_self) { "user" }