| ... | @@ -4487,7 +4487,7 @@ fn zirTryOperandTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: boo | ... | @@ -4487,7 +4487,7 @@ fn zirTryOperandTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: boo |
| 4487 | break :ty operand_ty.childType(zcu); | 4487 | break :ty operand_ty.childType(zcu); |
| 4488 | } else operand_ty; | 4488 | } else operand_ty; |
| 4489 | | 4489 | |
| 4490 | const err_set_ty = err_set: { | 4490 | const err_set_ty: Type = err_set: { |
| 4491 | // There are awkward cases, like `?E`. Our strategy is to repeatedly unwrap optionals | 4491 | // There are awkward cases, like `?E`. Our strategy is to repeatedly unwrap optionals |
| 4492 | // until we hit an error union or set. | 4492 | // until we hit an error union or set. |
| 4493 | var cur_ty = sema.fn_ret_ty; | 4493 | var cur_ty = sema.fn_ret_ty; |
| ... | @@ -4496,16 +4496,12 @@ fn zirTryOperandTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: boo | ... | @@ -4496,16 +4496,12 @@ fn zirTryOperandTy(sema: *Sema, block: *Block, inst: Zir.Inst.Index, is_ref: boo |
| 4496 | .error_set => break :err_set cur_ty, | 4496 | .error_set => break :err_set cur_ty, |
| 4497 | .error_union => break :err_set cur_ty.errorUnionSet(zcu), | 4497 | .error_union => break :err_set cur_ty.errorUnionSet(zcu), |
| 4498 | .optional => cur_ty = cur_ty.optionalChild(zcu), | 4498 | .optional => cur_ty = cur_ty.optionalChild(zcu), |
| 4499 | else => return sema.failWithOwnedErrorMsg(block, msg: { | 4499 | else => { |
| 4500 | const msg = try sema.errMsg(src, "expected '{}', found error set", .{sema.fn_ret_ty.fmt(pt)}); | 4500 | // This function cannot return an error. |
| 4501 | errdefer msg.destroy(sema.gpa); | 4501 | // `try` is still valid if the error case is impossible, i.e. no error is returned. |
| 4502 | const ret_ty_src: LazySrcLoc = .{ | 4502 | // So, the result type has an error set of `error{}`. |
| 4503 | .base_node_inst = sema.getOwnerFuncDeclInst(), | 4503 | break :err_set .fromInterned(try zcu.intern_pool.getErrorSetType(zcu.gpa, pt.tid, &.{})); |
| 4504 | .offset = .{ .node_offset_fn_type_ret_ty = 0 }, | 4504 | }, |
| 4505 | }; | | |
| 4506 | try sema.errNote(ret_ty_src, msg, "function cannot return an error", .{}); | | |
| 4507 | break :msg msg; | | |
| 4508 | }), | | |
| 4509 | } | 4505 | } |
| 4510 | } | 4506 | } |
| 4511 | }; | 4507 | }; |