master
1const std = @import("std");
2
3const Error = error{InvalidCharacter};
4
5const Direction = enum { upside_down };
6
7const Barrrr = union(enum) {
8 float: f64,
9 direction: Direction,
10};
11
12fn fooey(bar: std.meta.Tag(Barrrr), args: []const []const u8) !Barrrr {
13 return switch (bar) {
14 .float => .{ .float = try std.fmt.parseFloat(f64, args[0]) },
15 .direction => if (std.mem.eql(u8, args[0], "upside_down"))
16 Barrrr{ .direction = .upside_down }
17 else
18 error.InvalidDirection,
19 };
20}
21
22pub fn main() Error!void {
23 std.debug.print("{}", .{try fooey(.direction, &[_][]const u8{ "one", "two", "three" })});
24}
25
26// error
27// target=x86_64-linux
28//
29// :23:29: error: expected type 'error{InvalidCharacter}', found '@typeInfo(@typeInfo(@TypeOf(tmp.fooey)).@"fn".return_type.?).error_union.error_set'
30// :23:29: note: 'error.InvalidDirection' not a member of destination error set