fix: 修复 switch case 标签冲突与大 switch 寄存器回绕

This commit is contained in:
爱特每羊队
2026-06-08 23:45:00 +08:00
parent afcc76a222
commit bf75fcd0c9
5 changed files with 50 additions and 3 deletions
@@ -281,3 +281,25 @@ fn compile_continue_in_switch_errors() {
});
assert!(result.is_err(), "continue inside switch should error");
}
#[test]
fn compile_large_adjacent_switches_do_not_collide_labels() {
let mut source = String::from("var r=0;switch(256){");
for i in 0..=256 {
source.push_str(&format!("case {i}:"));
if i == 256 {
source.push_str("r=1;break;");
}
}
source.push_str("}switch(0){case 0:r=r+1;break;}r");
let module = compile_source(&source);
assert!(
module
.bytecode
.iter()
.filter(|&&i| opcode::opcode(i) == OpCode::JMP_IF_TRUE)
.count()
>= 258,
"expected both large switches to compile with distinct case labels"
);
}