From 1605c3b5f8d40232cbe8875e2b36aeaff270b668 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Fri, 25 Dec 2020 15:50:08 +0100 Subject: [PATCH] parser: fix error when accessing module without name after dot (#7530) --- vlib/v/parser/parser.v | 2 +- vlib/v/parser/tests/uncomplete_module_call_err.out | 5 +++++ vlib/v/parser/tests/uncomplete_module_call_err.vv | 7 +++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 vlib/v/parser/tests/uncomplete_module_call_err.out create mode 100644 vlib/v/parser/tests/uncomplete_module_call_err.vv diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index b422a8c01..db12909b5 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1147,7 +1147,7 @@ pub fn (mut p Parser) name_expr() ast.Expr { // mark the imported module as used p.register_used_import(p.tok.lit) if p.peek_tok.kind == .dot && - p.peek_tok2.kind != .eof && p.peek_tok2.lit[0].is_capital() { + p.peek_tok2.kind != .eof && p.peek_tok2.lit.len > 0 && p.peek_tok2.lit[0].is_capital() { is_mod_cast = true } } diff --git a/vlib/v/parser/tests/uncomplete_module_call_err.out b/vlib/v/parser/tests/uncomplete_module_call_err.out new file mode 100644 index 000000000..630b780ef --- /dev/null +++ b/vlib/v/parser/tests/uncomplete_module_call_err.out @@ -0,0 +1,5 @@ +vlib/v/parser/tests/uncomplete_module_call_err.vv:7:1: error: unexpected token `` + 5 | fn main() { + 6 | os. + 7 | } + | ^ \ No newline at end of file diff --git a/vlib/v/parser/tests/uncomplete_module_call_err.vv b/vlib/v/parser/tests/uncomplete_module_call_err.vv new file mode 100644 index 000000000..7a3cb0629 --- /dev/null +++ b/vlib/v/parser/tests/uncomplete_module_call_err.vv @@ -0,0 +1,7 @@ +module main + +import os + +fn main() { + os. +} -- 2.39.5