mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-03-09 05:26:39 +01:00
backend=auto (now the default if backend is omitted) means to let the compiler pick whatever backend it wants as the default. This is important for platforms where we don't yet have a self-hosted backend, such as loongarch64. Also purge a bunch of redundant target=native.
30 lines
916 B
Zig
30 lines
916 B
Zig
const std = @import("std");
|
|
|
|
const Error = error{InvalidCharacter};
|
|
|
|
const Direction = enum { upside_down };
|
|
|
|
const Barrrr = union(enum) {
|
|
float: f64,
|
|
direction: Direction,
|
|
};
|
|
|
|
fn fooey(bar: std.meta.Tag(Barrrr), args: []const []const u8) !Barrrr {
|
|
return switch (bar) {
|
|
.float => .{ .float = try std.fmt.parseFloat(f64, args[0]) },
|
|
.direction => if (std.mem.eql(u8, args[0], "upside_down"))
|
|
Barrrr{ .direction = .upside_down }
|
|
else
|
|
error.InvalidDirection,
|
|
};
|
|
}
|
|
|
|
pub fn main() Error!void {
|
|
std.debug.print("{}", .{try fooey(.direction, &[_][]const u8{ "one", "two", "three" })});
|
|
}
|
|
|
|
// error
|
|
// target=x86_64-linux
|
|
//
|
|
// :23:29: error: expected type 'error{InvalidCharacter}', found '@typeInfo(@typeInfo(@TypeOf(tmp.fooey)).@"fn".return_type.?).error_union.error_set'
|
|
// :23:29: note: 'error.InvalidDirection' not a member of destination error set
|