mirror of
https://github.com/ziglang/zig.git
synced 2025-12-24 23:23:07 +00:00
parent
49a270b203
commit
40447b25e8
@ -23990,7 +23990,10 @@ fn beginComptimePtrMutation(
|
||||
const array_len_including_sentinel =
|
||||
try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel());
|
||||
const elems = try arena.alloc(Value, array_len_including_sentinel);
|
||||
mem.set(Value, elems, repeated_val);
|
||||
if (elems.len > 0) elems[0] = repeated_val;
|
||||
for (elems[1..]) |*elem| {
|
||||
elem.* = try repeated_val.copy(arena);
|
||||
}
|
||||
|
||||
val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
|
||||
|
||||
|
||||
@ -1293,3 +1293,20 @@ test "mutate through pointer-like optional at comptime" {
|
||||
try expect(payload_ptr.*.* == 16);
|
||||
}
|
||||
}
|
||||
|
||||
test "repeated value is correctly expanded" {
|
||||
const S = struct { x: [4]i8 = std.mem.zeroes([4]i8) };
|
||||
const M = struct { x: [4]S = std.mem.zeroes([4]S) };
|
||||
|
||||
comptime {
|
||||
var res = M{};
|
||||
for (.{ 1, 2, 3 }) |i| res.x[i].x[i] = i;
|
||||
|
||||
try expectEqual(M{ .x = .{
|
||||
.{ .x = .{ 0, 0, 0, 0 } },
|
||||
.{ .x = .{ 0, 1, 0, 0 } },
|
||||
.{ .x = .{ 0, 0, 2, 0 } },
|
||||
.{ .x = .{ 0, 0, 0, 3 } },
|
||||
} }, res);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user