aboutsummaryrefslogtreecommitdiff
path: root/src/analyze.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <superjoe30@gmail.com>2016-05-09 13:44:29 -0700
committerAndrew Kelley <superjoe30@gmail.com>2016-05-09 13:44:29 -0700
commitf1e5be96860406d7a4239b174c896799d8fd6545 (patch)
tree4b322fa179f2eaca32664d415a4c069777bd3e7f /src/analyze.cpp
parent745c325d0f498406f229e532753e5d5712e824d4 (diff)
downloadzig-f1e5be96860406d7a4239b174c896799d8fd6545.tar.gz
zig-f1e5be96860406d7a4239b174c896799d8fd6545.zip
fix ability to use previous generic params and
add error when `%return` shows up in a function with incorrect return type
Diffstat (limited to 'src/analyze.cpp')
-rw-r--r--src/analyze.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/analyze.cpp b/src/analyze.cpp
index ac26cb3980..1d951f867e 100644
--- a/src/analyze.cpp
+++ b/src/analyze.cpp
@@ -5217,7 +5217,7 @@ static TypeTableEntry *analyze_generic_fn_call(CodeGen *g, ImportTableEntry *imp
AstNode **generic_param_type_node = &generic_param_decl_node->data.param_decl.type;
TypeTableEntry *expected_param_type = analyze_type_expr(g, decl_node->owner,
- decl_node->owner->block_context, *generic_param_type_node);
+ child_context, *generic_param_type_node);
if (expected_param_type->id == TypeTableEntryIdInvalid) {
return expected_param_type;
}
@@ -5809,6 +5809,17 @@ static TypeTableEntry *analyze_return_expr(CodeGen *g, ImportTableEntry *import,
if (resolved_type->id == TypeTableEntryIdInvalid) {
return resolved_type;
} else if (resolved_type->id == TypeTableEntryIdErrorUnion) {
+ TypeTableEntry *return_type = context->fn_entry->type_entry->data.fn.fn_type_id.return_type;
+ if (return_type->id != TypeTableEntryIdErrorUnion &&
+ return_type->id != TypeTableEntryIdPureError)
+ {
+ ErrorMsg *msg = add_node_error(g, node,
+ buf_sprintf("%%return statement in function with return type '%s'",
+ buf_ptr(&return_type->name)));
+ AstNode *return_type_node = context->fn_entry->fn_def_node->data.fn_def.fn_proto->data.fn_proto.return_type;
+ add_error_note(g, msg, return_type_node, buf_sprintf("function return type here"));
+ }
+
return resolved_type->data.error.child_type;
} else {
add_node_error(g, node->data.return_expr.expr,