authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-05 12:36:39-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-11-05 12:36:39-05:00
log9b4a52916472f39a0a9e6d0807240e304a9e9ca6
tree2bf61887435fff1328211eec5072ed67bb924ece
parentcbaa10fc3bcd2d5f8d48b9038e840ae508fe2822
signaturelock-open Commit is signed but in an unrecognized format.

fix initialization of vector in a struct field


2 files changed, 17 insertions(+), 1 deletions(-)

src/ir.cpp+1-1
......@@ -17640,7 +17640,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1764017640 return ira->codegen->invalid_instruction;
1764117641
1764217642 if (array_ptr_val->special == ConstValSpecialUndef && elem_ptr_instruction->init_array_type != nullptr) {
17643 if (array_type->id == ZigTypeIdArray) {
17643 if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) {
1764417644 array_ptr_val->data.x_array.special = ConstArraySpecialNone;
1764517645 array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len);
1764617646 array_ptr_val->special = ConstValSpecialStatic;
test/stage1/behavior/vector.zig+16
......@@ -234,3 +234,19 @@ test "store vector elements via runtime index" {
234234 S.doTheTest();
235235 comptime S.doTheTest();
236236}
237
238test "initialize vector which is a struct field" {
239 const Vec4Obj = struct {
240 data: @Vector(4, f32),
241 };
242
243 const S = struct {
244 fn doTheTest() void {
245 var foo = Vec4Obj{
246 .data = [_]f32{ 1, 2, 3, 4 },
247 };
248 }
249 };
250 S.doTheTest();
251 comptime S.doTheTest();
252}