E4187

E4187#

Compiler diagnostic name: using_missing_keyword.

Missing keyword in a using alias.

When a using declaration imports a type or trait, the imported name must be prefixed with the corresponding keyword. This keeps type and trait aliases distinct from value aliases.

Erroneous example#

The following example imports the builtin Array type without the type keyword:

///|
using @builtin {Array}

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

///|
test {
  ignore(length)
}

MoonBit will report an error.

Suggestion#

Add type when importing a type, or trait when importing a trait:

///|
using @builtin {type Array}

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

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