E4187

E4187#

Compiler diagnostic name: using_missing_keyword.

using 别名中缺少关键字。

using 声明导入类型或 trait 时,被导入的名称必须带有对应的关键字前缀。这样可以将类型和 trait 别名与值别名区分开。

错误示例#

下面的示例导入内置的 Array 类型,但没有使用 type 关键字:

///|
using @builtin {Array}

///|
fn length(values : Array[Int]) -> Int {
  values.length()
}

///|
test {
  ignore(length)
}

MoonBit 会报告一个错误。

建议#

导入类型时添加 type,导入 trait 时添加 trait

///|
using @builtin {type Array}

///|
fn length(values : Array[Int]) -> Int {
  values.length()
}

///|
test {
  inspect(length([1, 2]), content="2")
}