fix: catch 参数名补入捕获扫描且 catch 入口新 cell

This commit is contained in:
2026-09-20 04:46:41 +00:00
parent 9b4f1e916d
commit 2b0238f310
3 changed files with 260 additions and 1 deletions
@@ -72,7 +72,10 @@ impl Emitter {
let src_reg = ctx.alloc_reg();
// 异常值在 VM 物理 regs[0](unwind 展开处写入),STORE_VAR a=None 读回。
ctx.inst(Inst::new(OpCode::STORE_VAR, Operand::Reg(src_reg), Operand::None, Operand::None));
self.emit_binding_pattern(&param.pattern, src_reg, VariableDeclarationKind::Let, false, false, ctx)?;
// 每次 catch 执行都为参数新建词法环境:被捕获参数在入口发
// MAKE_CELL_FRESH(替换而非覆写上一入口的 cell),上一入口
// 闭包持有的旧 cell 指针仍可读到旧值。
self.emit_binding_pattern(&param.pattern, src_reg, VariableDeclarationKind::Let, false, true, ctx)?;
}
// catch 块函数预声明先于 lexical,块入口物化与 try/普通块同口径。
self.predeclare_block_function_declarations(&catch.body.body, ctx, false);