aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorLemonBoy <thatlemon@gmail.com>2020-02-26 23:17:44 +0100
committerAndrew Kelley <andrew@ziglang.org>2020-02-26 21:02:22 -0500
commitfd1eade4ca02b125b1a2ecea564f32af6a683248 (patch)
treee77e709dcc872897797de3844e18611ff992f55f /src/analyze.cpp
parent0a8835268915feab561bdb68adb17aed76b9708f (diff)
downloadzig-fd1eade4ca02b125b1a2ecea564f32af6a683248.tar.gz
zig-fd1eade4ca02b125b1a2ecea564f32af6a683248.zip
ir: Allow empty inferred error sets
Closes #4564
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp47
1 files changed, 25 insertions, 22 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 41ae69f803..9b776da930 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -4771,38 +4771,41 @@ static void analyze_fn_ir(CodeGen *g, ZigFn *fn, AstNode *return_type_node) {
if (return_err_set_type->data.error_set.infer_fn != nullptr &&
return_err_set_type->data.error_set.incomplete)
{
- ZigType *inferred_err_set_type;
+ // The inferred error set type is null if the function doesn't
+ // return any error
+ ZigType *inferred_err_set_type = nullptr;
+
if (fn->src_implicit_return_type->id == ZigTypeIdErrorSet) {
inferred_err_set_type = fn->src_implicit_return_type;
} else if (fn->src_implicit_return_type->id == ZigTypeIdErrorUnion) {
inferred_err_set_type = fn->src_implicit_return_type->data.error_union.err_set_type;
- } else {
- add_node_error(g, return_type_node,
- buf_sprintf("function with inferred error set must return at least one possible error"));
- fn->anal_state = FnAnalStateInvalid;
- return;
}
- if (inferred_err_set_type->data.error_set.infer_fn != nullptr &&
- inferred_err_set_type->data.error_set.incomplete)
- {
- if (!resolve_inferred_error_set(g, inferred_err_set_type, return_type_node)) {
- fn->anal_state = FnAnalStateInvalid;
- return;
+ if (inferred_err_set_type != nullptr) {
+ if (inferred_err_set_type->data.error_set.infer_fn != nullptr &&
+ inferred_err_set_type->data.error_set.incomplete)
+ {
+ if (!resolve_inferred_error_set(g, inferred_err_set_type, return_type_node)) {
+ fn->anal_state = FnAnalStateInvalid;
+ return;
+ }
}
- }
- return_err_set_type->data.error_set.incomplete = false;
- if (type_is_global_error_set(inferred_err_set_type)) {
- return_err_set_type->data.error_set.err_count = UINT32_MAX;
- } else {
- return_err_set_type->data.error_set.err_count = inferred_err_set_type->data.error_set.err_count;
- if (inferred_err_set_type->data.error_set.err_count > 0) {
- return_err_set_type->data.error_set.errors = heap::c_allocator.allocate<ErrorTableEntry *>(inferred_err_set_type->data.error_set.err_count);
- for (uint32_t i = 0; i < inferred_err_set_type->data.error_set.err_count; i += 1) {
- return_err_set_type->data.error_set.errors[i] = inferred_err_set_type->data.error_set.errors[i];
+ return_err_set_type->data.error_set.incomplete = false;
+ if (type_is_global_error_set(inferred_err_set_type)) {
+ return_err_set_type->data.error_set.err_count = UINT32_MAX;
+ } else {
+ return_err_set_type->data.error_set.err_count = inferred_err_set_type->data.error_set.err_count;
+ if (inferred_err_set_type->data.error_set.err_count > 0) {
+ return_err_set_type->data.error_set.errors = heap::c_allocator.allocate<ErrorTableEntry *>(inferred_err_set_type->data.error_set.err_count);
+ for (uint32_t i = 0; i < inferred_err_set_type->data.error_set.err_count; i += 1) {
+ return_err_set_type->data.error_set.errors[i] = inferred_err_set_type->data.error_set.errors[i];
+ }
}
}
+ } else {
+ return_err_set_type->data.error_set.incomplete = false;
+ return_err_set_type->data.error_set.err_count = 0;
}
}
}