Lyricdev
GitHub

LYR-SEM0113

an implicit member where no enum is expected

error · spec 03-types

An implicit member '.Name' or an implicit variant initializer '.Name { … }' stands where the position expects no particular type, a type that is no enum, or an enum without a variant of that name.

Explanation

.Red is short for a member of the type the position expects — the declared type of a binding or parameter, a return type, the other side of ==. Where nothing is expected (let s = .Red;) or what is expected is no enum, there is no type to look the member up in.

Name the enum (Signal.Red), or give the position a type (let s: Signal = .Red;).

Wrong

enum Signal { Red, Green }

fn main(): void {
    let s = .Red;
    let _ = s;
}
enum Signal { Red, Green }

fn main(): void {
    let s: Signal = .Red;
    let _ = s;
}