mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
Compare commits
1 commit
49ef28a5f1
...
76cf731436
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
76cf731436 |
2 changed files with 35 additions and 3 deletions
10
src/Sema.zig
10
src/Sema.zig
|
|
@ -18470,6 +18470,9 @@ fn zirCondbr(
|
||||||
break :blk try sub_block.addTyOp(.unwrap_errunion_err, result_ty, err_operand);
|
break :blk try sub_block.addTyOp(.unwrap_errunion_err, result_ty, err_operand);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Reset, this may have been updated by the then block analysis
|
||||||
|
sub_block.error_return_trace_index = parent_block.error_return_trace_index;
|
||||||
|
|
||||||
const false_hint: std.builtin.BranchHint = if (err_cond != null and
|
const false_hint: std.builtin.BranchHint = if (err_cond != null and
|
||||||
try sema.maybeErrorUnwrap(&sub_block, else_body, err_cond.?, cond_src, false))
|
try sema.maybeErrorUnwrap(&sub_block, else_body, err_cond.?, cond_src, false))
|
||||||
h: {
|
h: {
|
||||||
|
|
@ -18945,9 +18948,10 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
|
||||||
while (true) {
|
while (true) {
|
||||||
if (block.label) |label| {
|
if (block.label) |label| {
|
||||||
if (label.zir_block == zir_block) {
|
if (label.zir_block == zir_block) {
|
||||||
const target_trace_index = if (block.parent) |parent_block| tgt: {
|
const target_trace_index = if (block.parent) |parent_block|
|
||||||
break :tgt parent_block.error_return_trace_index;
|
parent_block.error_return_trace_index
|
||||||
} else sema.error_return_trace_index_on_fn_entry;
|
else
|
||||||
|
sema.error_return_trace_index_on_fn_entry;
|
||||||
|
|
||||||
if (start_block.error_return_trace_index != target_trace_index)
|
if (start_block.error_return_trace_index != target_trace_index)
|
||||||
break :b target_trace_index;
|
break :b target_trace_index;
|
||||||
|
|
|
||||||
28
test/cases/issue_30095.zig
Normal file
28
test/cases/issue_30095.zig
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
var e: anyerror = undefined;
|
||||||
|
const E = error{Err};
|
||||||
|
extern fn bar() u8;
|
||||||
|
|
||||||
|
fn foo() E!u8 {
|
||||||
|
const x = bar();
|
||||||
|
return if (x != 0) E.Err else 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn main() !void {
|
||||||
|
var val: bool = false;
|
||||||
|
_ = &val;
|
||||||
|
|
||||||
|
if (val) {
|
||||||
|
const maybe = foo();
|
||||||
|
_ = maybe catch {};
|
||||||
|
} else {
|
||||||
|
if (foo()) |byte| {
|
||||||
|
_ = byte;
|
||||||
|
} else |err| {
|
||||||
|
e = err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// compile
|
||||||
|
// output_mode=Obj
|
||||||
|
//
|
||||||
Loading…
Add table
Reference in a new issue