From 3a59f5727c419e0619974cd649e2912676a0b54e Mon Sep 17 00:00:00 2001 From: yuyi Date: Sun, 26 Apr 2020 14:04:28 +0800 Subject: [PATCH] checker: fix check main function error (#4601) --- vlib/v/checker/checker.v | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index c0246e36a0..140f5ca3b0 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -60,10 +60,12 @@ pub fn (mut c Checker) check2(ast_file ast.File) []scanner.Error { } pub fn (mut c Checker) check_files(ast_files []ast.File) { + mut has_main_mod_file := false mut has_main_fn := false for file in ast_files { c.check(file) if file.mod.name == 'main' { + has_main_mod_file = true if c.check_file_in_main(file) { has_main_fn = true } @@ -77,7 +79,7 @@ pub fn (mut c Checker) check_files(ast_files []ast.File) { // shared libs do not need to have a main return } - if !has_main_fn { + if has_main_mod_file && !has_main_fn { c.error('function `main` must be declared in the main module', token.Position{}) } }