Skip to content

Sema/MIR: let Ok(x) = … else: return 1 in fn main: (inferred return) fails the MIR validator at the return; -> i32 spelled explicitly compiles #1623

Closed

Description

@ehartford

Found by the ruling §66 example rewrite. A let-else whose else branch is return 1 does not make an unannotated fn main: return i32 the way an if …: return 1 does; the tail print is then Unit and the validator refuses the return:

fn make(ok: bool) -> Result[Vec[i32], i32]: if ok: Ok(Vec.new()) else: Err(1)
fn main:
    let Ok(v) = make(true) else:
        print("failed")
        return 1
    print("pure")
error: invalid MIR before codegen: use rvalue type is incompatible with assign destination (dest ty=14 kind=4, src ty=3 kind=1)
 --> letelse_pure.w:5:9
5 |         return 1
  • fn main -> i32: → compiles, prints pure.
  • The same program with a later if cond: return 1 (so a non-let-else return establishes i32) → compiles (this is why the sqlite3 UAT fixture, which has both, is fine).
  • Using v after the binding changes nothing.

So the D43 return-type inference does not see a return inside a let-else's diverging block; D58's let-else should count like any other statement's return. Stage1 of c18fdfe.

Activity

  1. ehartford commented on Sep 26, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by #1702 (55739d4); battery green, pinned by the behavior tests named in the PR.

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