Files
sx/examples/comptime/0614-comptime-metatype-enum.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

31 lines
1.0 KiB
Plaintext

// Comptime type construction: mint a NEW nominal enum from a `TypeInfo` value
// via the `define(declare("E"), info)` primitives, then construct one of its
// variants and match on it — exercising that a programmatically-built enum
// (with NO backing AST decl) flows through enum codegen unmodified (layout /
// construct / match), byte-identical to a hand-written enum.
//
// The enum has two variants: `value` carrying an i64 payload, and `closed` with
// no payload (`payload = void`).
#import "modules/std.sx";
#import "modules/std/meta.sx";
E :: define(declare("E"), .enum(.{ variants = .[
EnumVariant.{ name = "value", payload = i64 },
EnumVariant.{ name = "closed", payload = void },
] }));
main :: () -> i32 {
e := E.value(3);
if e == {
case .value: (v) { print("value {}\n", v); }
case .closed: { print("closed\n"); }
}
c : E = .closed;
if c == {
case .value: (v) { print("value {}\n", v); }
case .closed: { print("closed\n"); }
}
return 0;
}