Closed
Description
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.