Files
sx/examples/comptime/0627-comptime-enum-value-param.sx
agra 66bdc70bf1 test: group examples into per-category folders
Move examples/*.sx and their expected/ snapshots into per-category
subfolders (examples/<category>/...). Folder = leading filename token,
with ffi-objc/ffi-jni kept whole; filenames are unchanged. The corpus
runner and LSP sweep now discover each category's expected/ dir, while
issues/ stays flat. Example 1058's repo-root-relative companion import
is made file-relative. Path strings embedded in 164 snapshots were
regenerated (path-only changes). Test-layout docs in CLAUDE.md updated.
2026-06-21 14:41:34 +03:00

28 lines
978 B
Plaintext

// Comptime ENUM value parameter: `$o: <EnumType>` binds the enum-literal
// argument to its variant tag, monomorphizes the inlined body per distinct
// ordering value, and resolves `o` in the body as a compile-time-known enum
// constant — usable both in `if o == .a` comparisons AND as a comptime-readable
// variant tag during lowering (a downstream lowerer reads it via
// `comptime_value_bindings`, exercised here as the `[o]i64` array dimension).
#import "modules/std.sx";
Ord :: enum { a; b; c; }
pick :: ($o: Ord) -> i64 {
if o == .a { return 10; }
if o == .b { return 20; }
return 30;
}
// `o` read as a compile-time integer (its variant tag) in a TYPE position.
tag_dim :: ($o: Ord) -> i64 {
arr : [o]i64 = ---;
return arr.len;
}
main :: () {
print("{}\n", pick(.b)); // 20
print("{} {} {}\n", pick(.a), pick(.b), pick(.c)); // 10 20 30
print("{} {} {}\n", tag_dim(.a), tag_dim(.b), tag_dim(.c)); // 0 1 2
}