checker: fix check main function error (#4601)

pull/4602/head
yuyi 2020-04-26 14:04:28 +08:00 committed by GitHub
parent a48080afec
commit 3a59f5727c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 1 deletions

View File

@ -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{})
}
}