Skip to content

Enum-variant construction (Some(x)) as an operator operand has no codegen destination type #634

Closed

Description

@ehartford

Summary

Constructing an enum variant inline as an operand of a binary/default operator — opt == Some(2), Some(5) ?? rhs — fails codegen: 'aggregate rvalue missing destination struct type fn=main count=1'. Binding it first with an annotation works: let s: Option[i32] = Some(2) then compare/use.

Repro

fn main:
    let r: Option[i32] = Some(2)
    if r == Some(2):        // error: aggregate rvalue missing destination struct type
        print("eq")

Also (Some(5) ?? boom()).

Spec §4.4 / §4.3c

Expected-type-driven enum-variant construction. Sibling of #566/#586 (both fixed via MirLower expected_type threading, commit e9956f2) but in a different context: the comparison/default-operator operand position doesn't thread the expected type into the Some(...) aggregate. Candidate: check_binary/check_default_op operand expected-type propagation → MirLower aggregate dest.

Found

Coverage sweep #515/#493, 2026-07-03. Worked around in those fixtures via match/bound-locals.

Activity

  1. ehartford commented on Jul 14, 2026

    @ehartford
    ContributorAuthor

    Fixed in 058f38c. lower_bin_op lowered a comparison's operand with the ambient expected type (bool for if a == b:), so an enum-variant-constructor operand like Some(2) in r == Some(2) built its aggregate with the comparison's type — 'aggregate rvalue missing destination struct type'. Fix: for EQ/NEQ/LT/GT/LTE/GTE, lower each operand with the OTHER operand's type as expected (generalizing the #586 bare-None rebind). Verified across Option/Result and both operand orders; plain scalar comparisons unaffected. Full gate green.

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