mirror of
https://github.com/ziglang/zig.git
synced 2025-12-16 03:03:09 +00:00
astgen.zig: fix emitting wrong error unwrapping instructions in tryExpr
This commit is contained in:
parent
ec3ed92f48
commit
135cb529de
@ -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 },
|
||||
|
||||
@ -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;
|
||||
\\}
|
||||
, "");
|
||||
}
|
||||
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user