From f1e5be96860406d7a4239b174c896799d8fd6545 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Mon, 9 May 2016 13:44:29 -0700 Subject: fix ability to use previous generic params and add error when `%return` shows up in a function with incorrect return type --- src/analyze.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/analyze.cpp') 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, -- cgit v1.2.3