Files
sx/examples/comptime/0613-comptime-print-any-type.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

33 lines
1.2 KiB
Plaintext

// Comptime `#run` formatting of an `Any` that holds a `Type`.
//
// `print("{}", at)` where `at: Any` holds a `Type` value routes through
// `format` → `any_to_string`, whose `type := type_of(val)` lowers (for an
// `.any` operand) to `struct_get(val, 0)` — reading the Any-Type's tag.
// At runtime a `Type` value is the aggregate `{ tag=.any, value=tid }`,
// so the read works and the type's name prints. The comptime interpreter
// stores a first-class `Type` as a bare `.type_tag`, so the struct_get
// must mirror that same `{ .any, tid }` layout — otherwise it bails and
// the `#run` truncates. Reflection over the same `Any` (`type_name`,
// `type_is_unsigned`) already works; the value-print must match.
//
// Regression (issue 0096): a comptime `#run` print of an `Any`-held
// `Type` silently stopped (omitted `value=` + every later line) yet still
// built with exit 0.
#import "modules/std.sx";
ct_probe :: () {
print("before\n");
x : u64 = 1;
t : Type = type_of(x);
at : Any = t;
print("name={}\n", type_name(at));
print("unsigned={}\n", type_is_unsigned(at));
print("value={}\n", at);
print("after\n");
}
#run ct_probe();
main :: () {}