parser: fix the no fn main error in script mode

pull/2763/head^2
Alexander Medvednikov 2019-11-18 00:40:59 +03:00
parent ffb72e855a
commit 4fb0b49806
1 changed files with 2 additions and 1 deletions

View File

@ -432,7 +432,8 @@ pub fn (v mut V) generate_main() {
if v.pref.build_mode != .build_module { if v.pref.build_mode != .build_module {
if !v.table.main_exists() && !v.pref.is_test { if !v.table.main_exists() && !v.pref.is_test {
// It can be skipped in single file programs // It can be skipped in single file programs
if v.pref.is_script { // But make sure that there's some code outside of main()
if v.pref.is_script && cgen.fn_main.trim_space() != ''{
//println('Generating main()...') //println('Generating main()...')
v.gen_main_start(true) v.gen_main_start(true)
cgen.genln('$cgen.fn_main;') cgen.genln('$cgen.fn_main;')