checker: make the no-body main function a checker error (#8211)

pull/8286/head
zakuro 2021-01-23 17:30:26 +09:00 committed by GitHub
parent 325731e3b6
commit 9812230847
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 0 deletions

View File

@ -246,6 +246,9 @@ fn (mut c Checker) check_file_in_main(file ast.File) bool {
if stmt.return_type != table.void_type {
c.error('function `main` cannot return values', stmt.pos)
}
if stmt.no_body {
c.error('function `main` must declare a body', stmt.pos)
}
} else {
for attr in stmt.attrs {
if attr.name == 'console' {

View File

@ -0,0 +1,3 @@
vlib/v/checker/tests/main_no_body_err.vv:1:1: error: function `main` must declare a body
1 | fn main()
| ~~~~~~~~~

View File

@ -0,0 +1 @@
fn main()