| 1 | const std = @import("std"); |
| 2 | |
| 3 | const Error = error{InvalidCharacter}; |
| 4 | |
| 5 | const Direction = enum { upside_down }; |
| 6 | |
| 7 | const Barrrr = union(enum) { |
| 8 | float: f64, |
| 9 | direction: Direction, |
| 10 | }; |
| 11 | |
| 12 | fn 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 | |
| 22 | pub 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}!void', 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 |
| 31 | // :22:20: note: function return type declared here |