The implicit address-of that gives `*T` params reference semantics only fired for plain identifiers (`mut(v)`). For a field-access / index / deref lvalue (`make_move(self.board, m)`, `mut(w.s)`), the branch was skipped: the arg was loaded into a temporary and the callee mutated a throwaway copy — silent data loss, with the type check satisfied through the temp so no diagnostic fired. Now compound lvalues auto-ref too: take the real lvalue address via `lowerExprAsPtr`, normalizing the "place" ref to `*T` exactly as `@field_access` does. Mutations through the pointer are now visible to the caller, matching the identifier case. Regression: examples/255-autoref-compound-lvalue.sx.
21 lines
770 B
Plaintext
21 lines
770 B
Plaintext
// Auto-ref of a COMPOUND lvalue (field access / index / deref) passed to a
|
|
// `*T` parameter must reference the REAL lvalue, not a copy. Regression: a
|
|
// field-access argument (e.g. `make_move(self.board, m)`) silently passed the
|
|
// address of a temporary copy, so mutations through the pointer were lost with
|
|
// no diagnostic. A plain local (`bump(x)`) already auto-ref'd; now compound
|
|
// lvalues do too. Expected: w.s.v == 42 (the real field was mutated).
|
|
|
|
#import "modules/std.sx";
|
|
|
|
S :: struct { v: s32; }
|
|
W :: struct { s: S; }
|
|
|
|
bump :: (p: *S) { p.v = p.v + 41; }
|
|
|
|
main :: () -> s32 {
|
|
w : W = .{ s = .{ v = 1 } };
|
|
bump(w.s); // field access, no `@` — auto-refs &w.s
|
|
print("w.s.v = {}\n", w.s.v); // 42, not 1
|
|
return 0;
|
|
}
|