// Phase 212: Pattern 1 + Pattern 3 (IfPHI) test - if-sum implementation // Tests: Loop with conditional update inside if block // Target: selfhost if-sum pattern (e.g., FuncScannerBox._sum_def_count) // // Expected behavior: // Array [null-equivalent, "a", "b"] → sum counts non-empty strings // Empty string "" treated as null-equivalent → skip // "a", "b" are valid → sum = 2 // // Expected result: 2 (count of valid items) static box IfSumTest { sum_def_count(defs) { local sum sum = 0 local i i = 0 local len len = 3 loop(i < len) { // ArrayBox.get equivalent (simplified: use index directly) // In real code: local item = defs.get(i) // For Phase 212: simulate with positional check // Simulate: [empty, "a", "b"] // i=0 → empty (skip) // i=1 → "a" (count) // i=2 → "b" (count) if i > 0 { // Conditional update: sum = sum + 1 sum = sum + 1 print(sum) // ← Force if to stay in MIR } else { print(0) // ← Ensure else branch exists } i = i + 1 } return sum } main() { // Array: [empty, "a", "b"] → sum=2 // (simplified without actual ArrayBox for Phase 212) local result result = IfSumTest.sum_def_count(0) // dummy arg return result } }