Commit 31ed8d293d
src/Sema.zig
@@ -29761,6 +29761,25 @@ fn resolvePeerTypes(
continue;
}
},
+ .ErrorSet => {
+ chosen = candidate;
+ chosen_i = candidate_i + 1;
+ if (err_set_ty) |chosen_set_ty| {
+ if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, chosen_set_ty, chosen_ty, src, src)) {
+ continue;
+ }
+ if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, chosen_ty, chosen_set_ty, src, src)) {
+ err_set_ty = chosen_ty;
+ continue;
+ }
+
+ err_set_ty = try chosen_set_ty.errorSetMerge(sema.arena, chosen_ty);
+ continue;
+ } else {
+ err_set_ty = chosen_ty;
+ continue;
+ }
+ },
else => {},
}
test/behavior/cast.zig
@@ -1541,3 +1541,15 @@ test "single item pointer to pointer to array to slice" {
const z1 = @as([]const i32, @as(*[1]i32, &x));
try expect(z1[0] == 1234);
}
+
+test "peer type resolution forms error union" {
+ if (builtin.zig_backend == .stage2_wasm) return error.SkipZigTest; // TODO
+
+ var foo: i32 = 123;
+ const result = if (foo < 0) switch (-foo) {
+ 0 => unreachable,
+ 42 => error.AccessDenied,
+ else => unreachable,
+ } else @intCast(u32, foo);
+ try expect(try result == 123);
+}