E1022#
Ambiguous block expression. In MoonBit, the expression { value }
is ambiguous
because it could be interpreted as a block expression or a struct literal. For
now, we treat it as a struct literal, but writing such expressions is
discouraged.
Erroneous example#
struct S {
value : Int
}
fn main {
let value = 3
let s = { value }
ignore(s)
}
Suggestion#
If you want to construct a struct using the struct literal, you can add a comma to the end of the struct literal. Or you can call formatter on this buffer to have the comma added automatically.
fn main {
let value = 3
let s = { value, }
ignore(s)
}
If you are using it as a block expression, please remove the braces as it has
only one expression and is equivalent to the expression value
:
fn main {
let value = 3
let s = value
ignore(s)
}