authorgravatar for matthew.h.borkowski@gmail.comMatthew Borkowski <matthew.h.borkowski@gmail.com> 2021-10-18 23:10:47-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-10-19 13:44:48-04:00
log135cb529def1d77e2e7e3edb641c37fb0cb47f2e
tree3630e4cf3afd2df6b6e3e851a98af21fc54ee5f9
parentec3ed92f48097c70791dda9e5cf20086776d26ce

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


2 files changed, 14 insertions(+), 1 deletions(-)

src/AstGen.zig+1-1
......@@ -4912,7 +4912,7 @@ fn tryExpr(
49124912 .ref => .ref,
49134913 else => .none,
49144914 };
4915 const err_ops = switch (rl) {
4915 const err_ops = switch (operand_rl) {
49164916 // zig fmt: off
49174917 .ref => [3]Zir.Inst.Tag{ .is_non_err_ptr, .err_union_code_ptr, .err_union_payload_unsafe_ptr },
49184918 else => [3]Zir.Inst.Tag{ .is_non_err, .err_union_code, .err_union_payload_unsafe },
test/stage2/cbe.zig+13
......@@ -501,6 +501,19 @@ pub fn addCases(ctx: *TestContext) !void {
501501 \\ return 69 - i;
502502 \\}
503503 , "");
504 case.addCompareOutput(
505 \\const E = error{e};
506 \\const S = struct { x: u32 };
507 \\fn f() E!u32 {
508 \\ const x = (try @as(E!S, S{ .x = 1 })).x;
509 \\ return x;
510 \\}
511 \\pub export fn main() c_int {
512 \\ const x = f() catch @as(u32, 0);
513 \\ if (x != 1) unreachable;
514 \\ return 0;
515 \\}
516 , "");
504517 }
505518
506519 {