checker: make sure `main` has no args and doesn't return
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)
|
||||
|
|
|
@ -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| }
|
|
@ -0,0 +1,3 @@
|
|||
fn main(a string) {
|
||||
println(a)
|
||||
}
|
|
@ -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| }
|
|
@ -0,0 +1,3 @@
|
|||
fn main() f64 {
|
||||
return 1.23
|
||||
}
|
Loading…
Reference in New Issue