Lyricdev
GitHub

LYR-SEM0117

the placeholder type '_' where nothing infers it

error · spec 03-types

The placeholder '_' is written as a type, or as a type argument outside a call or initializer that infers it — for example in the type of a binding.

Explanation

_ in a list of type arguments asks the compiler to infer that argument from the call or initializer it stands in: Pair<_, int> { first = 1, second = 2 }. A binding's type has nothing to infer from: it is written in full or omitted.

Write the type argument, or drop the annotation and let the initializer give the binding its type.

Wrong

struct Pair<A, B> { first: A, second: B }

fn main(): void {
    let p: Pair<_, int> = Pair<int, int> { first = 1, second = 2 };
    let _ = p.second;
}
struct Pair<A, B> { first: A, second: B }

fn main(): void {
    let p: Pair<int, int> = Pair<int, int> { first = 1, second = 2 };
    let _ = p.second;
}