Saltar al contenido
TE131 · Tipos · error

La llamada con argumento nombrado no se puede reordenar

Un argumento nombrado (`f(nombre: valor)`) no coincide con los parámetros declarados de la función llamada — un nombre desconocido o duplicado, un argumento posicional después de uno nombrado, un parámetro intermedio omitido, o una llamada cuya firma no se conoce localmente.

Why this fires

A call with at least one named argument (f(name: value)) could not be safely reordered to the callee's declared parameter order. Zolo binds named arguments by name — the compiler reorders them to match the declaration before the call runs — but it refuses to do so, and reports TE131, when:

  • The label doesn't match any declared parameter name (a "did you mean?" suggestion is attached when a close match exists).
  • A positional argument follows a named one (f(a: 1, 2)).
  • The label names a parameter that's already filled — by an earlier positional argument or an earlier named argument.
  • The named arguments leave an earlier parameter unfilled while a later one is supplied by name (a "skipped middle parameter") — reordering can't splice that parameter's default in from the middle of the argument list.
  • The callee has no locally-known signature (a stored function value, a dynamically re-exported import, a plugin/native call) — named-argument reordering only works against a function declared in the same program.
fn f(a: int, b: int = 1, c: int = 2) -> int {
    return a + b + c
}

f(a: 1, c: 5)
//      ^^^^ error[TE131]: named-argument call skips parameter `b`; pass it
//            explicitly (middle-parameter defaults with named arguments are
//            not supported yet)

Fix it

1. Pass the skipped parameter explicitly

f(a: 1, b: 1, c: 5)      // ok
f(c: 5, a: 1, b: 1)      // ok — order between named args is free

2. Fix the label name

fn f(a: int, b: int) -> int { return a + b }

f(a: 1, bb: 2)
//      ^^ error[TE131]: unknown parameter `bb` — did you mean `b`?

f(a: 1, b: 2)             // fixed

3. Don't name a parameter that's already filled

f(1, a: 2)                // error[TE131]: `a` is a duplicate or collides
                           //   with the already-bound positional slot
f(a: 2)                    // fixed — pick one form

4. Don't mix a positional argument after a named one

f(a: 1, 2)                 // error[TE131]: positional argument after named argument
f(a: 1, b: 2)               // fixed — label both...
f(1, 2)                     // ...or label neither

5. Give the callee a local signature

Named-argument reordering only applies to a function declared in the same program, since the compiler needs its parameter list at compile time. If you're calling through a value (a stored function reference, a dynamically re-exported import, or a plugin/native call), use positional arguments instead:

let g = some_dynamic_lookup()
g(1, 2)                      // positional — g's signature isn't known locally

See also

  • TE110 — argument count mismatch (arity), independent of naming.
  • TE111 — argument type mismatch.
  • /docs/functions — default arguments and named-argument call syntax.

Véase también

Buscar en Zolo

9 resultados

en