diff --git a/lang/src/compiler/parser/stmt/parser_stmt_box.hako b/lang/src/compiler/parser/stmt/parser_stmt_box.hako index b7763e45..b8ecbb25 100644 --- a/lang/src/compiler/parser/stmt/parser_stmt_box.hako +++ b/lang/src/compiler/parser/stmt/parser_stmt_box.hako @@ -9,6 +9,17 @@ using lang.compiler.parser.stmt.parser_exception_box static box ParserStmtBox { parse(src, i, ctx) { + // Shallow recursion guard: prevent ParserStmtBox.parse from recursively + // re-entering itself on the same VM stack(Stage‑B/selfhost 安全弁)。 + { + local depth = env.get("HAKO_STAGEB_STMT_DEPTH") + if depth != null && ("" + depth) != "0" { + print("[stageb/recursion] ParserStmtBox.parse recursion detected") + // Fail-fast: return empty stmt and keep position unchanged + return "" + } + env.set("HAKO_STAGEB_STMT_DEPTH", "1") + } local j = ctx.skip_ws(src, i) local stmt_start = j @@ -182,6 +193,8 @@ static box ParserStmtBox { if j < src.length() { j = j + 1 } else { j = src.length() } } ctx.gpos_set(j) + // Clear depth guard before returning + env.set("HAKO_STAGEB_STMT_DEPTH", "0") return "{\"type\":\"Expr\",\"expr\":" + e + "}" }