fix initialization of vector in a struct field

This commit is contained in:
Andrew Kelley 2019-11-05 12:36:39 -05:00
parent cbaa10fc3b
commit 9b4a529164
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 17 additions and 1 deletions

View File

@ -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;

View File

@ -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();
}