049 invocation meta

✓ Passing This code compiles and runs correctly.

Code

// Test: InvocationMeta provides call site metadata for comptime introspection
// This enables conditional compilation based on flow annotations

~import "$std/io"

const std = @import("std");

// A comptime event that receives metadata about its invocation
~[comptime]pub event check_config { meta: InvocationMeta }
| matched { config_name: []const u8 }
| no_annotation {}

~proc check_config {
    // meta.annotations contains the flow annotations like ["release"], ["debug"]
    // meta.path contains the full path like "check_config"
    // meta.location contains the source location

    if (meta.annotations.len > 0) {
        // Return the first annotation as the config name
        return .{ .matched = .{ .config_name = meta.annotations[0] } };
    } else {
        return .{ .no_annotation = .{} };
    }
}

// Test 1: Invocation with [release] annotation
~[release]check_config()
| matched _ |> std.io:println(text: "Config: release")
| no_annotation |> std.io:println(text: "No config")

// Test 2: Invocation with [debug] annotation
~[debug]check_config()
| matched _ |> std.io:println(text: "Config: debug")
| no_annotation |> std.io:println(text: "No config")

// Test 3: Invocation without annotation
~check_config()
| matched _ |> std.io:println(text: "Config: unexpected")
| no_annotation |> std.io:println(text: "No config (expected)")
input.kz