commit cb55803a59d4fe99b527dc3ffc5674666511f729 (tree)
parent c61e0a078cea2a6845ed7b03189409829d2cdf24
Author: Andrew Kelley <andrew@ziglang.org>
Date: Tue, 25 Jun 2019 13:57:45 -0400
fix implicit cast vector to array
Diffstat:
2 files changed, 16 insertions(+), 0 deletions(-)
diff --git a/src/ir.cpp b/src/ir.cpp
@@ -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;
diff --git a/test/stage1/behavior/vector.zig b/test/stage1/behavior/vector.zig
@@ -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();
+}