authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-02-19 17:36:35-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-02-19 21:18:27-07:00
log53104b91656182094a4048964f6a3f384e7f199f
treee9937b4e507bdb4d54bc7d564e1c493f0eb24a53
parent476bdc8b0b02cbd09f6a856aa7dc548dea565109

add test coverage for fixed bug. closes #5410


1 files changed, 31 insertions(+), 0 deletions(-)

test/cases/compile_errors/error_set_membership.zig created+31
...@@ -0,0 +1,31 @@
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// backend=llvm
28// target=native
29//
30// :23:29: error: expected type 'error{InvalidCharacter}', found '@typeInfo(@typeInfo(@TypeOf(tmp.fooey)).Fn.return_type.?).ErrorUnion.error_set'
31// :23:29: note: 'error.InvalidDirection' not a member of destination error set