Skip to content

Commit 28b0cbd

Browse files
authored
parser: check error for script mode that define main function (fix #14467) (#14469)
1 parent 913164b commit 28b0cbd

File tree

4 files changed

+9
-5
lines changed

4 files changed

+9
-5
lines changed

vlib/v/checker/tests/main_and_script_err.out

Lines changed: 0 additions & 5 deletions
This file was deleted.

vlib/v/parser/parser.v

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,10 @@ pub fn (mut p Parser) top_stmt() ast.Stmt {
693693
p.script_mode = true
694694
p.script_mode_start_token = p.tok
695695

696+
if p.table.known_fn('main.main') {
697+
p.error('function `main` is already defined, put your script statements inside it')
698+
}
699+
696700
p.open_scope()
697701
mut stmts := []ast.Stmt{}
698702
for p.tok.kind != .eof {
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
vlib/v/parser/tests/main_and_script_err.vv:4:1: error: function `main` is already defined, put your script statements inside it
2+
2 | println('main')
3+
3 | }
4+
4 | println('out')
5+
| ~~~~~~~

0 commit comments

Comments
 (0)