Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 11 additions & 31 deletions src/AstGen.zig
Original file line number Diff line number Diff line change
Expand Up @@ -886,33 +886,6 @@ fn expr(gz: *GenZir, scope: *Scope, rl: ResultLoc, node: Ast.Node.Index) InnerEr
catch_token + 2
else
null;

var rhs = node_datas[node].rhs;
while (true) switch (node_tags[rhs]) {
.grouped_expression => rhs = node_datas[rhs].lhs,
.unreachable_literal => {
if (payload_token != null and mem.eql(u8, tree.tokenSlice(payload_token.?), "_")) {
return astgen.failTok(payload_token.?, "discard of error capture; omit it instead", .{});
} else if (payload_token != null) {
return astgen.failTok(payload_token.?, "unused capture", .{});
}
const lhs = node_datas[node].lhs;

const operand = try reachableExpr(gz, scope, switch (rl) {
.ref => .ref,
else => .none,
}, lhs, lhs);
const result = try gz.addUnNode(switch (rl) {
.ref => .err_union_payload_safe_ptr,
else => .err_union_payload_safe,
}, operand, node);
switch (rl) {
.none, .coerced_ty, .discard, .ref => return result,
else => return rvalue(gz, rl, result, lhs),
}
},
else => break,
};
switch (rl) {
.ref => return orelseCatchExpr(
gz,
Expand Down Expand Up @@ -2377,9 +2350,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
.optional_payload_unsafe,
.optional_payload_safe_ptr,
.optional_payload_unsafe_ptr,
.err_union_payload_safe,
.err_union_payload_unsafe,
.err_union_payload_safe_ptr,
.err_union_payload_unsafe_ptr,
.err_union_code,
.err_union_code_ptr,
Expand Down Expand Up @@ -2556,6 +2527,7 @@ fn addEnsureResult(gz: *GenZir, maybe_unused_result: Zir.Inst.Ref, statement: As
.validate_array_init_ty,
.validate_struct_init_ty,
.validate_deref,
.reset_err_ret_index,
=> break :b true,

.@"defer" => unreachable,
Expand Down Expand Up @@ -5233,7 +5205,7 @@ fn orelseCatchExpr(
// instructions or not.

const break_tag: Zir.Inst.Tag = if (parent_gz.force_comptime) .break_inline else .@"break";
return finishThenElseBlock(
const result = try finishThenElseBlock(
parent_gz,
rl,
node,
Expand All @@ -5248,6 +5220,10 @@ fn orelseCatchExpr(
block,
break_tag,
);
if (astgen.fn_block != null and (cond_op == .is_non_err or cond_op == .is_non_err_ptr)) {
_ = try parent_gz.addNode(.reset_err_ret_index, node);
}
return result;
}

/// Supports `else_scope` stacked on `then_scope` stacked on `block_scope`. Unstacks `else_scope` then `then_scope`.
Expand Down Expand Up @@ -5610,7 +5586,7 @@ fn ifExpr(
};

const break_tag: Zir.Inst.Tag = if (parent_gz.force_comptime) .break_inline else .@"break";
return finishThenElseBlock(
const result = try finishThenElseBlock(
parent_gz,
rl,
node,
Expand All @@ -5625,6 +5601,10 @@ fn ifExpr(
block,
break_tag,
);
if (astgen.fn_block != null and if_full.error_token != null) {
_ = try parent_gz.addNode(.reset_err_ret_index, node);
}
return result;
}

/// Supports `else_scope` stacked on `then_scope`. Unstacks `else_scope` then `then_scope`.
Expand Down
Loading