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.
27 lines
738 B
Plaintext
27 lines
738 B
Plaintext
// 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);
|
|
};
|