Files
sx/examples/diagnostics/1118-diagnostics-global-non-const-initializer-rejected.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

20 lines
711 B
Plaintext

// A top-level global initialized from a non-constant expression (here a field
// access on a module constant, `K.x`) is rejected with a diagnostic. Without
// the fix `registerTopLevelGlobal`'s init_val serializer handled only literals
// / array / struct literals / identifiers and let every other shape fall through
// to a null payload, so the global silently zero-initialized (`g=0`) — a wrong
// value with no error.
// Regression (issue 0072).
// Expected: "global 'g' must be initialized by a compile-time constant"; exit 1.
#import "modules/std.sx";
Point :: struct { x: i32; y: i32; }
K : Point : Point.{ x = 9, y = 4 };
g : i32 = K.x;
main :: () -> i32 {
print("g={}\n", g);
return g;
}