From 68238d5678a4c055bb6f1206254dcac2e0c634f0 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Wed, 7 Feb 2018 22:33:05 -0500 Subject: fix comptime fn execution not returning error unions properly --- src/ir.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index c9c73c66f3..ccd4567842 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -9361,6 +9361,15 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors")); return ira->codegen->builtin_types.entry_invalid; } + TypeTableEntry *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node); + if (type_is_invalid(intersect_type)) { + return ira->codegen->builtin_types.entry_invalid; + } + + if (!resolve_inferred_error_set(ira, intersect_type, source_node)) { + return ira->codegen->builtin_types.entry_invalid; + } + // exception if one of the operators has the type of the empty error set, we allow the comparison // (and make it comptime known) // this is a function which is evaluated at comptime and returns an inferred error set will have an empty @@ -9379,14 +9388,6 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp out_val->data.x_bool = answer; return ira->codegen->builtin_types.entry_bool; } - TypeTableEntry *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node); - if (type_is_invalid(intersect_type)) { - return ira->codegen->builtin_types.entry_invalid; - } - - if (!resolve_inferred_error_set(ira, intersect_type, source_node)) { - return ira->codegen->builtin_types.entry_invalid; - } if (!type_is_global_error_set(intersect_type)) { if (intersect_type->data.error_set.err_count == 0) { @@ -10940,6 +10941,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal if (inferred_err_set_type != nullptr) { inferred_err_set_type->data.error_set.infer_fn = nullptr; if (result->value.type->id == TypeTableEntryIdErrorUnion) { + if (result->value.data.x_err_union.err != nullptr) { + inferred_err_set_type->data.error_set.err_count = 1; + inferred_err_set_type->data.error_set.errors = allocate(1); + inferred_err_set_type->data.error_set.errors[0] = result->value.data.x_err_union.err; + } TypeTableEntry *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type; inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count; inferred_err_set_type->data.error_set.errors = fn_inferred_err_set_type->data.error_set.errors; -- cgit v1.2.3