| author | |
| committer | |
| log | 40447b25e87ece9eee2d83d1c78c365ad7ab40f1 |
| tree | a5546ed8efe05ed9de5de88924238333b38c3edc |
| parent | 49a270b2038709a6a0c1f4de604696278769257b |
Closes #123862 files changed, 21 insertions(+), 1 deletions(-)
src/Sema.zig+4-1| ... | ... | @@ -23990,7 +23990,10 @@ fn beginComptimePtrMutation( |
| 23990 | 23990 | const array_len_including_sentinel = |
| 23991 | 23991 | try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel()); |
| 23992 | 23992 | const elems = try arena.alloc(Value, array_len_including_sentinel); |
| 23993 | mem.set(Value, elems, repeated_val); | |
| 23993 | if (elems.len > 0) elems[0] = repeated_val; | |
| 23994 | for (elems[1..]) |*elem| { | |
| 23995 | elem.* = try repeated_val.copy(arena); | |
| 23996 | } | |
| 23994 | 23997 | |
| 23995 | 23998 | val_ptr.* = try Value.Tag.aggregate.create(arena, elems); |
| 23996 | 23999 |
test/behavior/eval.zig+17| ... | ... | @@ -1293,3 +1293,20 @@ test "mutate through pointer-like optional at comptime" { |
| 1293 | 1293 | try expect(payload_ptr.*.* == 16); |
| 1294 | 1294 | } |
| 1295 | 1295 | } |
| 1296 | ||
| 1297 | test "repeated value is correctly expanded" { | |
| 1298 | const S = struct { x: [4]i8 = std.mem.zeroes([4]i8) }; | |
| 1299 | const M = struct { x: [4]S = std.mem.zeroes([4]S) }; | |
| 1300 | ||
| 1301 | comptime { | |
| 1302 | var res = M{}; | |
| 1303 | for (.{ 1, 2, 3 }) |i| res.x[i].x[i] = i; | |
| 1304 | ||
| 1305 | try expectEqual(M{ .x = .{ | |
| 1306 | .{ .x = .{ 0, 0, 0, 0 } }, | |
| 1307 | .{ .x = .{ 0, 1, 0, 0 } }, | |
| 1308 | .{ .x = .{ 0, 0, 2, 0 } }, | |
| 1309 | .{ .x = .{ 0, 0, 0, 3 } }, | |
| 1310 | } }, res); | |
| 1311 | } | |
| 1312 | } |