001 pure annotation

✗ Failing This test is currently failing.

Failed: backend-exec

Error Details

output_emitted.zig:55:74: error: type 'i32' does not support field access

Failure Output

🎯 Compiler coordination: Passes: 13 (flow-based: frontend, analysis, emission)
Error: output_emitted.zig:55:74: error: type 'i32' does not support field access
        const result_1 = main_module.print_number_event.handler(.{ .n = d.result });
                                                                        ~^~~~~~~
referenced by:
    main: output_emitted.zig:105:22
    callMain [inlined]: /opt/homebrew/Cellar/zig/0.15.2_1/lib/zig/std/start.zig:618:22
    callMainWithArgs [inlined]: /opt/homebrew/Cellar/zig/0.15.2_1/lib/zig/std/start.zig:587:20
    main: /opt/homebrew/Cellar/zig/0.15.2_1/lib/zig/std/start.zig:602:28
    1 reference(s) hidden; use '-freference-trace=5' to see all references

Code

// Test basic ~[pure] annotation
// Verify that parser accepts ~[pure] annotation on proc

const std = @import("std");

// Pure math function - marked with ~[pure]
~event add { a: i32, b: i32 }
| done i32

~[pure]proc add {
    return .{ .done = a + b };
}

// Impure I/O function (no annotation - defaults to impure)
~event print_number { n: i32 }
| done

~proc print_number {
    std.debug.print("Number: {}\n", .{n});
    return .{ .done = .{} };
}

// Use flow composition (not handler calls)
// This tests that pure annotation is parsed correctly
~add(a: 10, b: 32)
| done d |> print_number(n: d.result)
    | done |> _
input.kz

Expected

Number: 42

Test Configuration

MUST_RUN

Post-validation Script:

#!/bin/bash
# Verify that ~[pure] annotation is preserved in the AST
# The backend can reason about purity during compilation

# Generate AST JSON from the input
# Note: koruc --ast-json generates JSON even with parse errors (for IDE tooling)
AST_JSON=$(koruc --ast-json input.kz 2>&1)

# Check that the add proc has is_pure: true
if ! echo "$AST_JSON" | grep -q '"event_name": "add"'; then
    echo "Missing 'add' proc in AST"
    exit 1
fi

if ! echo "$AST_JSON" | grep -A 10 '"event_name": "add"' | grep -q '"is_pure": true'; then
    echo "'add' proc should have is_pure: true"
    exit 1
fi

# Check that the print_number proc has is_pure: false
if ! echo "$AST_JSON" | grep -q '"event_name": "print_number"'; then
    echo "Missing 'print_number' proc in AST"
    exit 1
fi

if ! echo "$AST_JSON" | grep -A 10 '"event_name": "print_number"' | grep -q '"is_pure": false'; then
    echo "'print_number' proc should have is_pure: false"
    exit 1
fi

echo "✓ Pure annotations correctly preserved in AST"
exit 0