about summary refs log tree commit diff
path: root/lang/zig/error-set.zig
diff options
context:
space:
mode:
Diffstat (limited to 'lang/zig/error-set.zig')
-rw-r--r--lang/zig/error-set.zig22
1 files changed, 22 insertions, 0 deletions
diff --git a/lang/zig/error-set.zig b/lang/zig/error-set.zig
new file mode 100644
index 0000000..60b01aa
--- /dev/null
+++ b/lang/zig/error-set.zig
@@ -0,0 +1,22 @@
+const expect = @import("std").testing.expect;
+const FileOpenError = error { AccessDenied, OutOfMemory, FileNotFound };
+const AllocationError = error { OutOfMemory };
+
+fn foo(err: AllocationError) FileOpenError {
+    return err;
+}
+
+test "coerce subset to superset" {
+    const err = foo(AllocationError.OutOfMemory);
+    expect(err == FileOpenError.OutOfMemory);
+    expect(err == AllocationError.OutOfMemory);
+    expect(err == error.OutOfMemory);
+}
+
+fn bar(err: FileOpenError) AllocationError {
+    return err;
+}
+
+test "coerce superset to subset" {
+    bar(FileOpenError.OutOfMemory) catch {};
+}