Skip to content

var best = None passes check, then codegen fails: aggregate enum payload missing destination payload type #2103

Closed

Description

@ehartford

Repro (with v0.15.3.0, macOS arm64)

type Pick { score: i32 = 0 }

fn best_of(xs: &Vec[i32]) -> Option[Pick]:
    var best = None
    for x in xs:
        if x > 2: best = Some(Pick { score: x })
    best

fn main:
    var xs = Vec.new()
    xs.push(1)
    xs.push(5)
    match best_of(&xs):
        Some(p) => print(f"{p.score}")
        None => print("none")
$ with check optnone.w
ok
$ with run optnone.w
error: aggregate enum payload missing destination payload type fn=best_of variant=0
error: code generation failed

Expected

It prints 5. Sema infers best: Option[Pick] from the later Some(Pick {...}) assignment and the return type, which is why with check is clean, but code generation never receives the payload type for the None initializer. One stage accepts what the next can't lower (D65: one authoritative producer per semantic fact).

Writing var best: Option[Pick] = None works around it. WIPE keeps three such annotations (src/account.w, next_unlock and next_rank) until this is fixed. Found while removing redundant annotations from withlang-dev/wipe.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions