Lyricdev
GitHub

LYR-PAR0025

something else than a declaration at module level

error · spec 02-grammar

At the top level of a file stands a token that begins no declaration — a statement, an expression, a stray brace. The parser skips to the next declaration.

Explanation

A file holds imports and declarations: functions, types, interfaces, extend blocks, let and var bindings, type aliases. Statements stand in a function's body.

Move the statement into a function, or remove it.

Wrong

return 1;

fn main(): void {
}
fn one(): int {
    return 1;
}

fn main(): void {
    let _ = one();
}