You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
let-else: the pattern's bindings are in scope inside the else branch; check accepts it and MIR lowering then fails #1476
Spec: §9.7 let ... else — the else branch runs when the pattern does not match, so nothing the pattern binds exists there.
fn vec_or_err(k: i32) -> Result[Vec[str], str]:
if k == 0: return Err("none".clone())
var v: Vec[str] = Vec.new()
v.push("a".clone())
v
fn h(k: i32) -> i32:
let Ok(v) = vec_or_err(k) else: return v.len() as i32
v.len() as i32
fn main:
print(f"{h(0)}")
Actual (stage1 of origin/main ba2d5d1): with check says ok; with run fails in MIR lowering: error: MIR lowering failed for function 'h' ... AST codegen was removed, so this function cannot be compiled.
Expected: a Sema error at the v in the else branch (the name is not bound on that path), the same diagnostic as any unbound name.
Mechanism (from reading, not yet traced): check_let_else (src/SemaCheck.w) binds the pattern's names with check_pattern into the enclosing scope before it checks the else body, so the else body resolves them.
Found while building the #1383 let-else move matrix.
Activity
let-else: a move in the diverging else branch stays on that path — Se…
let-else: a move in the diverging else branch stays on that path — Se…
Sema: let-else checks the else branch before the pattern binds its na…