checker: make sure `main` has no args and doesn't return

pull/4644/head
yuyi 2020-04-29 15:19:46 +08:00 committed by GitHub
parent a9e33e712a
commit 2b48ce21df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 0 deletions

View File

@ -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)

View 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| }

View File

@ -0,0 +1,3 @@
fn main(a string) {
println(a)
}

View 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| }

View File

@ -0,0 +1,3 @@
fn main() f64 {
return 1.23
}