diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 9fbbf785c4..32a4c30451 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -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' { diff --git a/vlib/v/checker/tests/main_no_body_err.out b/vlib/v/checker/tests/main_no_body_err.out new file mode 100644 index 0000000000..09e4a9f480 --- /dev/null +++ b/vlib/v/checker/tests/main_no_body_err.out @@ -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() + | ~~~~~~~~~ diff --git a/vlib/v/checker/tests/main_no_body_err.vv b/vlib/v/checker/tests/main_no_body_err.vv new file mode 100644 index 0000000000..d955fb2df4 --- /dev/null +++ b/vlib/v/checker/tests/main_no_body_err.vv @@ -0,0 +1 @@ +fn main()