fix implicit cast vector to array

This commit is contained in:
Andrew Kelley 2019-06-25 13:57:45 -04:00
parent c61e0a078c
commit cb55803a59
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
2 changed files with 16 additions and 0 deletions

View File

@ -12283,6 +12283,9 @@ static IrInstruction *ir_analyze_vector_to_array(IrAnalyze *ira, IrInstruction *
result->value.type = array_type;
return result;
}
if (result_loc == nullptr) {
result_loc = no_result_loc();
}
IrInstruction *result_loc_inst = ir_resolve_result(ira, source_instr, result_loc, array_type, nullptr, true, false);
if (type_is_invalid(result_loc_inst->value.type) || instr_is_unreachable(result_loc_inst)) {
return result_loc_inst;

View File

@ -61,3 +61,16 @@ test "vector bit operators" {
S.doTheTest();
comptime S.doTheTest();
}
test "implicit cast vector to array" {
const S = struct {
fn doTheTest() void {
var a: @Vector(4, i32) = [_]i32{ 1, 2, 3, 4 };
var result_array: [4]i32 = a;
result_array = a;
expect(mem.eql(i32, result_array, [4]i32{ 1, 2, 3, 4 }));
}
};
S.doTheTest();
comptime S.doTheTest();
}