aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2018-02-07 22:33:05 -0500
committerAndrew Kelley <superjoe30@gmail.com>2018-02-07 22:33:05 -0500
commit68238d5678a4c055bb6f1206254dcac2e0c634f0 (patch)
tree71a5f9fa0fd77dc078b0a091775ca84b0e006eae /src
parentf99b8b006fe458ee717acc6c8de6170fc453acb7 (diff)
downloadzig-68238d5678a4c055bb6f1206254dcac2e0c634f0.tar.gz
zig-68238d5678a4c055bb6f1206254dcac2e0c634f0.zip
fix comptime fn execution not returning error unions properly
Diffstat (limited to 'src')
-rw-r--r--src/ir.cpp22
1 files changed, 14 insertions, 8 deletions
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<ErrorTableEntry *>(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;