Files
sx/examples/types/0102-types-union.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

49 lines
996 B
Plaintext

#import "modules/std.sx";
Shape :: enum {
circle: f32;
rect: struct { w, h: f32;};
none;
}
main :: () {
// Construction with .variant(payload)
s :Shape = .circle(3.14);
print("circle: {}\n", s);
// Payload access
r := s.circle;
print("radius: {}\n", r);
// Void variant via enum literal
s = .none;
print("none: {}\n", s);
// Reassign with payload
s = .rect(.{4, 2});
print("rect: {}\n", s);
// Explicit prefix construction
sh :Shape = Shape.circle(2.71);
print("sh: {}\n", sh);
// Field access on second variable
sh2 :Shape = .rect(.{2,4});
val := sh2.rect;
print("rect val: {}\n", val);
// Match on enum
if sh2 == {
case .circle: print("matched circle\n");
case .rect: print("matched rect\n");
case .none: print("matched none\n");
}
cs := if sh2 == {
case .circle: 1;
case .rect: 2;
case .none: 3;
}
print("case : {}", cs);
}