You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
js backend: string builtins are not lowered and crash at run time (ReferenceError) instead of being refused at compile time #832
architectureStructural/system-level shape and runtime behaviourbugSomething is broken or behaves incorrectlyenhancementNew capability or improvement to existing behaviourpriority:p2Normal - queue itscope:repoConfined to this repository
$ affinescript compile idx.affine -o idx.js # succeeds
$ node idx.js
ReferenceError: int_to_string is not defined
lib/js_codegen.ml:171 emits ExprVar as a bare mangled name. Nothing checks it against the builtins the JS-text backend actually provides. The same happens for len, string_get, string_sub, int_to_string and the other string builtins.
Classification
This is a divergence, not a soundness hole. It fails loudly, but at run time rather than compile time. The Bun-ESM backend lowers all of these builtins.
Options
Ranked by elegance and correctness first, then by dependability.
(Recommended: most elegant and correct) Do a closed-world check at codegen. Each backend declares which builtins it can lower. Any free identifier that is neither bound by the program nor in that table makes codegen return Error ("int_to_string is not available on the JS backend; use Bun-ESM"). The bug class becomes a compile-time refusal on every text backend, not only on JS.
Problem: On mainee211d3, the plain-JS backend compiles programs that use string builtins (int_to_string, len, string_get, string_sub, and others) without error, then crashes in Node with ReferenceError. lib/js_codegen.ml:171 emits ExprVar as a bare mangled name and never checks it against the builtins that backend provides. Bun-ESM lowers these builtins correctly.
Expected: Compilation of idx.affine to .js should fail with an Error naming the unsupported builtin, rather than succeeding.
architectureStructural/system-level shape and runtime behaviourbugSomething is broken or behaves incorrectlyenhancementNew capability or improvement to existing behaviourpriority:p2Normal - queue itscope:repoConfined to this repository
Activity
whatproblem-ai commentedon Dec 1, 2026
Problem: On
mainee211d3, the plain-JS backend compiles programs that use string builtins (int_to_string,len,string_get,string_sub, and others) without error, then crashes in Node withReferenceError.lib/js_codegen.ml:171emitsExprVaras a bare mangled name and never checks it against the builtins that backend provides. Bun-ESM lowers these builtins correctly.Expected: Compilation of
idx.affineto.jsshould fail with anErrornaming the unsupported builtin, rather than succeeding.Missing: source of
idx.affineClarity: 92%. Clear enough to work on.
⌨️ Commands · 💬 Have feedback? Tell us · 🎯 New here? Add WhatProblem to your repo · 🔒 Privacy
Merge branch 'main' into claude/js-backend-builtin-refusal-832
fix(codegen): start the wasm heap after the last data segment (#830) (#…