From 2b4f72ef646ea414d87dc69350aa562f035a2e74 Mon Sep 17 00:00:00 2001 From: yuyi Date: Thu, 23 Apr 2020 20:48:05 +0800 Subject: [PATCH] parser: fix empty import error --- vlib/v/parser/parser.v | 3 +++ vlib/v/tests/inout/empty_import.out | 1 + vlib/v/tests/inout/empty_import.vv | 7 +++++++ 3 files changed, 11 insertions(+) create mode 100644 vlib/v/tests/inout/empty_import.out create mode 100644 vlib/v/tests/inout/empty_import.vv diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 47d94ffe8d..84349d63ab 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -302,6 +302,9 @@ pub fn (mut p Parser) top_stmt() ast.Stmt { } .key_import { node := p.import_stmt() + if node.len == 0 { + return p.top_stmt() + } p.ast_imports << node return node[0] } diff --git a/vlib/v/tests/inout/empty_import.out b/vlib/v/tests/inout/empty_import.out new file mode 100644 index 0000000000..c1e44f4f09 --- /dev/null +++ b/vlib/v/tests/inout/empty_import.out @@ -0,0 +1 @@ +empty import \ No newline at end of file diff --git a/vlib/v/tests/inout/empty_import.vv b/vlib/v/tests/inout/empty_import.vv new file mode 100644 index 0000000000..ada986a14a --- /dev/null +++ b/vlib/v/tests/inout/empty_import.vv @@ -0,0 +1,7 @@ +import ( + // no module +) + +fn main() { + println('empty import') +}