Lyricdev
GitHub

LYR-PAR0060

a local function that is not one plain closure

error ยท spec 03-types

A fn declared inside a function body has type parameters, a parameter with a default value or a variadic parameter, or has no body.

Explanation

A local function is a named closure: one function value, capturing as a lambda does. Type parameters would make it one function per type, which a closure is not; defaults and variadic parameters belong to declared functions. It needs a body, since nothing else could give it one.

Move the function to module level, or drop the type parameters, the default or the variadic parameter.

Wrong

fn main(): void {
    fn id<T>(x: T): T {
        return x;
    }
}
fn main(): void {
    fn id(x: int): int {
        return x;
    }
    let _ = id(1);
}