| author | |
| committer | |
| log | b55b8e7745316a8e3acd4be8f2e3651d6225c710 |
| tree | 2ae91e49c4624754449db88ba6a3858ebf4d2fd8 |
| parent | bc4d9f3aa93ad58f9cbc75021dc297f29dcf2961 |
This fixes a crash when @compileLog is passed a slice backed by an aggregate field at comptime.2 files changed, 41 insertions(+), 0 deletions(-)
src/value.zig+9| ... | ... | @@ -3002,6 +3002,15 @@ pub const Value = extern union { |
| 3002 | 3002 | const data = val.castTag(.elem_ptr).?.data; |
| 3003 | 3003 | return data.array_ptr.elemValueAdvanced(mod, index + data.index, arena, buffer); |
| 3004 | 3004 | }, |
| 3005 | .field_ptr => { | |
| 3006 | const data = val.castTag(.field_ptr).?.data; | |
| 3007 | if (data.container_ptr.pointerDecl()) |decl_index| { | |
| 3008 | const container_decl = mod.declPtr(decl_index); | |
| 3009 | const field_type = data.container_ty.structFieldType(data.field_index); | |
| 3010 | const field_val = container_decl.val.fieldValue(field_type, data.field_index); | |
| 3011 | return field_val.elemValueAdvanced(mod, index, arena, buffer); | |
| 3012 | } else unreachable; | |
| 3013 | }, | |
| 3005 | 3014 | |
| 3006 | 3015 | // The child type of arrays which have only one possible value need |
| 3007 | 3016 | // to have only one possible value itself. |
test/cases/comptime_aggregate_print.zig created+32| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | const UnionContainer = union { | |
| 2 | buf: [2]i32, | |
| 3 | }; | |
| 4 | ||
| 5 | fn getUnionSlice() []i32 { | |
| 6 | var c = UnionContainer{ .buf = .{ 1, 2 } }; | |
| 7 | return c.buf[0..2]; | |
| 8 | } | |
| 9 | ||
| 10 | const StructContainer = struct { | |
| 11 | buf: [2]i32, | |
| 12 | }; | |
| 13 | ||
| 14 | fn getStructSlice() []i32 { | |
| 15 | var c = StructContainer{ .buf = .{ 3, 4 } }; | |
| 16 | return c.buf[0..2]; | |
| 17 | } | |
| 18 | ||
| 19 | comptime { | |
| 20 | @compileLog(getUnionSlice()); | |
| 21 | @compileLog(getStructSlice()); | |
| 22 | } | |
| 23 | ||
| 24 | pub fn main() !void {} | |
| 25 | ||
| 26 | // error | |
| 27 | // | |
| 28 | // :20:5: error: found compile log statement | |
| 29 | // | |
| 30 | // Compile Log Output: | |
| 31 | // @as([]i32, .{ 1, 2 }) | |
| 32 | // @as([]i32, .{ 3, 4 }) |