Commit 250dd9ac21

xackus <14938807+xackus@users.noreply.github.com>
2020-05-31 15:04:34
stage1: fix unresolved inferred error sets
1 parent 557d75d
Changed files (3)
src
test
stage1
behavior
src/ir.cpp
@@ -18177,12 +18177,6 @@ static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
     if (type_is_invalid(op2_type))
         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;
     }
@@ -18191,6 +18185,12 @@ static IrInstGen *ir_analyze_instruction_merge_err_sets(IrAnalyze *ira,
         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);
+    }
+
     size_t errors_count = ira->codegen->errors_by_index.length;
     ErrorTableEntry **errors = heap::c_allocator.allocate<ErrorTableEntry *>(errors_count);
     for (uint32_t i = 0, count = op1_type->data.error_set.err_count; i < count; i += 1) {
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()});
+}
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");