fix: 修复无 else 块时冗余指令跳转问题

This commit is contained in:
爱特每羊队
2026-06-06 13:30:41 +08:00
parent fc953a53fc
commit a3f6db1da7
2 changed files with 10 additions and 5 deletions
+6 -3
View File
@@ -93,9 +93,12 @@ impl Compiler {
));
}
let end_pos = ctx.label_map[&end_label];
let offset = (end_pos as isize) - (ctx.bytecode.len() as isize);
ctx.emit(opcode::encode_jmp(offset as i16));
let has_alt = ifs.alternate.is_some();
if has_alt {
let end_pos = ctx.label_map[&end_label];
let offset = (end_pos as isize) - (ctx.bytecode.len() as isize);
ctx.emit(opcode::encode_jmp(offset as i16));
}
if let Some(alt) = &ifs.alternate {
let alt_reg = self.emit_statement(alt, ctx)?;