authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-06 20:41:49-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-03-06 20:41:49-05:00
log6b5cfd9d9963d2f1e91dfdb40f26c2ad11beb3c4
tree80b8530ad4d55c603dd0110cf15e9e335e7e5841
parenteff3530dfab5ecb4e480e0516ed57a8f564543f5

turn assertion into compile error for using var as return type

closes #758

2 files changed, 14 insertions(+), 11 deletions(-)

src/analyze.cpp+13-10
...@@ -1510,6 +1510,19 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c...@@ -1510,6 +1510,19 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1510 }1510 }
1511 }1511 }
15121512
1513 if (fn_proto->return_var_token != nullptr) {
1514 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
1515 add_node_error(g, fn_proto->return_type,
1516 buf_sprintf("return type 'var' not allowed in function with calling convention '%s'",
1517 calling_convention_name(fn_type_id.cc)));
1518 return g->builtin_types.entry_invalid;
1519 }
1520 add_node_error(g, proto_node,
1521 buf_sprintf("TODO implement inferred return types https://github.com/zig-lang/zig/issues/447"));
1522 return g->builtin_types.entry_invalid;
1523 //return get_generic_fn_type(g, &fn_type_id);
1524 }
1525
1513 TypeTableEntry *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type);1526 TypeTableEntry *specified_return_type = analyze_type_expr(g, child_scope, fn_proto->return_type);
1514 if (type_is_invalid(specified_return_type)) {1527 if (type_is_invalid(specified_return_type)) {
1515 fn_type_id.return_type = g->builtin_types.entry_invalid;1528 fn_type_id.return_type = g->builtin_types.entry_invalid;
...@@ -1523,16 +1536,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c...@@ -1523,16 +1536,6 @@ static TypeTableEntry *analyze_fn_type(CodeGen *g, AstNode *proto_node, Scope *c
1523 fn_type_id.return_type = specified_return_type;1536 fn_type_id.return_type = specified_return_type;
1524 }1537 }
15251538
1526 if (fn_proto->return_var_token != nullptr) {
1527 if (!calling_convention_allows_zig_types(fn_type_id.cc)) {
1528 add_node_error(g, fn_proto->return_type,
1529 buf_sprintf("return type 'var' not allowed in function with calling convention '%s'",
1530 calling_convention_name(fn_type_id.cc)));
1531 return g->builtin_types.entry_invalid;
1532 }
1533 return get_generic_fn_type(g, &fn_type_id);
1534 }
1535
1536 if (!calling_convention_allows_zig_types(fn_type_id.cc) && !type_allowed_in_extern(g, fn_type_id.return_type)) {1539 if (!calling_convention_allows_zig_types(fn_type_id.cc) && !type_allowed_in_extern(g, fn_type_id.return_type)) {
1537 add_node_error(g, fn_proto->return_type,1540 add_node_error(g, fn_proto->return_type,
1538 buf_sprintf("return type '%s' not allowed in function with calling convention '%s'",1541 buf_sprintf("return type '%s' not allowed in function with calling convention '%s'",
src/ir.cpp+1-1
...@@ -12019,7 +12019,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal...@@ -12019,7 +12019,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
12019 inst_fn_type_id.alignment = align_bytes;12019 inst_fn_type_id.alignment = align_bytes;
12020 }12020 }
1202112021
12022 {12022 if (fn_proto_node->data.fn_proto.return_var_token == nullptr) {
12023 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;12023 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
12024 TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);12024 TypeTableEntry *specified_return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);
12025 if (type_is_invalid(specified_return_type))12025 if (type_is_invalid(specified_return_type))