E3023

E3023#

Compiler diagnostic name: invalid_grouped_impls.

无效的分组 impl 声明。

MoonBit 不使用 Rust 风格的分组 impl 块。每个 trait 实现或方法实现都写作单独的 impl ... with method(...) { ... } 声明。

错误示例#

下面的示例尝试将方法体放在 impl ... { ... } 块内部:

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

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

MoonBit 会报告一个错误。

建议#

将方法名和方法体移动到 impl 声明的 with 子句中:

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

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