aboutsummaryrefslogtreecommitdiff
path: root/src/type.zig
diff options
context:
space:
mode:
authorJimmi Holst Christensen <jhc@dismail.de>2022-01-06 22:18:27 +0100
committerAndrew Kelley <andrew@ziglang.org>2022-01-06 22:57:45 -0500
commit7f4fdcc4fce79cc1277c2a89a6a4136293c1b2e5 (patch)
tree8b185810946a998f3a1bdf78e13265cb07f7a8dc /src/type.zig
parent59315463f2d579d788f9af43e4e74577dfd4e21f (diff)
downloadzig-7f4fdcc4fce79cc1277c2a89a6a4136293c1b2e5.tar.gz
zig-7f4fdcc4fce79cc1277c2a89a6a4136293c1b2e5.zip
stage2: Implement validating switch on errors
Diffstat (limited to 'src/type.zig')
-rw-r--r--src/type.zig14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/type.zig b/src/type.zig
index b948093994..4ad15f2399 100644
--- a/src/type.zig
+++ b/src/type.zig
@@ -3617,6 +3617,20 @@ pub const Type = extern union {
};
}
+ // Asserts that `ty` is an error set and not `anyerror`.
+ pub fn errorSetNames(ty: Type) []const []const u8 {
+ return switch (ty.tag()) {
+ .error_set_single => blk: {
+ // Work around coercion problems
+ const tmp: *const [1][]const u8 = &ty.castTag(.error_set_single).?.data;
+ break :blk tmp;
+ },
+ .error_set_merged => ty.castTag(.error_set_merged).?.data.keys(),
+ .error_set => ty.castTag(.error_set).?.data.names.keys(),
+ else => unreachable,
+ };
+ }
+
pub fn enumFields(ty: Type) Module.EnumFull.NameMap {
return switch (ty.tag()) {
.enum_full, .enum_nonexhaustive => ty.cast(Payload.EnumFull).?.data.fields,