mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
20 lines
361 B
Zig
20 lines
361 B
Zig
const std = @import("std");
|
|
const expect = std.testing.expect;
|
|
|
|
const Number = union {
|
|
int: i32,
|
|
float: f64,
|
|
};
|
|
|
|
test "anonymous union literal syntax" {
|
|
const i: Number = .{ .int = 42 };
|
|
const f = makeNumber();
|
|
try expect(i.int == 42);
|
|
try expect(f.float == 12.34);
|
|
}
|
|
|
|
fn makeNumber() Number {
|
|
return .{ .float = 12.34 };
|
|
}
|
|
|
|
// test
|