Files
sx/examples/types/0187-types-enum-qualified-variant.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

36 lines
1.0 KiB
Plaintext

// Qualified enum-variant construction: `EnumType.variant` for a payloadless
// variant, the explicit twin of the leading-dot `.variant` form. Works for a
// plain enum and for a payloadless variant of a tagged union; a payload-carrying
// variant keeps its call form (`Shape.circle(2.0)`), unaffected.
#import "modules/std.sx";
Color :: enum { red; green; blue; }
Shape :: enum {
circle: f32; // payload-carrying
dot; // payloadless
}
main :: () {
// Plain enum, qualified construction.
c := Color.green;
if c == {
case .red: { print("red\n"); }
case .green: { print("green\n"); }
case .blue: { print("blue\n"); }
}
// Tagged union: payloadless variant qualified, payload variant via call.
d := Shape.dot;
if d == {
case .circle: (r) { print("circle {}\n", r); }
case .dot: { print("dot\n"); }
}
s := Shape.circle(2.0);
if s == {
case .circle: (r) { print("circle {}\n", r); }
case .dot: { print("dot\n"); }
}
}