A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/ziglang/zig/issues/769 below:

else value when switching on error set should have optional capture value which is subset · Issue #769 · ziglang/zig · GitHub

pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) !void {
    if (symLink(allocator, existing_path, new_path)) {
        return;
    } else |err| switch (err) {
        error.PathAlreadyExists => {},
        else => return err, // TODO zig should know this set does not include PathAlreadyExists
    }
    ...
}

It should not be possible for atomicSymLink to return error.PathAlreadyExists.

Here's my proposal:

pub fn atomicSymLink(allocator: &Allocator, existing_path: []const u8, new_path: []const u8) !void {
    if (symLink(allocator, existing_path, new_path)) {
        return;
    } else |err| switch (err) {
        error.PathAlreadyExists => {},
        else => |subset| return subset,
    }
    ...
}

In this example, subset has exactly the same value as err, except that it has a different type. The type is @typeOf(err) except the error set does not have any of the errors covered by the switch prongs above.

If the type of subset would be error{} then the else is dead code.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4