Error reference › Runtime diagnostics
stack overflow
errorWhat it means
Each Mozhi call consumes C stack. Since v3.2.0 the interpreter counts nested calls and stops at the limit with this diagnostic instead of crashing. The stack rlimit is also raised at startup so legitimate deep recursion has headroom.
Trigger condition
A recursion (or mutual recursion) exceeds the call-depth limit — previously this crashed the interpreter with a stack overflow SIGSEGV.
Minimal failing example
fn f(n) { return 1 + f(n) }
echo(string(f(1)))Verified fix
fn f(n) { if n <= 0 { return 0 } return 1 + f(n-1) }
echo(string(f(500)))Every recursion needs a terminating condition that eventually holds.
What the interpreter prints
error[RUNTIME006]: stack overflow
--> app.mz:1:16
1 | fn f(n) { return 1 + f(n) }
| ^
|
reason: (the exact problem, with positions)
help: (a suggested fix appears here)
docs: https://crossberry-in.github.io/mozhi-doc/errors/RUNTIME006mozhi --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
Add/strengthen the base case, or convert to a loop (`while`). Verified: depth 5000 completes; the default guard fires at 8000 nested calls.
Related syntax
Functions, recursion, while loops
Related diagnostics
None
Reference links
Limitations
The depth limit is fixed (8000) in v3.2.0 and not yet configurable. Extremely deep legitimate recursion must be restructured into loops.