Skip to content

monadic Result comprehension lowers Ok temps at the generic base type (aggregate rvalue missing destination struct type) #722

Closed

Description

@ehartford

6-line repro (seed passes; current D22-batch tree fails — in-batch regression, also breaks spec_ss13_6a):

fn main:
    let result: Result[i32, str] =
        for a in Ok(2); b in Ok(3):
            yield a + b
    assert(result.unwrap() == 5)
    print("ok")
error: aggregate rvalue missing destination struct type fn=main count=1 dest_sema=84 current_ret=void

MIR facts: the annotated binding result is the instantiated type (ty=333, Result[i32,str]) but the comprehension's intermediate temps are ty=84 — the UNINSTANTIATED generic base — so codegen's enum aggregate (CodegenDispatch.w:3566) has no concrete destination struct. The Ok(2)/Ok(3) iterables are being checked without the binding annotation's expectation reaching them, leaving the Err side unbound. Same unbound-Err family as the e == Ok(5) comparison fix in this batch (peer expectation was missing there too); the comprehension desugar needs the target type threaded into its iterable checks.

Tracked with the other two remaining spec-lane Class-B regressions (ss10_5 Option.cloned surface, ss13_3 wrong-value assert) — all three are seed-green.

Activity

  1. ehartford commented on Jul 26, 2026

    @ehartford
    ContributorAuthor

    Fixed in 6410a26. Root cause confirmed as the expectation-free "self-determined" subject check in check_match_expr: comprehension lowerings whose clause iterable is a bare variant construction (for a in Ok(2) under Result[i32, str]) never bound Result's Err side, so temps lowered at the uninstantiated generic base and codegen had no destination struct. Fix mirrors the batch's e == Ok(5) peer rule — a for-comprehension-lowered match subject that is a bare variant construction is typed against the present carrier expectation; every other match subject stays self-determined (the match if ok: Some(7) else: None guard case is untouched). Verified: the 6-line repro prints ok; spec_ss13_6a passes; err_default_op_type_mismatch and the comprehension carrier-mismatch diagnostics still fire.

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