mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: prompt error on script expression while inside a file with main (#6400)
This commit is contained in:
parent
4038ac463c
commit
c02a0f90df
@ -191,6 +191,9 @@ fn (mut c Checker) check_file_in_main(file ast.File) bool {
|
|||||||
}
|
}
|
||||||
ast.FnDecl {
|
ast.FnDecl {
|
||||||
if stmt.name == 'main.main' {
|
if stmt.name == 'main.main' {
|
||||||
|
if has_main_fn {
|
||||||
|
c.error('function `main` is already defined', stmt.pos)
|
||||||
|
}
|
||||||
has_main_fn = true
|
has_main_fn = true
|
||||||
if stmt.is_pub {
|
if stmt.is_pub {
|
||||||
c.error('function `main` cannot be declared public', stmt.pos)
|
c.error('function `main` cannot be declared public', stmt.pos)
|
||||||
|
5
vlib/v/checker/tests/main_and_script_err.out
Normal file
5
vlib/v/checker/tests/main_and_script_err.out
Normal 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 | }
|
4
vlib/v/checker/tests/main_and_script_err.vv
Normal file
4
vlib/v/checker/tests/main_and_script_err.vv
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
fn main() {
|
||||||
|
println('main')
|
||||||
|
}
|
||||||
|
println('out')
|
Loading…
x
Reference in New Issue
Block a user