aboutsummaryrefslogtreecommitdiff
path: root/test/behavior/vector.zig
diff options
context:
space:
mode:
authorJohn Schmidt <john.schmidt.h@gmail.com>2023-03-08 23:13:37 +0100
committerJohn Schmidt <john.schmidt.h@gmail.com>2023-03-09 00:55:33 +0100
commit0606f0aa5576122204886f1a3c9530c0ce75c044 (patch)
tree8e1c9cf9b000a60d4f98aafeb318f6814bea52a7 /test/behavior/vector.zig
parent505e720421ce4f7ed11730fe68d32e3bba711f3c (diff)
downloadzig-0606f0aa5576122204886f1a3c9530c0ce75c044.tar.gz
zig-0606f0aa5576122204886f1a3c9530c0ce75c044.zip
sema: fix result ptr coercion array -> vector
Previously this worked for array to vector where the element type matched exactly (e.g `[4]u8` to `@Vector(4, u8)`) since that is performed with a simple `.bitcast` operation, but now it also works for types where the array is coercible to the vector type (e.g `[4]u8` to `@Vector(4, u16)`).
Diffstat (limited to 'test/behavior/vector.zig')
-rw-r--r--test/behavior/vector.zig19
1 files changed, 19 insertions, 0 deletions
diff --git a/test/behavior/vector.zig b/test/behavior/vector.zig
index 2c7be227c4..b1c0e310fe 100644
--- a/test/behavior/vector.zig
+++ b/test/behavior/vector.zig
@@ -175,6 +175,25 @@ test "array to vector" {
comptime try S.doTheTest();
}
+test "array to vector with element type coercion" {
+ if (builtin.zig_backend == .stage2_wasm) 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
+ if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
+
+ const S = struct {
+ fn doTheTest() !void {
+ var foo: f16 = 3.14;
+ var arr32 = [4]f32{ foo, 1.5, 0.0, 0.0 };
+ var vec: @Vector(4, f32) = [4]f16{ foo, 1.5, 0.0, 0.0 };
+ try std.testing.expect(std.mem.eql(f32, &@as([4]f32, vec), &arr32));
+ }
+ };
+ try S.doTheTest();
+ comptime try S.doTheTest();
+}
+
test "peer type resolution with coercible element types" {
if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO