diff --git a/vlib/v/checker/tests/main_and_script_err.out b/vlib/v/checker/tests/main_and_script_err.out deleted file mode 100644 index 71b5f75084..0000000000 --- a/vlib/v/checker/tests/main_and_script_err.out +++ /dev/null @@ -1,5 +0,0 @@ -vlib/v/checker/tests/main_and_script_err.vv:1:1: error: function `main` is already defined - 1 | fn main() { - | ^ - 2 | println('main') - 3 | } diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 55000ac7c4..8e216c2776 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -693,6 +693,10 @@ pub fn (mut p Parser) top_stmt() ast.Stmt { p.script_mode = true p.script_mode_start_token = p.tok + if p.table.known_fn('main.main') { + p.error('function `main` is already defined, put your script statements inside it') + } + p.open_scope() mut stmts := []ast.Stmt{} for p.tok.kind != .eof { diff --git a/vlib/v/parser/tests/main_and_script_err.out b/vlib/v/parser/tests/main_and_script_err.out new file mode 100644 index 0000000000..0ec7a9f259 --- /dev/null +++ b/vlib/v/parser/tests/main_and_script_err.out @@ -0,0 +1,5 @@ +vlib/v/parser/tests/main_and_script_err.vv:4:1: error: function `main` is already defined, put your script statements inside it + 2 | println('main') + 3 | } + 4 | println('out') + | ~~~~~~~ diff --git a/vlib/v/checker/tests/main_and_script_err.vv b/vlib/v/parser/tests/main_and_script_err.vv similarity index 100% rename from vlib/v/checker/tests/main_and_script_err.vv rename to vlib/v/parser/tests/main_and_script_err.vv