From 9b4a52916472f39a0a9e6d0807240e304a9e9ca6 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 5 Nov 2019 12:36:39 -0500 Subject: [PATCH] fix initialization of vector in a struct field --- src/ir.cpp | 2 +- test/stage1/behavior/vector.zig | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/ir.cpp b/src/ir.cpp index 0c75fe7c19..d4687e5adb 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -17640,7 +17640,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct return ira->codegen->invalid_instruction; if (array_ptr_val->special == ConstValSpecialUndef && elem_ptr_instruction->init_array_type != nullptr) { - if (array_type->id == ZigTypeIdArray) { + if (array_type->id == ZigTypeIdArray || array_type->id == ZigTypeIdVector) { array_ptr_val->data.x_array.special = ConstArraySpecialNone; array_ptr_val->data.x_array.data.s_none.elements = create_const_vals(array_type->data.array.len); array_ptr_val->special = ConstValSpecialStatic; diff --git a/test/stage1/behavior/vector.zig b/test/stage1/behavior/vector.zig index d7dc7b5763..f747f7c184 100644 --- a/test/stage1/behavior/vector.zig +++ b/test/stage1/behavior/vector.zig @@ -234,3 +234,19 @@ test "store vector elements via runtime index" { S.doTheTest(); comptime S.doTheTest(); } + +test "initialize vector which is a struct field" { + const Vec4Obj = struct { + data: @Vector(4, f32), + }; + + const S = struct { + fn doTheTest() void { + var foo = Vec4Obj{ + .data = [_]f32{ 1, 2, 3, 4 }, + }; + } + }; + S.doTheTest(); + comptime S.doTheTest(); +}