From b6ccde47adeb0dbd7b39150c36498100e0d98075 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 28 Mar 2022 14:17:05 -0700 Subject: Sema: allow mixing array and vector operands * Added peer type resolution for arrays and vectors: the vector type is selected. * Fixed passing the lhs type or rhs type instead of the peer resolved type when calling Value methods during analyzeArithmetic handling of comptime expressions. * `checkVectorizableBinaryOperands` now allows mixing vectors and arrays, as long as one of the operands is a vector. This matches stage1's handling of `^=` but apparently stage1 is inconsistent and does not handle e.g. `*=`. stage2 now will always allow mixing vector and array operands for all operations. --- test/behavior/vector.zig | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'test') diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig index 1651e8107b..ccf22a2094 100644 --- a/test/behavior/vector.zig +++ b/test/behavior/vector.zig @@ -879,3 +879,27 @@ test "saturating shift-left" { try S.doTheTest(); comptime try S.doTheTest(); } + +test "multiplication-assignment operator with an array operand" { + if (builtin.zig_backend == .stage1) { + // stage1 emits a compile error + return error.SkipZigTest; + } + if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO + if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO + + const S = struct { + fn doTheTest() !void { + var x: @Vector(3, i32) = .{ 1, 2, 3 }; + x *= [_]i32{ 4, 5, 6 }; + try expect(x[0] == 4); + try expect(x[1] == 10); + try expect(x[2] == 18); + } + }; + try S.doTheTest(); + comptime try S.doTheTest(); +} -- cgit v1.2.3