Skip to content

Inferless enum-variant shorthand in a discard binding crashes codegen instead of a sema diagnostic #694

Closed

Description

@ehartford

Found by tools/drop_audit.w (discard/option cell). Minimal repro:

fn main:
    let _ = .Some(5)
    print("ok")

with build → error: aggregate rvalue missing destination struct type fn=main count=1 dest_sema=42 current_ret=void / code generation failed.

The .Variant shorthand has no expected type here, so sema should reject it with a clean "cannot infer enum type for .Some" diagnostic; instead it passes sema and codegen dies on the missing destination. Error-quality/robustness, not soundness. (Annotated forms let _: Option[i32] = .Some(5) and ordinary bindings work fine.)

Activity

  1. ehartford commented on Sep 1, 2026

    @ehartford
    ContributorAuthor

    Fixed (two commits): the variant_lookup fallback returned a GENERIC enum's template tid as an expression type — codegen has no layout for it, so let _ = .Some(5) crashed on aggregate lowering and let x = .Some(5) + match died on invalid MIR (worse than filed — the ordinary-binding form had regressed to a crash too). An unknown payload-carrying variant (.Missing(5)) crashed as well.

    Now: a generic template resolved without an expected type errors 'cannot infer the enum type for .Some' with an annotate-the-binding help; an unknown PAYLOAD-CARRYING variant errors 'no enum in scope has a variant'. Bare shorthands keep the silent deferred-completion path (the comprehension _Empty marker and bare None ahead of their expected type are completed by a later pass — the first suite run caught exactly that on spec_ss13_6a). Annotated forms and non-generic user-enum shorthands unchanged. Full :test green.

    Possible ergonomics follow-up (not smuggled into the crash fix): payload-driven instantiation — .Some(5) could infer Option[i32] from the argument and remove the annotation entirely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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