diff --git a/src/ir.cpp b/src/ir.cpp index a263e7c24d11c25a6d9ecbfed32a28daf0a774d7..54442861ca515461616400dd511f6789fcb2b5dc 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -18177,20 +18177,20 @@ static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira, if (type_is_invalid(op2_type)) return ira->codegen->invalid_inst_gen; + if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->base.source_node)) { + return ira->codegen->invalid_inst_gen; + } + + if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->base.source_node)) { + return ira->codegen->invalid_inst_gen; + } + if (type_is_global_error_set(op1_type) || type_is_global_error_set(op2_type)) { return ir_const_type(ira, &instruction->base.base, ira->codegen->builtin_types.entry_global_error_set); } - if (!resolve_inferred_error_set(ira->codegen, op1_type, instruction->op1->child->base.source_node)) { - return ira->codegen->invalid_inst_gen; - } - - if (!resolve_inferred_error_set(ira->codegen, op2_type, instruction->op2->child->base.source_node)) { - return ira->codegen->invalid_inst_gen; - } - size_t errors_count = ira->codegen->errors_by_index.length; ErrorTableEntry **errors = heap::c_allocator.allocate(errors_count); for (uint32_t i = 0, count = op1_type->data.error_set.err_count; i < count; i += 1) { diff --git a/test/stage1/behavior.zig b/test/stage1/behavior.zig index 76ec11cdf57fa158b913996f390d7a04ecacedef..2961ffee47f3f3cb2ad3b0f78a8bc3bdfeb5e0c3 100644 --- a/test/stage1/behavior.zig +++ b/test/stage1/behavior.zig @@ -50,6 +50,7 @@ comptime { _ = @import("behavior/bugs/4769_b.zig"); _ = @import("behavior/bugs/4769_c.zig"); _ = @import("behavior/bugs/4954.zig"); + _ = @import("behavior/bugs/5487.zig"); _ = @import("behavior/bugs/394.zig"); _ = @import("behavior/bugs/421.zig"); _ = @import("behavior/bugs/529.zig"); diff --git a/test/stage1/behavior/bugs/5487.zig b/test/stage1/behavior/bugs/5487.zig new file mode 100644 index 0000000000000000000000000000000000000000..05967b6de4fd9c49c86397362cd2b4a68b459989 --- /dev/null +++ b/test/stage1/behavior/bugs/5487.zig @@ -0,0 +1,12 @@ +const io = @import("std").io; + +pub fn write(_: void, bytes: []const u8) !usize { + return 0; +} +pub fn outStream() io.OutStream(void, @TypeOf(write).ReturnType.ErrorSet, write) { + return io.OutStream(void, @TypeOf(write).ReturnType.ErrorSet, write){ .context = {} }; +} + +test "crash" { + _ = io.multiOutStream(.{outStream()}); +}