| author | |
| committer | |
| log | 44fb5275c1babed97a38b4b3c97e59740a2a5cc5 |
| tree | 421673b24e4605ce0fc8290c1248ebffc4364728 |
| parent | 3f7f52003690ccee8a2a33e91258428e22761492 |
| signature |
closes #30952 files changed, 25 insertions(+), 4 deletions(-)
src/ir.cpp+5-2| ... | ... | @@ -13963,8 +13963,11 @@ static IrInstruction *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp * |
| 13963 | 13963 | uint64_t i = 0; |
| 13964 | 13964 | for (uint64_t x = 0; x < mult_amt; x += 1) { |
| 13965 | 13965 | for (uint64_t y = 0; y < old_array_len; y += 1) { |
| 13966 | copy_const_val(&out_val->data.x_array.data.s_none.elements[i], | |
| 13967 | &array_val->data.x_array.data.s_none.elements[y], false); | |
| 13966 | ConstExprValue *elem_dest_val = &out_val->data.x_array.data.s_none.elements[i]; | |
| 13967 | copy_const_val(elem_dest_val, &array_val->data.x_array.data.s_none.elements[y], false); | |
| 13968 | elem_dest_val->parent.id = ConstParentIdArray; | |
| 13969 | elem_dest_val->parent.data.p_array.array_val = out_val; | |
| 13970 | elem_dest_val->parent.data.p_array.elem_index = i; | |
| 13968 | 13971 | i += 1; |
| 13969 | 13972 | } |
| 13970 | 13973 | } |
test/stage1/behavior/array.zig+20-2| ... | ... | @@ -1,5 +1,6 @@ |
| 1 | const expect = @import("std").testing.expect; | |
| 2 | const mem = @import("std").mem; | |
| 1 | const std = @import("std"); | |
| 2 | const expect = std.testing.expect; | |
| 3 | const mem = std.mem; | |
| 3 | 4 | |
| 4 | 5 | test "arrays" { |
| 5 | 6 | var array: [5]u32 = undefined; |
| ... | ... | @@ -274,3 +275,20 @@ test "double nested array to const slice cast in array literal" { |
| 274 | 275 | S.entry(2); |
| 275 | 276 | comptime S.entry(2); |
| 276 | 277 | } |
| 278 | ||
| 279 | test "read/write through global variable array of struct fields initialized via array mult" { | |
| 280 | const S = struct { | |
| 281 | fn doTheTest() void { | |
| 282 | expect(storage[0].term == 1); | |
| 283 | storage[0] = MyStruct{ .term = 123 }; | |
| 284 | expect(storage[0].term == 123); | |
| 285 | } | |
| 286 | ||
| 287 | pub const MyStruct = struct { | |
| 288 | term: usize, | |
| 289 | }; | |
| 290 | ||
| 291 | var storage: [1]MyStruct = [_]MyStruct{MyStruct{ .term = 1 }} ** 1; | |
| 292 | }; | |
| 293 | S.doTheTest(); | |
| 294 | } |