aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorxackus <14938807+xackus@users.noreply.github.com>2020-03-05 08:32:09 +0100
committerxackus <14938807+xackus@users.noreply.github.com>2020-03-08 18:05:45 +0100
commit7782c76bee0201227be730ae131171939f728538 (patch)
tree9667fa7cc1ae51a61dd9fb4a5ad45579550b56e4 /src/analyze.cpp
parentf90fe1f8f2be6ffa1c19997d123e12310d9e04b5 (diff)
downloadzig-7782c76bee0201227be730ae131171939f728538.tar.gz
zig-7782c76bee0201227be730ae131171939f728538.zip
fix failed assert on generic fn opaque return type
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp42
1 files changed, 20 insertions, 22 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index 7712f0f707..638a31ab5a 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -1955,29 +1955,14 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
return g->builtin_types.entry_invalid;
}
- switch (specified_return_type->id) {
- case ZigTypeIdInvalid:
- zig_unreachable();
-
- case ZigTypeIdUndefined:
- case ZigTypeIdNull:
- add_node_error(g, fn_proto->return_type,
- buf_sprintf("return type '%s' not allowed", buf_ptr(&specified_return_type->name)));
- return g->builtin_types.entry_invalid;
-
- case ZigTypeIdOpaque:
- {
- ErrorMsg* msg = add_node_error(g, fn_proto->return_type,
- buf_sprintf("opaque return type '%s' not allowed", buf_ptr(&specified_return_type->name)));
- Tld *tld = find_decl(g, &fn_entry->fndef_scope->base, &specified_return_type->name);
- if (tld != nullptr) {
- add_error_note(g, msg, tld->source_node, buf_sprintf("declared here"));
- }
- return g->builtin_types.entry_invalid;
+ if(!is_valid_return_type(specified_return_type)){
+ ErrorMsg* msg = add_node_error(g, fn_proto->return_type,
+ buf_sprintf("return type '%s' not allowed", buf_ptr(&specified_return_type->name)));
+ Tld *tld = find_decl(g, &fn_entry->fndef_scope->base, &specified_return_type->name);
+ if (tld != nullptr) {
+ add_error_note(g, msg, tld->source_node, buf_sprintf("type declared here"));
}
-
- default:
- break;
+ return g->builtin_types.entry_invalid;
}
if (fn_proto->auto_err_set) {
@@ -2049,6 +2034,19 @@ static ZigType *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *child_sc
return get_fn_type(g, &fn_type_id);
}
+bool is_valid_return_type(ZigType* type) {
+ switch (type->id) {
+ case ZigTypeIdInvalid:
+ case ZigTypeIdUndefined:
+ case ZigTypeIdNull:
+ case ZigTypeIdOpaque:
+ return false;
+ default:
+ return true;
+ }
+ zig_unreachable();
+}
+
bool type_is_invalid(ZigType *type_entry) {
switch (type_entry->id) {
case ZigTypeIdInvalid: