From 9812230847d530121ac70c737c5ac0ca1894051a Mon Sep 17 00:00:00 2001 From: zakuro Date: Sat, 23 Jan 2021 17:30:26 +0900 Subject: [PATCH] checker: make the no-body main function a checker error (#8211) --- vlib/v/checker/checker.v | 3 +++ vlib/v/checker/tests/main_no_body_err.out | 3 +++ vlib/v/checker/tests/main_no_body_err.vv | 1 + 3 files changed, 7 insertions(+) create mode 100644 vlib/v/checker/tests/main_no_body_err.out create mode 100644 vlib/v/checker/tests/main_no_body_err.vv 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()