authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-16 21:16:40-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-18 19:02:06-07:00
log3a4d565254f918bc949179f0f5a6934ef43b4f0d
tree09650b4e75a2112456affb8ea90df909c5bb6c64
parent7c66bd39be82c09cf004843da058a48769066c3f

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.

1 files changed, 4 insertions(+), 6 deletions(-)

src/Sema.zig+4-6
......@@ -5282,12 +5282,10 @@ fn zirStoreNode(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!v
52825282 // %b = store(%a, %c)
52835283 // Where %c is an error union or error set. In such case we need to add
52845284 // to the current function's inferred error set, if any.
5285 if (is_ret and (sema.typeOf(operand).zigTypeTag(mod) == .ErrorUnion or
5286 sema.typeOf(operand).zigTypeTag(mod) == .ErrorSet) and
5287 sema.fn_ret_ty.zigTypeTag(mod) == .ErrorUnion)
5288 {
5289 try sema.addToInferredErrorSet(operand);
5290 }
5285 if (is_ret and sema.fn_ret_ty_ies != null) switch (sema.typeOf(operand).zigTypeTag(mod)) {
5286 .ErrorUnion, .ErrorSet => try sema.addToInferredErrorSet(operand),
5287 else => {},
5288 };
52915289
52925290 const ptr_src: LazySrcLoc = .{ .node_offset_store_ptr = inst_data.src_node };
52935291 const operand_src: LazySrcLoc = .{ .node_offset_store_operand = inst_data.src_node };