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

This commit is contained in:
2026-06-08 23:45:00 +08:00
parent c1412d20fa
commit 40dba1159c
5 changed files with 50 additions and 3 deletions
@@ -256,3 +256,16 @@ fn eval_break_in_switch_in_loop() {
"2"
);
}
#[test]
fn eval_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");
assert_eq!(eval(&source), "2");
}