astgen.zig: fix emitting wrong error unwrapping instructions in tryExpr

This commit is contained in:
Matthew Borkowski 2021-10-18 23:10:47 -04:00 committed by Andrew Kelley
parent ec3ed92f48
commit 135cb529de
2 changed files with 14 additions and 1 deletions

View File

@ -4912,7 +4912,7 @@ fn tryExpr(
.ref => .ref,
else => .none,
};
const err_ops = switch (rl) {
const err_ops = switch (operand_rl) {
// zig fmt: off
.ref => [3]Zir.Inst.Tag{ .is_non_err_ptr, .err_union_code_ptr, .err_union_payload_unsafe_ptr },
else => [3]Zir.Inst.Tag{ .is_non_err, .err_union_code, .err_union_payload_unsafe },

View File

@ -501,6 +501,19 @@ pub fn addCases(ctx: *TestContext) !void {
\\ return 69 - i;
\\}
, "");
case.addCompareOutput(
\\const E = error{e};
\\const S = struct { x: u32 };
\\fn f() E!u32 {
\\ const x = (try @as(E!S, S{ .x = 1 })).x;
\\ return x;
\\}
\\pub export fn main() c_int {
\\ const x = f() catch @as(u32, 0);
\\ if (x != 1) unreachable;
\\ return 0;
\\}
, "");
}
{