From 38c569c1dac7dcf9b29ffc7d332a275aa2cba64c Mon Sep 17 00:00:00 2001 From: pjh456 <147148383@qq.com> Date: Fri, 7 Aug 2026 16:27:48 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20catch=20=E5=8F=82=E6=95=B0=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E8=A7=A3=E6=9E=84=20pattern=EF=BC=88=E6=95=B0?= =?UTF-8?q?=E7=BB=84/=E5=AF=B9=E8=B1=A1/=E9=BB=98=E8=AE=A4=E5=80=BC?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/oxide_emit/src/stmt/exception/try_catch.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/crates/oxide_emit/src/stmt/exception/try_catch.rs b/crates/oxide_emit/src/stmt/exception/try_catch.rs index 654cacf8..dffcff91 100644 --- a/crates/oxide_emit/src/stmt/exception/try_catch.rs +++ b/crates/oxide_emit/src/stmt/exception/try_catch.rs @@ -47,11 +47,10 @@ impl Emitter { if let Some(catch) = &ts.handler { ctx.push_scope(); if let Some(param) = &catch.param { - let catch_reg = ctx.alloc_reg(); - if let oxide_parser::BindingPattern::BindingIdentifier(bi) = ¶m.pattern { - ctx.declare_initialized(bi.name.as_str(), catch_reg, VariableDeclarationKind::Let, false)?; - ctx.inst(Inst::new(OpCode::STORE_VAR, Operand::Reg(catch_reg), Operand::None, Operand::None)); - } + 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(¶m.pattern, src_reg, VariableDeclarationKind::Let, false, ctx)?; } let mut last_catch_result: Option = None; for s in &catch.body.body {