Files
sx/examples/types/0188-types-method-array-index-receiver.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

27 lines
888 B
Plaintext

// A `*self` method called directly on an array-index place (`arr[i].method()`)
// must mutate the LIVE array slot, not a throwaway copy. `fixupMethodReceiver`
// now takes the real address of `.index_expr`/`.deref_expr` receivers (via
// `lowerExprAsPtr`), mirroring the explicit-argument path — instead of falling
// through to an alloca+store-of-value that the callee then mutates in vain.
//
// Regression (issue 0145).
#import "modules/std.sx";
S :: struct {
flag: bool;
set :: (self: *S) { self.flag = true; }
}
A :: struct { items: [4]S; }
main :: () -> i32 {
a : A = .{};
a.items[1].set(); // direct: must mutate the slot
print("direct = {}\n", a.items[1].flag); // true
p := @a.items[1];
p.set(); // via explicit pointer
print("ptr = {}\n", a.items[1].flag); // true
0
}