checker: prompt error on script expression while inside a file with main (#6400)

pull/6411/head
Henrixounez 2020-09-18 01:14:14 +02:00 committed by GitHub
parent 4038ac463c
commit c02a0f90df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View File

@ -191,6 +191,9 @@ fn (mut c Checker) check_file_in_main(file ast.File) bool {
}
ast.FnDecl {
if stmt.name == 'main.main' {
if has_main_fn {
c.error('function `main` is already defined', stmt.pos)
}
has_main_fn = true
if stmt.is_pub {
c.error('function `main` cannot be declared public', stmt.pos)

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/main_and_script_err.vv:1:1: error: function `main` is already defined
1 | fn main() {
| ^
2 | println('main')
3 | }

View File

@ -0,0 +1,4 @@
fn main() {
println('main')
}
println('out')