E4074#
This error code is generated when a toplevel declaration is missing a necessary type annotation. MoonBit requires toplevel variables and functions to have fully annotated types, because types are important documentation for toplevel definitions.
There are two exceptions to this rule:
if the value of a toplevel
letis just a simple literal value, type annotation can be omitted:pub let forty_two = 42 pub let float = 1.0 pub let string = "Hello, world!" pub let array = [1, 2, 3]
if the value is a private alias of a foreign value. In this case, the type can be easily inferred. However, for public
let, MoonBit still requires annotation for documentation sake.
Erroneous example#
///|
let a = 1 + 1 // Error: Cannot infer the type of variable a, please add more type annotation.
Suggestion#
This error can be fixed by explicitly annotating the type of the variable:
///|
pub let a : Int = 1 + 1