| ... | ... | @@ -11253,7 +11253,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11253 | 11253 | var spa: SwitchProngAnalysis = .{ |
| 11254 | 11254 | .sema = sema, |
| 11255 | 11255 | .parent_block = block, |
| 11256 | | .operand = raw_operand_val, |
| 11256 | .operand = undefined, // must be set to the unwrapped error code before use |
| 11257 | 11257 | .operand_ptr = .none, |
| 11258 | 11258 | .cond = raw_operand_val, |
| 11259 | 11259 | .else_error_ty = else_error_ty, |
| ... | ... | @@ -11387,6 +11387,7 @@ fn zirSwitchBlockErrUnion(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Comp |
| 11387 | 11387 | undefined, |
| 11388 | 11388 | undefined, |
| 11389 | 11389 | cond_dbg_node_index, |
| 11390 | true, |
| 11390 | 11391 | ); |
| 11391 | 11392 | |
| 11392 | 11393 | try sema.air_extra.ensureUnusedCapacity(gpa, @typeInfo(Air.CondBr).Struct.fields.len + |
| ... | ... | @@ -11970,7 +11971,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 11970 | 11971 | if (special_prong == .none) { |
| 11971 | 11972 | return sema.fail(block, src, "switch must handle all possibilities", .{}); |
| 11972 | 11973 | } |
| 11973 | | if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand, operand_src)) { |
| 11974 | if (err_set and try sema.maybeErrorUnwrap(block, special.body, operand, operand_src, false)) { |
| 11974 | 11975 | return .unreachable_value; |
| 11975 | 11976 | } |
| 11976 | 11977 | if (mod.backendSupportsFeature(.is_named_enum_value) and block.wantSafety() and operand_ty.zigTypeTag(mod) == .Enum and |
| ... | ... | @@ -12024,6 +12025,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r |
| 12024 | 12025 | true_count, |
| 12025 | 12026 | false_count, |
| 12026 | 12027 | cond_dbg_node_index, |
| 12028 | false, |
| 12027 | 12029 | ); |
| 12028 | 12030 | |
| 12029 | 12031 | return sema.analyzeBlockBody(block, src, &child_block, merges); |
| ... | ... | @@ -12060,6 +12062,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12060 | 12062 | true_count: u8, |
| 12061 | 12063 | false_count: u8, |
| 12062 | 12064 | cond_dbg_node_index: Zir.Inst.Index, |
| 12065 | allow_err_code_unwrap: bool, |
| 12063 | 12066 | ) CompileError!Air.Inst.Ref { |
| 12064 | 12067 | const mod = sema.mod; |
| 12065 | 12068 | const gpa = sema.gpa; |
| ... | ... | @@ -12101,7 +12104,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12101 | 12104 | break :blk field_ty.zigTypeTag(mod) != .NoReturn; |
| 12102 | 12105 | } else true; |
| 12103 | 12106 | |
| 12104 | | if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src)) { |
| 12107 | if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src, allow_err_code_unwrap)) { |
| 12105 | 12108 | // nothing to do here |
| 12106 | 12109 | } else if (analyze_body) { |
| 12107 | 12110 | try spa.analyzeProngRuntime( |
| ... | ... | @@ -12285,7 +12288,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12285 | 12288 | |
| 12286 | 12289 | const body = sema.code.bodySlice(extra_index, info.body_len); |
| 12287 | 12290 | extra_index += info.body_len; |
| 12288 | | if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src)) { |
| 12291 | if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src, allow_err_code_unwrap)) { |
| 12289 | 12292 | // nothing to do here |
| 12290 | 12293 | } else if (analyze_body) { |
| 12291 | 12294 | try spa.analyzeProngRuntime( |
| ... | ... | @@ -12369,7 +12372,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12369 | 12372 | |
| 12370 | 12373 | const body = sema.code.bodySlice(extra_index, info.body_len); |
| 12371 | 12374 | extra_index += info.body_len; |
| 12372 | | if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src)) { |
| 12375 | if (err_set and try sema.maybeErrorUnwrap(&case_block, body, operand, operand_src, allow_err_code_unwrap)) { |
| 12373 | 12376 | // nothing to do here |
| 12374 | 12377 | } else { |
| 12375 | 12378 | try spa.analyzeProngRuntime( |
| ... | ... | @@ -12612,7 +12615,7 @@ fn analyzeSwitchRuntimeBlock( |
| 12612 | 12615 | else |
| 12613 | 12616 | true; |
| 12614 | 12617 | if (special.body.len != 0 and err_set and |
| 12615 | | try sema.maybeErrorUnwrap(&case_block, special.body, operand, operand_src)) |
| 12618 | try sema.maybeErrorUnwrap(&case_block, special.body, operand, operand_src, allow_err_code_unwrap)) |
| 12616 | 12619 | { |
| 12617 | 12620 | // nothing to do here |
| 12618 | 12621 | } else if (special.body.len != 0 and analyze_body and !special.is_inline) { |
| ... | ... | @@ -13266,7 +13269,14 @@ fn validateSwitchNoRange( |
| 13266 | 13269 | return sema.failWithOwnedErrorMsg(block, msg); |
| 13267 | 13270 | } |
| 13268 | 13271 | |
| 13269 | | fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, operand: Air.Inst.Ref, operand_src: LazySrcLoc) !bool { |
| 13272 | fn maybeErrorUnwrap( |
| 13273 | sema: *Sema, |
| 13274 | block: *Block, |
| 13275 | body: []const Zir.Inst.Index, |
| 13276 | operand: Air.Inst.Ref, |
| 13277 | operand_src: LazySrcLoc, |
| 13278 | allow_err_code_inst: bool, |
| 13279 | ) !bool { |
| 13270 | 13280 | const mod = sema.mod; |
| 13271 | 13281 | if (!mod.backendSupportsFeature(.panic_unwrap_error)) return false; |
| 13272 | 13282 | |
| ... | ... | @@ -13274,6 +13284,7 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 13274 | 13284 | for (body) |inst| { |
| 13275 | 13285 | switch (tags[@intFromEnum(inst)]) { |
| 13276 | 13286 | .@"unreachable" => if (!block.wantSafety()) return false, |
| 13287 | .err_union_code => if (!allow_err_code_inst) return false, |
| 13277 | 13288 | .save_err_ret_index, |
| 13278 | 13289 | .dbg_block_begin, |
| 13279 | 13290 | .dbg_block_end, |
| ... | ... | @@ -13291,6 +13302,7 @@ fn maybeErrorUnwrap(sema: *Sema, block: *Block, body: []const Zir.Inst.Index, op |
| 13291 | 13302 | const air_inst = switch (tags[@intFromEnum(inst)]) { |
| 13292 | 13303 | .dbg_block_begin, |
| 13293 | 13304 | .dbg_block_end, |
| 13305 | .err_union_code, |
| 13294 | 13306 | => continue, |
| 13295 | 13307 | .dbg_stmt => { |
| 13296 | 13308 | try sema.zirDbgStmt(block, inst); |
| ... | ... | @@ -18754,7 +18766,7 @@ fn zirCondbr( |
| 18754 | 18766 | break :blk try sub_block.addTyOp(.unwrap_errunion_err, result_ty, err_operand); |
| 18755 | 18767 | }; |
| 18756 | 18768 | |
| 18757 | | if (err_cond != null and try sema.maybeErrorUnwrap(&sub_block, else_body, err_cond.?, cond_src)) { |
| 18769 | if (err_cond != null and try sema.maybeErrorUnwrap(&sub_block, else_body, err_cond.?, cond_src, false)) { |
| 18758 | 18770 | // nothing to do |
| 18759 | 18771 | } else { |
| 18760 | 18772 | try sema.analyzeBodyRuntimeBreak(&sub_block, else_body); |