From 33e3d5645344d5c8076a1f020d49917334f6902a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 13 May 2016 13:08:54 -0700 Subject: add error for wrong return type of main --- src/analyze.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'src/analyze.cpp') diff --git a/src/analyze.cpp b/src/analyze.cpp index aa8fe0d060..ee3235d342 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -1560,6 +1560,17 @@ static void preview_fn_proto_instance(CodeGen *g, ImportTableEntry *import, AstN proto_node->data.fn_proto.fn_table_entry = fn_table_entry; resolve_function_proto(g, proto_node, fn_table_entry, import, containing_context); + + if (is_main_fn && !g->link_libc) { + TypeTableEntry *err_void = get_error_type(g, g->builtin_types.entry_void); + TypeTableEntry *actual_return_type = fn_table_entry->type_entry->data.fn.fn_type_id.return_type; + if (actual_return_type != err_void) { + AstNode *return_type_node = fn_table_entry->proto_node->data.fn_proto.return_type; + add_node_error(g, return_type_node, + buf_sprintf("expected return type of main to be '%%void', instead is '%s'", + buf_ptr(&actual_return_type->name))); + } + } } static void preview_fn_proto(CodeGen *g, ImportTableEntry *import, AstNode *proto_node) { -- cgit v1.2.3