aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-03-09 22:10:57 -0400
committerGitHub <noreply@github.com>2020-03-09 22:10:57 -0400
commit675f01f1768aa08c307640b53e8a5240fa190fab (patch)
tree14702a748268e301cf5fc23a0d28221c487fae7e /src/analyze.cpp
parent1f44b29724b52433d84b43345a52da59f9220e62 (diff)
parente7cc45642138472c29e09cd10e31962426c1aba5 (diff)
downloadzig-675f01f1768aa08c307640b53e8a5240fa190fab.tar.gz
zig-675f01f1768aa08c307640b53e8a5240fa190fab.zip
Merge pull request #4590 from xackus/fix-4587
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 905a6a6f94..33d28269b9 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -1962,29 +1962,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("%s return type '%s' not allowed", type_id_name(specified_return_type->id), 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) {
@@ -2056,6 +2041,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: