From 331691e8bd63613a32d922f7a1d6ab8eee3fe417 Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Sun, 16 Aug 2026 12:34:03 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20class=20=E5=A3=B0=E6=98=8E=E5=90=8D?= =?UTF-8?q?=E7=BA=B3=E5=85=A5=E9=97=AD=E5=8C=85=E6=8D=95=E8=8E=B7=EF=BC=8C?= =?UTF-8?q?=E5=B5=8C=E5=A5=97=E5=87=BD=E6=95=B0=E7=BB=8F=20cell=20?= =?UTF-8?q?=E8=AF=BB=E5=8F=96=E7=B1=BB=E7=BB=91=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_emit/src/class/emit.rs | 10 ++++++++++ crates/oxide_emit/src/closure.rs | 7 +++++++ 2 files changed, 17 insertions(+) diff --git a/crates/oxide_emit/src/class/emit.rs b/crates/oxide_emit/src/class/emit.rs index 2251e4f..cc6eda4 100644 --- a/crates/oxide_emit/src/class/emit.rs +++ b/crates/oxide_emit/src/class/emit.rs @@ -400,6 +400,16 @@ impl Emitter { Operand::None, )); } + // 类名被外层嵌套函数捕获时,真实名 cell 同样须初始化(类元素自引用走 + // @@class_self_* 合成 cell,二者 cell_idx 不同则各发一次)。 + if let Some(&cell_idx) = ctx.captured_bindings.get(name) { + ctx.inst(Inst::new( + OpCode::MAKE_CELL, + Operand::Reg(binding_reg), + Operand::Imm(cell_idx as u16), + Operand::None, + )); + } } if pushed_scope { diff --git a/crates/oxide_emit/src/closure.rs b/crates/oxide_emit/src/closure.rs index 601f308..a6b6f76 100644 --- a/crates/oxide_emit/src/closure.rs +++ b/crates/oxide_emit/src/closure.rs @@ -86,6 +86,13 @@ impl Emitter { out.insert(id.name.to_string()); } } + // class 名是本作用域 const 绑定:须计入 own_bindings,否则嵌套函数 + // 引用类名时捕获分析缺失 → 落符号表兜底(TDZ 误报或读父寄存器残留)。 + Statement::ClassDeclaration(cd) => { + if let Some(id) = &cd.id { + out.insert(id.name.to_string()); + } + } // import 绑定是模块作用域 const 绑定,须计入 own_bindings 供 // 嵌套函数 cell 捕获。 Statement::ImportDeclaration(imp) => {