Repository navigation
Done
Labels
bugSomething is broken or behaves incorrectlymeta:umbrellaParent issue aggregating child issuespriority:p2Normal - queue itscope:repoConfined to this repositorystatus:readyFully specified and ready to be picked up
Description
Evidence (main ee211d3)
Each program below type-checks and runs correctly when compiled to Bun-ESM and to core wasm.
| Program | affinescript eval |
Bun-ESM / wasm |
|---|---|---|
fn g(x) { … 1 + g(x - 1) } (self-recursion) |
Runtime error: Unbound variable: g |
5 |
main calls helper, which is declared after it |
Unbound variable: helper → Type error |
3 |
is_even / is_odd (mutual recursion) |
Unbound variable: is_odd → Type error |
even |
let mut k = 0; while k < 3 { k = k + 1; } |
Runtime error: Type mismatch: Expected mutable reference |
3 |
println(int_to_string(2)) |
prints "2", with quotes |
2 |
Root causes
- Self-recursion.
lib/interp.ml:1151(TopFn) builds the closure withcl_env = envbefore binding the function's own name. There is no letrec. - Forward and mutual references. The CLI
evalpath (bin/main.ml:315,:363) type-checks with its own fold ofTypecheck.check_decl. That fold skips the forward pass thatTypecheck.check_program(lib/typecheck.ml:2656) uses to pre-register signatures. As a result,evalaccepts a smaller language thancompile. let mut.StmtLet(lib/interp.ml:507) ignores mutability.StmtAssignevaluates the left-hand side to a plain value, andValue.assignthen rejects that value.- Quoted output. The interpreter's
printlnprints aStringas an escaped OCaml literal (feat(strings): backend-independent UTF-8 octet count and code-point view #829 finding 7).
Classification
These are divergences, and all of them fail loudly. The reference interpreter refuses well-typed programs, and its frontend accepts less than compile does. None of them is a silent wrong value. The quoted println output is the exception: it is wrong output, but visibly so.
Options
Ranked by elegance and correctness first, then by dependability.
- (Recommended: most elegant and correct) Fix each at source:
- Make
evalcallTypecheck.check_program, so there is one frontend entry for every command. - Make
eval_programtwo-phase: bind every top-level function into one recursive environment by tying the knot through a mutable env cell. This matches the checker's forward pass and JS hoisting. - Make
StmtLetwithsl_mutbind aVMutcell, make variable reads dereference it, and resolveStmtAssignon anExprVarto that cell. - Make
printlnprint the raw string.
- Make
- (Most dependable) Add differential tests: run every fixture under
tests/codegen*through bothevaland Bun-ESM and compare stdout. This catches the whole class, not just these instances. - (Outside the box) Retire the tree-walker's CLI role in favour of the
solo_ceskmachine. That would also unblock tracking: interpreter non-tail single-shot resume returns the resumed value (shallow continuation) — needs delimited-continuation/CPS rewrite #623 (non-tail resume).
None of these changes language semantics: they make eval agree with the type checker and with the compiled backends.
Generated by Claude Code
Reacted by coderabbitai
Metadata
Metadata
Assignees
Labels
bugSomething is broken or behaves incorrectlymeta:umbrellaParent issue aggregating child issuespriority:p2Normal - queue itscope:repoConfined to this repositorystatus:readyFully specified and ready to be picked up
Activity
whatproblem-ai commentedon Dec 1, 2026
Problem: On
mainee211d3,affinescript evalrejects or mis-runs well-typed programs that compile and run correctly to Bun-ESM and wasm. Five cases fail: self-recursion, forward references, mutual recursion,let mutreassignment, andprintlnquoting strings.Expected:
evalaccepts the same programs ascompileand produces the same stdout as the compiled backends.Missing: full source of the five repro programs (the table abbreviates them with
…), so they can become regression fixtures.Clarity: 94%. Clear enough to work on.
⌨️ Commands · 💬 Have feedback? Tell us · 🎯 New here? Add WhatProblem to your repo · 🔒 Privacy
coderabbitai commentedon Dec 1, 2026
🔗 Related PRs
#829 - feat(strings): backend-independent UTF-8 octet count and code-point view [open]
📝 Issue Planner
Check the box below or use the
@coderabbitai plancommand to generate an implementation plan and prompts that you can use with your favorite coding assistant.🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord!
Merge origin/main into fix/833-interp-recursion-mut
fix(codegen): start the wasm heap after the last data segment (#830) (#…