mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: make sure main
has no args and doesn't return
This commit is contained in:
parent
a9e33e712a
commit
2b48ce21df
@ -115,6 +115,12 @@ fn (mut c Checker) check_file_in_main(file ast.File) bool {
|
||||
if it.is_pub {
|
||||
c.error('function `main` cannot be declared public', it.pos)
|
||||
}
|
||||
if it.args.len > 0 {
|
||||
c.error('function `main` cannot have arguments', it.pos)
|
||||
}
|
||||
if it.return_type != table.void_type {
|
||||
c.error('function `main` cannot return values', it.pos)
|
||||
}
|
||||
} else {
|
||||
if it.is_pub {
|
||||
c.warn('function `$it.name` $no_pub_in_main_warning', it.pos)
|
||||
|
5
vlib/v/checker/tests/main_args_err.out
Normal file
5
vlib/v/checker/tests/main_args_err.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/checker/tests/main_args_err.v:1:1: error: function `main` cannot have arguments
|
||||
1| fn main(a string) {
|
||||
~~~~~~~~~~~~~~~~~
|
||||
2| println(a)
|
||||
3| }
|
3
vlib/v/checker/tests/main_args_err.vv
Normal file
3
vlib/v/checker/tests/main_args_err.vv
Normal file
@ -0,0 +1,3 @@
|
||||
fn main(a string) {
|
||||
println(a)
|
||||
}
|
5
vlib/v/checker/tests/main_return_err.out
Normal file
5
vlib/v/checker/tests/main_return_err.out
Normal file
@ -0,0 +1,5 @@
|
||||
vlib/v/checker/tests/main_return_err.v:1:1: error: function `main` cannot return values
|
||||
1| fn main() f64 {
|
||||
~~~~~~~~~~~~~
|
||||
2| return 1.23
|
||||
3| }
|
3
vlib/v/checker/tests/main_return_err.vv
Normal file
3
vlib/v/checker/tests/main_return_err.vv
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() f64 {
|
||||
return 1.23
|
||||
}
|
Loading…
Reference in New Issue
Block a user