Skip to content

Unannotated Ok/Err join (if or match) types the binding 0; check passes, MIR aborts #1856

Closed

Description

@ehartford

Spec

§9.7 / §21.1 contextual joins: an if/match whose arms are Ok(a) and Err(b) has one type, Result[A, B].

Repro

fn pick(c: bool, s: str):
    let r = if c: Ok(s.len()) else: Err("e" ++ "")
    print(f"{r:?}")
fn main:
    pick(true, "ab")

and the match spelling:

fn pick(s: str):
    let q: Result[str, str] = Ok(s ++ "")
    let n = match q:
        Ok(x) => Ok(x.len())
        Err(e) => Err(e)
    print(f"{n:?}")

Actual (main 355c20b)

with check: ok. with run:

BUG: `:?` reached MIR for type 0 with no registered formatter (D61) [src/MirLower.w:3401 MirBuilder.lower_debug_write_place]

The binding's type is 0: Ok(a) alone is Result[A, ?], Err(b) alone Result[?, B], and the join does not combine them. The Option spelling (Some(x) / None) joins.

Expected

Ok(2); Sema types the join Result[i64, str] (or refuses it with a diagnostic) — post-Sema type 0 is a compiler bug.

Workaround

Annotate the binding (let r: Result[i64, str] = ...). Found while fixing the §13.6a comprehension yield typing (which no longer goes through this join).

Activity

  1. ehartford commented on Oct 3, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by 792351b (stack #2007, battery green on 0f13a62). An unannotated join of Ok(a)/Err(b) arms types Result[A, B].

  2. added 2 commits that reference this issue on Oct 13, 2026
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