Issue #2636: Tuple spread in a call: f(..t) (ADR-call-spread-v1 D1)

Open and answer this issue on GitHub.

ready · opened 2026-11-21 · updated 2026-11-21 · 0 comments

Part of #449 (subcommands of main, option A decided by the owner, 2026-11-21).

Decision: ADR-call-spread-v1 D1 and D4; Part I 5.1 (commit b609876ab).

Probe

fn show(file: String, depth: int) {
    println(f"{file} {depth}")
}

fn main() {
    let t = ("areas.md", 2)
    show(..t)
}

Today (target/fast/nikaia check, b609876ab):

error: Expected `)`, `;` or identifier here, but found `.`.
  --> tuple.nika:7:10

Expected

areas.md 2. ..t before the ; spreads the tuple t into the positional arguments in order; it may stand beside written arguments (f(x, ..t), f(..t, y); the spread after the ; is the struct-spread issue). The call is checked as if written out: a tuple of the wrong length is NK1101, an element of the wrong type NK1102, both naming the spread. A second .. before the ;, or ..v of a value that is not a tuple, is NK1355 (reserved for this lane, listed in Part III 30 under Decided, not built yet). The tuple is evaluated once, then taken apart.

To build

  1. Grammar in crates/nikaia/src/parser/mod.rs, rule call_args / call_args_tail (around line 3594): an element may be ".." e:expr. The AST Expr::Call in crates/nikaia-std/src/compiler/ast.nika gets the spread as an argument form (e.g. Expr::Spread { value, id } allowed only in args), so later passes see where it stood. Test call_spread_tuple_is_parsed.nika (+ .stdout): the probe prints areas.md 2 once steps 2-3 are in; until then the parser test is the nikaia check run of it.
  2. Check in crates/nikaia-std/src/compiler/check_core_args.nika (check_core_args_other and wherever arity and argument types are matched): expand the spread to the tuple’s element types before the positional check, so NK1101/NK1102 come out of the existing code; NK1355 for a second spread or a non-tuple. Tests call_spread_tuple_wrong_length.nika + .stderr (NK1101), call_spread_tuple_wrong_type.nika + .stderr (NK1102), call_spread_two_in_one_zone.nika + .stderr and call_spread_of_a_non_tuple.nika + .stderr (NK1355).
  3. Lowering (the emit pass for calls, crates/nikaia-std/src/compiler/emit_*.nika): bind the tuple once (let __s = t;) and pass __s.0, __s.1, …. Test call_spread_tuple_evaluated_once.nika + .stdout: the tuple comes from a function that prints when called; it prints once; with written arguments before and after the spread, the order is kept.
  4. Tooling page: move NK1355 from Decided, not built yet into the built list of Part III 30 (the struct-spread half of NK1355 lands with the next issue; say so in the row).

Done when

All tests above pass and the existing call tests stay green. The commit of step 4 carries Fixes #N. A gap met on the way is a Found: line in the report (CLAUDE.md, Moving Rust into Nikaia), not a workaround.

Files: crates/nikaia/src/parser/mod.rs (Rust: the grammar lives only there; the same allowance as b39218396; report the lines for #557 / #125), ast.nika, check_core_args.nika, the call emitter, docs/specification/30-nikaia-tooling.md, tests in tests/compiler/tests/.

Facts: nikaia test --filter call_spread from tests/compiler runs the new tests; nikaia test takes no file arguments.

Ruled out: a spread in a struct literal or a list literal, a Vec spread into positional arguments (length unknown at compile time), two spreads in one zone: not decided (ADR-call-spread-v1, Not decided); a builder meeting a need for them stops with Result: blocked.

Back to Open Issues