From c1f224640faaa4e3ff191c8e150287c31a2fae83 Mon Sep 17 00:00:00 2001 From: Enzo Baldisserri Date: Wed, 6 May 2020 00:09:46 +0200 Subject: [PATCH] checker: verify that there is a main module --- vlib/v/checker/checker.v | 4 +++- vlib/v/checker/tests/no_main_mod.out | 3 +++ vlib/v/checker/tests/no_main_mod.vv | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 vlib/v/checker/tests/no_main_mod.out create mode 100644 vlib/v/checker/tests/no_main_mod.vv diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index f2225f0021..da72229b26 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -89,7 +89,9 @@ pub fn (mut c Checker) check_files(ast_files []ast.File) { // shared libs do not need to have a main return } - if has_main_mod_file && !has_main_fn { + if !has_main_mod_file { + c.error('projet must include a `main` module or be a shared library (compile with `v -shared`)', token.Position{}) + } else if !has_main_fn { c.error('function `main` must be declared in the main module', token.Position{}) } } diff --git a/vlib/v/checker/tests/no_main_mod.out b/vlib/v/checker/tests/no_main_mod.out new file mode 100644 index 0000000000..35b327469f --- /dev/null +++ b/vlib/v/checker/tests/no_main_mod.out @@ -0,0 +1,3 @@ +vlib/v/checker/tests/no_main_mod.v:1:1: error: projet must include a `main` module or be a shared library (compile with `v -shared`) + 1 | module a + | ^ diff --git a/vlib/v/checker/tests/no_main_mod.vv b/vlib/v/checker/tests/no_main_mod.vv new file mode 100644 index 0000000000..a32281dc37 --- /dev/null +++ b/vlib/v/checker/tests/no_main_mod.vv @@ -0,0 +1 @@ +module a