M Mozhi v3.7.0 code

Error reference › Runtime diagnostics

RUNTIME010

wrong number of arguments

error
verifiedverified on v3.7.0 categoryruntime terminalstable code

What it means

Before v3.5 the interpreter bound parameters without checking the argument count and could read past the end of the argument array (measured with AddressSanitizer as an 8-byte heap-buffer-overflow). Since v3.5 every call path shares one arity model: required parameters must be present, defaulted parameters fill in when omitted, and a trailing `...rest` collects surplus arguments.

Trigger condition

A function is called with a number of arguments it does not accept: too few required arguments, or too many arguments for a function without a `...rest` parameter. Applies to declared functions, anonymous `fn` expressions, nested and recursive calls, constructors, and module-member functions.

Minimal failing example

fn add(a, b, c) {
    return a + b + c
}
print(add(1, 2))

Verified fix

fn add(a, b, c) {
    return a + b + c
}
print(add(1, 2, 3))

The error message always names the function and both counts, for example: `function 'add' expects 3 arguments, got 2`. Functions with default values report `expects at least N arguments`; functions with a rest parameter never reject extra arguments.

What the interpreter prints

error[RUNTIME010]: wrong number of arguments
  --> app.mz:1:16
 1 | fn add(a, b, c) {
   |                 ^
   |
reason: (the exact problem, with positions)
help:   (a suggested fix appears here)
docs:   https://crossberry-in.github.io/mozhi-doc/errors/RUNTIME010
Run mozhi --json run app.mz to get the same information as machine-readable JSON (schema mozhi.diagnostics.v1), or --verbose to also show grouped related diagnostics. See the CLI reference.

Suggested fix

Count the arguments at the call site against the function's parameter list. If the extra or missing arguments are intentional, declare a default value (`b = 10`) or a rest parameter (`...rest`).

Related syntax

Function declarations, default parameters, rest parameters

Related diagnostics

PARSE001RUNTIME007

Reference links

Limitations

The diagnostic is emitted at the call site when one is available; calls made through the native-module callback API report the error without a source span. The arity check is exact (no implicit argument coercion).