| author | |
| committer | |
| log | a3cfb15fb4be719fe11f231113020532ad0b1258 |
| tree | dc28befc2d69638d85ed51e54fa5016257471c66 |
| parent | 07cc2fce2a2745a05c65fdd1a36c3198d0ec91b4 |
2 files changed, 22 insertions(+), 0 deletions(-)
src/Sema.zig+7| ... | ... | @@ -16692,6 +16692,13 @@ fn coerceInMemoryAllowedErrorSets( |
| 16692 | 16692 | else => unreachable, |
| 16693 | 16693 | } |
| 16694 | 16694 | |
| 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 | 16702 | try sema.resolveInferredErrorSet(block, dest_src, dst_payload.data); |
| 16696 | 16703 | // isAnyError might have changed from a false negative to a true positive after resolution. |
| 16697 | 16704 | if (dest_ty.isAnyError()) { |
test/behavior/error.zig+15| ... | ... | @@ -634,3 +634,18 @@ test "peer type resolution of two different error unions" { |
| 634 | 634 | const err = if (cond) a else b; |
| 635 | 635 | try err; |
| 636 | 636 | } |
| 637 | ||
| 638 | test "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 | } |