authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-12 11:36:05+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-03-12 11:36:05+02:00
loga3cfb15fb4be719fe11f231113020532ad0b1258
treedc28befc2d69638d85ed51e54fa5016257471c66
parent07cc2fce2a2745a05c65fdd1a36c3198d0ec91b4

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


2 files changed, 22 insertions(+), 0 deletions(-)

src/Sema.zig+7
...@@ -16692,6 +16692,13 @@ fn coerceInMemoryAllowedErrorSets(...@@ -16692,6 +16692,13 @@ fn coerceInMemoryAllowedErrorSets(
16692 else => unreachable,16692 else => unreachable,
16693 }16693 }
1669416694
16695 if (dst_ies.func == sema.owner_func) {
16696 // We are trying to coerce an error set to the current function's
16697 // inferred error set.
16698 try dst_ies.addErrorSet(sema.gpa, src_ty);
16699 return .ok;
16700 }
16701
16695 try sema.resolveInferredErrorSet(block, dest_src, dst_payload.data);16702 try sema.resolveInferredErrorSet(block, dest_src, dst_payload.data);
16696 // isAnyError might have changed from a false negative to a true positive after resolution.16703 // isAnyError might have changed from a false negative to a true positive after resolution.
16697 if (dest_ty.isAnyError()) {16704 if (dest_ty.isAnyError()) {
test/behavior/error.zig+15
...@@ -634,3 +634,18 @@ test "peer type resolution of two different error unions" {...@@ -634,3 +634,18 @@ test "peer type resolution of two different error unions" {
634 const err = if (cond) a else b;634 const err = if (cond) a else b;
635 try err;635 try err;
636}636}
637
638test "coerce error set to the current inferred error set" {
639 const S = struct {
640 fn foo() !void {
641 var a = false;
642 if (a) {
643 const b: error{A}!void = error.A;
644 return b;
645 }
646 const b = error.A;
647 return b;
648 }
649 };
650 S.foo() catch {};
651}