Skip to content

let [a, b, c] = fixed_array is called refutable; §9.7 compile-time length matching makes it irrefutable #1367

Closed

Description

@ehartford

Spec §9.7: "For fixed-size arrays, the compiler performs compile-time length matching: [a, b, c] matches exactly 3 elements". The let destructuring example let [first, second, ..rest] = items is irrefutable when the array's length is known. The compiler calls every slice pattern refutable.

Repro (a stage1 built from origin/main 5fd93bc):

fn main:
    let arr = [1, 2, 3]
    let [a, b, c] = arr
    print(f"{a} {b} {c}")

Actual: error: let ... else requires an else branch for refutable patterns.
Expected: prints 1 2 3. A length mismatch against a fixed array should be a compile error, not an else requirement.

Exact line: SemaCheck.pattern_is_refutable returns 1 for NK_PAT_SLICE whatever the subject type (it gets no type), and check_let_else calls it before the subject is known to be TY_ARRAY.

Workaround: let [a, b, c] = arr else: return (the else never runs).

Found while building the #1354 matrix.

Activity

  1. ehartford commented on Sep 26, 2026

    @ehartford
    ContributorAuthor

    Verified fixed on main 55739d4 (release binary): let [a, b, c] = arr accepted, prints 1 2 3.

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