Files
hakorune/tests/mir_static_main_args_loop.rs
nyash-codex e656958033 feat(env): Phase 71-73 - SSA fix + Stage-3 ENV consolidation
## Phase 71-SSA: StageBDriverBox birth warning 解消
- Fixed false-positive dev verify warning for static boxes
- StageBDriverBox is a static box, so it doesn't follow NewBox→birth pattern
- Modified lifecycle.rs to skip StageBDriverBox from birth() requirement

## Phase 73-A: Stage-3 legacy ENV 統一化
- Consolidated NYASH_PARSER_STAGE3 and HAKO_PARSER_STAGE3 → NYASH_FEATURES=stage3
- Updated 20 test files (46 direct replacements)
- Special handling for parser_stage3.rs compat layer and mir_static_main_args_loop.rs
- All test files now use unified NYASH_FEATURES=stage3

## Phase 72-73: ENV inventory documented
- Created phase72-73-env-inventory.md with complete usage analysis
- Identified 113 direct ENV reads requiring SSOT consolidation
- Prioritized Phase 72 (JoinIR EXPERIMENT SSOT) and Phase 73 (Stage-3 cleanup)

## Phase 74-SSA: Minimal reproduction for static box delegation
- Created parser_box_minimal.hako and ssa_static_delegation_min.hako
- Investigated spawn failure in selfhost compiler (arguments too long)
- Root cause: NYASH_NY_COMPILER_EMIT_ONLY=1 defaults to emit-only mode

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-02 12:36:28 +09:00

109 lines
2.7 KiB
Rust

use std::fs;
/// 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;
#[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_FEATURES", "stage3")
.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_FEATURES", "stage3")
.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_FEATURES", "stage3")
.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");
}