Files
sx/examples/0102-types-union.sx
agra 4e942b5373 test: migrate examples to XXXX-category-name layout + split expected streams
Rename all example tests/companions to the XXXX-category-test-name scheme
(per-category 100-blocks: basic 0010, types 0100, ... errors 1000,
diagnostics 1100, ffi 1200, ffi-objc 1300, ffi-jni 1400, vectors 1500,
platform 1600). Companions and dir/C fixtures move in lockstep with their
parent test; #import/#source/#include paths rewritten to match.

Expected output now lives in examples/expected/ (a sibling dir of the
tests) split into three streams per the new convention:
  <name>.exit / <name>.stdout / <name>.stderr  (+ optional <name>.ir)

run_examples.sh rewritten: scans examples/ and issues/ for an
expected/<name>.exit marker, captures stdout and stderr separately (no
more 2>&1), compares each stream + exit + optional IR snapshot.

Behavior validated unchanged: every renamed test reproduces its prior
merged output + exit (diffs limited to file paths/basenames embedded in
diagnostics + traces, which correctly reflect the new names). Suite:
292 passed, 0 failed. 50-smoke.sx split + issue relocation + docs follow
in subsequent commits.
2026-06-01 19:05:15 +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);
}