authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-05-13 13:08:54-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-05-13 13:08:54-07:00
log33e3d5645344d5c8076a1f020d49917334f6902a
treecef7fac7e9eedd1c5004bdcf3aa02b0bacb9fb1c
parent65e0e85685ac704088cc0ee319c6e4c51adb0c8b

add error for wrong return type of main


2 files changed, 15 insertions(+), 0 deletions(-)

src/analyze.cpp+11
......@@ -1560,6 +1560,17 @@ static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstN
15601560
15611561 proto_node->data.fn_proto.fn_table_entry = fn_table_entry;
15621562 resolve_function_proto(g, proto_node, fn_table_entry, import, containing_context);
1563
1564 if (is_main_fn && !g->link_libc) {
1565 TypeTableEntry *err_void = get_error_type(g, g->builtin_types.entry_void);
1566 TypeTableEntry *actual_return_type = fn_table_entry->type_entry->data.fn.fn_type_id.return_type;
1567 if (actual_return_type != err_void) {
1568 AstNode *return_type_node = fn_table_entry->proto_node->data.fn_proto.return_type;
1569 add_node_error(g, return_type_node,
1570 buf_sprintf("expected return type of main to be '%%void', instead is '%s'",
1571 buf_ptr(&actual_return_type->name)));
1572 }
1573 }
15631574}
15641575
15651576static void preview_fn_proto(CodeGen *g, ImportTableEntry *import, AstNode *proto_node) {
test/run_tests.cpp+4
......@@ -1391,6 +1391,10 @@ fn something() -> %void { }
13911391 ".tmp_source.zig:3:5: error: %return statement in function with return type 'void'",
13921392 ".tmp_source.zig:2:8: note: function return type here");
13931393
1394 add_compile_fail_case("wrong return type for main", R"SOURCE(
1395pub fn main(args: [][]u8) { }
1396 )SOURCE", 1, ".tmp_source.zig:2:27: error: expected return type of main to be '%void', instead is 'void'");
1397
13941398}
13951399
13961400//////////////////////////////////////////////////////////////////////////////