checker: main function called error

pull/4631/head
yuyi 2020-04-28 13:21:50 +08:00 committed by GitHub
parent 9edbcb823c
commit b20777df59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 0 deletions

View File

@ -677,6 +677,9 @@ pub fn (mut c Checker) call_fn(call_expr mut ast.CallExpr) table.Type {
c.returns = true
}
fn_name := call_expr.name
if fn_name == 'main' {
c.error('the `main` function cannot be called in the program', call_expr.pos)
}
if fn_name == 'typeof' {
// TODO: impl typeof properly (probably not going to be a fn call)
return table.string_type

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/main_called_err.v:2:2: error: the `main` function cannot be called in the program
1| fn main() {
2| main()
~~~~~~
3| }

View File

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

View File

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