Files
sx/examples/types/0109-types-global-compound-assign.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
824 B
Plaintext

// `+=` on a global variable loads the current value (not the initializer)
// before storing — same semantics as the explicit `g = g + 1` form.
#import "modules/std.sx";
g_counter : i64 = 0;
tick :: () {
g_counter += 1;
print("counter={}\n", g_counter);
}
main :: () -> void {
// Test 1: += always produces 1 (BUG)
out("--- Test 1: += (broken) ---\n");
out("Expected: 1, 2, 3\n");
i : i64 = 0;
while i < 3 {
tick();
i += 1;
}
// Test 2: manual read-modify-write works correctly
out("--- Test 2: = x + 1 (works) ---\n");
out("Expected: 2, 3, 4\n");
g_counter = g_counter + 1;
print("counter={}\n", g_counter);
g_counter = g_counter + 1;
print("counter={}\n", g_counter);
g_counter = g_counter + 1;
print("counter={}\n", g_counter);
}