From cb55803a59d4fe99b527dc3ffc5674666511f729 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 25 Jun 2019 13:57:45 -0400 Subject: [PATCH] fix implicit cast vector to array --- src/ir.cpp | 3 +++ test/stage1/behavior/vector.zig | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/src/ir.cpp b/src/ir.cpp index 2991dd518..98d6cb25d 100644 --- 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 index 21bbe3160..70b47c459 100644 --- 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(); +}