From 61af0443161e8f492d7e653905b5774f668397e5 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Sun, 13 Oct 2019 17:55:12 +0300 Subject: [PATCH] Revert "parser: fix programs without fn main" This reverts commit bf21108fdb2fa20484108fe561020d73db9e00e4. --- vlib/compiler/parser.v | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index 1457c704d3..6804835409 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -395,18 +395,21 @@ fn (p mut Parser) parse(pass Pass) { if p.pref.is_script && !p.pref.is_test { // cur_fn is empty since there was no fn main declared // we need to set it to save and find variables + if p.first_pass() { + if p.cur_fn.name == '' { + p.set_current_fn( MainFn ) + } + return + } if p.cur_fn.name == '' { p.set_current_fn( MainFn ) if p.pref.is_repl { - if p.first_pass() { - return - } p.clear_vars() } } mut start := p.cgen.lines.len p.statement(true) - if start > 0 && p.cgen.lines[start - 1] != '' && p.cgen.fn_main != '' { + if p.cgen.lines[start - 1] != '' && p.cgen.fn_main != '' { start-- } p.genln('')