authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-07 22:33:05-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-07 22:33:05-05:00
log68238d5678a4c055bb6f1206254dcac2e0c634f0
tree71a5f9fa0fd77dc078b0a091775ca84b0e006eae
parentf99b8b006fe458ee717acc6c8de6170fc453acb7

fix comptime fn execution not returning error unions properly


1 files changed, 14 insertions(+), 8 deletions(-)

src/ir.cpp+14-8
...@@ -9361,6 +9361,15 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp...@@ -9361,6 +9361,15 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
9361 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));9361 ir_add_error_node(ira, source_node, buf_sprintf("operator not allowed for errors"));
9362 return ira->codegen->builtin_types.entry_invalid;9362 return ira->codegen->builtin_types.entry_invalid;
9363 }9363 }
9364 TypeTableEntry *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node);
9365 if (type_is_invalid(intersect_type)) {
9366 return ira->codegen->builtin_types.entry_invalid;
9367 }
9368
9369 if (!resolve_inferred_error_set(ira, intersect_type, source_node)) {
9370 return ira->codegen->builtin_types.entry_invalid;
9371 }
9372
9364 // exception if one of the operators has the type of the empty error set, we allow the comparison9373 // exception if one of the operators has the type of the empty error set, we allow the comparison
9365 // (and make it comptime known)9374 // (and make it comptime known)
9366 // this is a function which is evaluated at comptime and returns an inferred error set will have an empty9375 // 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...@@ -9379,14 +9388,6 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
9379 out_val->data.x_bool = answer;9388 out_val->data.x_bool = answer;
9380 return ira->codegen->builtin_types.entry_bool;9389 return ira->codegen->builtin_types.entry_bool;
9381 }9390 }
9382 TypeTableEntry *intersect_type = get_error_set_intersection(ira, op1->value.type, op2->value.type, source_node);
9383 if (type_is_invalid(intersect_type)) {
9384 return ira->codegen->builtin_types.entry_invalid;
9385 }
9386
9387 if (!resolve_inferred_error_set(ira, intersect_type, source_node)) {
9388 return ira->codegen->builtin_types.entry_invalid;
9389 }
93909391
9391 if (!type_is_global_error_set(intersect_type)) {9392 if (!type_is_global_error_set(intersect_type)) {
9392 if (intersect_type->data.error_set.err_count == 0) {9393 if (intersect_type->data.error_set.err_count == 0) {
...@@ -10940,6 +10941,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -10940,6 +10941,11 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
10940 if (inferred_err_set_type != nullptr) {10941 if (inferred_err_set_type != nullptr) {
10941 inferred_err_set_type->data.error_set.infer_fn = nullptr;10942 inferred_err_set_type->data.error_set.infer_fn = nullptr;
10942 if (result->value.type->id == TypeTableEntryIdErrorUnion) {10943 if (result->value.type->id == TypeTableEntryIdErrorUnion) {
10944 if (result->value.data.x_err_union.err != nullptr) {
10945 inferred_err_set_type->data.error_set.err_count = 1;
10946 inferred_err_set_type->data.error_set.errors = allocate<ErrorTableEntry *>(1);
10947 inferred_err_set_type->data.error_set.errors[0] = result->value.data.x_err_union.err;
10948 }
10943 TypeTableEntry *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type;10949 TypeTableEntry *fn_inferred_err_set_type = result->value.type->data.error_union.err_set_type;
10944 inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count;10950 inferred_err_set_type->data.error_set.err_count = fn_inferred_err_set_type->data.error_set.err_count;
10945 inferred_err_set_type->data.error_set.errors = fn_inferred_err_set_type->data.error_set.errors;10951 inferred_err_set_type->data.error_set.errors = fn_inferred_err_set_type->data.error_set.errors;