Sema: always allow coercing error set to current inferred error set

This commit is contained in:
Veikka Tuominen
2022-03-12 11:36:05 +02:00
parent 07cc2fce2a
commit a3cfb15fb4
2 changed files with 22 additions and 0 deletions

View File

@@ -16692,6 +16692,13 @@ fn coerceInMemoryAllowedErrorSets(
else => unreachable,
}
if (dst_ies.func == sema.owner_func) {
// We are trying to coerce an error set to the current function's
// inferred error set.
try dst_ies.addErrorSet(sema.gpa, src_ty);
return .ok;
}
try sema.resolveInferredErrorSet(block, dest_src, dst_payload.data);
// isAnyError might have changed from a false negative to a true positive after resolution.
if (dest_ty.isAnyError()) {

View File

@@ -634,3 +634,18 @@ test "peer type resolution of two different error unions" {
const err = if (cond) a else b;
try err;
}
test "coerce error set to the current inferred error set" {
const S = struct {
fn foo() !void {
var a = false;
if (a) {
const b: error{A}!void = error.A;
return b;
}
const b = error.A;
return b;
}
};
S.foo() catch {};
}