blob: b87513d51003d02757628522d752a634af8b813a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
const std = @import("std");
const builtin = @import("builtin");
const expect = std.testing.expect;
const U = union(enum) {
x: u128,
y: [17]u8,
};
fn foo(val: U) !void {
try expect(val.x == 1);
}
test "runtime union init, most-aligned field != largest" {
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
var x: u8 = 1;
try foo(.{ .x = x });
const val: U = @unionInit(U, "x", x);
try expect(val.x == 1);
const val2: U = .{ .x = x };
try expect(val2.x == 1);
}
|