mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 23:52:31 +00:00
378d3e4403
Changed container and initializer syntax * <container> { ... } -> <container> . { ... } * <exrp> { ... } -> <expr> . { ...}
23 lines
476 B
Zig
23 lines
476 B
Zig
const assert = @import("std").debug.assert;
|
|
|
|
const FormValue = union(enum).{
|
|
One: void,
|
|
Two: bool,
|
|
};
|
|
|
|
fn foo(id: u64) !FormValue {
|
|
return switch (id) {
|
|
2 => FormValue.{ .Two = true },
|
|
1 => FormValue.{ .One = {} },
|
|
else => return error.Whatever,
|
|
};
|
|
}
|
|
|
|
test "switch prong implicit cast" {
|
|
const result = switch (foo(2) catch unreachable) {
|
|
FormValue.One => false,
|
|
FormValue.Two => |x| x,
|
|
};
|
|
assert(result);
|
|
}
|