cgen: accept an indexed source in aggregate element assignment

The a[i] = src copy loop enumerated ident/field/deref sources; an
N_INDEX rhs fell to the scalar tail and truncated the element. Route
it through the generic place-address funnel. Both stages.
This commit is contained in:
2026-08-07 23:00:02 +09:00
parent 078708770b
commit 7dc3150b65
3 changed files with 47 additions and 8 deletions

View File

@@ -0,0 +1,26 @@
// Indexed aggregate assignment must copy from the source element's storage.
// Sorting uses this three-step swap on slices, so preserving only one word can
// silently duplicate records while both compiler stages still agree.
package aggregate_slice_swap_test;
type row = struct {
key: i64,
value: i64,
guard: i64,
};
@test fn distinct_after_swap() void = {
let rows: []row = [];
append(rows, row { key = 1, value = 11, guard = 111 });
append(rows, row { key = 2, value = 22, guard = 222 });
let t: row = rows[1];
rows[1] = rows[0];
rows[0] = t;
assert(rows[0].key == 2);
assert(rows[0].value == 22);
assert(rows[0].guard == 222);
assert(rows[1].key == 1);
assert(rows[1].value == 11);
assert(rows[1].guard == 111);
};