blob: f8fa18f7f81b5e4308910ef0239cfd11090f0476 (
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
29
30
31
|
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
// backend=llvm
// target=native
//
// :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
|