Skip to content

Sema: let (a, b) = if c: f() else: (1, 0) rejected — "tuple pattern requires tuple subject" #1349

Closed

Description

@ehartford

Repro (the seed pinned in seed.lock and installed ~/.local/bin/with, main at ae609cd):

fn lc(b: i32) -> (i32, i32): (b + 1, b + 2)
fn main:
    let b = 3
    let (x, y) = if b > 0: lc(b) else: (1, 0)
    print(f"{x} {y}")

Actual: error: tuple pattern requires tuple subject at the let (x, y) line, followed by follow-on "undefined variable" errors for x/y.
Expected: prints 4 5. Both arms have type (i32, i32). let (x, y) = lc(b) compiles, so the tuple pattern is rejected only because the subject is an if expression (the subject's type is apparently not settled when the pattern gets checked). Spec: tuple destructuring in let (§9.7 patterns). An if-expression is an ordinary expression.

Workaround used in fix-stage-debug-info (Codegen.debug_push_lexical_block): bind the tuple to a let lc = ... first, then .0/.1.

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