From 3a4d565254f918bc949179f0f5a6934ef43b4f0d Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 16 Jul 2023 21:16:40 -0700 Subject: [PATCH] Sema: fix zirStoreNode crash when other function's inferred error set is the return type of a function, it should not try to insert the error set into it. this implies that this branch fixes a bug in master branch. --- src/Sema.zig | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index 805de066ca..e95c248428 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -5282,12 +5282,10 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v // %b = store(%a, %c) // Where %c is an error union or error set. In such case we need to add // to the current function's inferred error set, if any. - if (is_ret and (sema.typeOf(operand).zigTypeTag(mod) == .ErrorUnion or - sema.typeOf(operand).zigTypeTag(mod) == .ErrorSet) and - sema.fn_ret_ty.zigTypeTag(mod) == .ErrorUnion) - { - try sema.addToInferredErrorSet(operand); - } + if (is_ret and sema.fn_ret_ty_ies != null) switch (sema.typeOf(operand).zigTypeTag(mod)) { + .ErrorUnion, .ErrorSet => try sema.addToInferredErrorSet(operand), + else => {}, + }; const ptr_src: LazySrcLoc = .{ .node_offset_store_ptr = inst_data.src_node }; const operand_src: LazySrcLoc = .{ .node_offset_store_operand = inst_data.src_node };