Files
sx/examples/comptime/0605-comptime-aggregate-global.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

32 lines
974 B
Plaintext

#import "modules/std.sx";
// MEM Phase 1.4 regression: an aggregate (struct) returned from a `#run`
// initializer must serialize correctly into the static binary, not
// silently collapse to a zero-init constant.
//
// Before Phase 1.4 the LLVM `valueToLLVMConst` only handled int/float/bool
// and dropped everything else into `LLVMConstNull` — so a global like
// `POINT :: #run make_point();` ended up emitting `{0, 0}` regardless of
// what the interp computed. Reading POINT.x would give 0, hiding the bug.
//
// Also exercises type inference at the `NAME :: #run expr;` binding site:
// without an explicit annotation, the global's type is taken from the
// comptime expression's return shape (here, `Point`).
Point :: struct {
x: i32;
y: i32;
}
make_point :: () -> Point {
return Point.{ x = 7, y = 13 };
}
POINT :: #run make_point();
main :: () -> i32 {
print("POINT.x = {}\n", POINT.x);
print("POINT.y = {}\n", POINT.y);
return 0;
}