E4143

E4143#

Not a valid constant type, only immutable primitive types are allowed.

In MoonBit, you can use const to declare a constant value. Only literal value of immutable primitive types can be assigned to const.

  • These are valid constant types: Int, String, Byte, Char, Float, Bool, etc.

  • These are not valid constant types: Array[Int], (Int) -> Int, Ref[Int], etc.

错误示例#

const A : Array[Int] = [1, 2, 3] // Error: Not a valid constant type, only immutable primitive types are allowed.

建议#

You can bind the value to a variable using let instead.

let a : Array[Int] = [1, 2, 3]