Files
hakorune/tests/mir_static_main_args_loop.rs
nyash-codex a95fedf26a fix(mir): Phase 25.1m - Continue PHI修正 & Bug A main(args)ループ修正
**Phase 25.1m: Continue PHI修正**
- seal_phis に continue_snapshots 入力を追加 (loopform_builder.rs)
- LoopShape::debug_validate に continue/break エッジ検証追加 (control_form.rs)
- test_seal_phis_includes_continue_snapshots テスト追加
- 実証テスト成功: balanced scan loop で 228回イテレーション確認

**Bug A修正: main(args) でループ未実行問題**
- LoopBuilder::build_loop で entry → preheader への jump 追加
- decls.rs でデュアル関数作成時のブロック接続修正
- mir_static_main_args_loop.rs テスト追加

**パーサー改善**:
- parser_box.hako に HAKO_PARSER_PROG_MAX ガード追加(無限ループ対策)

🎉 成果:
- Continue 文の PHI predecessor mismatch エラー完全解消
- main(args) パラメータ有りループが正常動作
- Stage-B balanced scan で continue 正常動作確認 (228回イテレーション)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-19 08:04:43 +09:00

107 lines
2.7 KiB
Rust

/// Bug A investigation: main(args) causes loops not to execute
/// This test reproduces the issue where adding a parameter to main()
/// causes the loop body to never execute (RC=0 instead of RC=3)
use std::process::Command;
use std::fs;
#[test]
fn mir_static_main_no_args_loop() {
// Working case: main() → RC=3
let source = r#"
static box Main {
main() {
local i = 0
local count = 0
loop(i < 3) {
count = count + 1
i = i + 1
}
return count
}
}
"#;
let temp_file = "/tmp/mir_test_no_args.hako";
fs::write(temp_file, source).expect("Failed to write test file");
let output = Command::new("./target/release/hakorune")
.arg("--backend")
.arg("vm")
.arg(temp_file)
.env("NYASH_PARSER_STAGE3", "1")
.env("NYASH_DISABLE_PLUGINS", "1")
.output()
.expect("Failed to execute hakorune");
fs::remove_file(temp_file).ok();
let exit_code = output.status.code().unwrap_or(-1);
assert_eq!(exit_code, 3, "Expected RC=3 for main() with loop");
}
#[test]
fn mir_static_main_with_args_loop() {
// Broken case: main(args) → RC=0 (BUG: should be 3)
let source = r#"
static box Main {
main(args) {
local i = 0
local count = 0
loop(i < 3) {
count = count + 1
i = i + 1
}
return count
}
}
"#;
let temp_file = "/tmp/mir_test_with_args.hako";
fs::write(temp_file, source).expect("Failed to write test file");
let output = Command::new("./target/release/hakorune")
.arg("--backend")
.arg("vm")
.arg(temp_file)
.env("NYASH_PARSER_STAGE3", "1")
.env("NYASH_DISABLE_PLUGINS", "1")
.output()
.expect("Failed to execute hakorune");
fs::remove_file(temp_file).ok();
let exit_code = output.status.code().unwrap_or(-1);
// This will FAIL due to the bug - loop doesn't execute
assert_eq!(exit_code, 3, "Expected RC=3 for main(args) with loop (BUG: currently returns 0)");
}
#[test]
fn mir_static_main_args_without_loop() {
// Sanity check: main(args) works WITHOUT loop
let source = r#"
static box Main {
main(args) {
return 42
}
}
"#;
let temp_file = "/tmp/mir_test_args_no_loop.hako";
fs::write(temp_file, source).expect("Failed to write test file");
let output = Command::new("./target/release/hakorune")
.arg("--backend")
.arg("vm")
.arg(temp_file)
.env("NYASH_PARSER_STAGE3", "1")
.env("NYASH_DISABLE_PLUGINS", "1")
.output()
.expect("Failed to execute hakorune");
fs::remove_file(temp_file).ok();
let exit_code = output.status.code().unwrap_or(-1);
assert_eq!(exit_code, 42, "Expected RC=42 for main(args) without loop");
}