Lyricdev
GitHub

LYR-SEM0060

a type argument nothing determines

error ยท spec 03-types

A generic call leaves a type argument that neither the arguments nor the expected type determine, or an empty [] stands where nothing gives it an element type.

Explanation

Type arguments are inferred from the arguments of a call and from the type the position expects. When neither mentions a type parameter, there is nothing to infer it from; the same holds for [], which has no element type of its own.

Write the type argument (empty<int>()), give the binding a type (let xs: int[] = empty();), or give the empty literal one (let none: int[] = [];).

Wrong

fn empty<T>(): T[] {
    return [];
}

fn main(): void {
    let xs = empty();
    let _ = xs.length();
}
fn empty<T>(): T[] {
    return [];
}

fn main(): void {
    let xs = empty<int>();
    let _ = xs.length();
}