From 1c56ff7faf9affbf5c290ba2d1408d67c273cb9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Thu, 10 Dec 2020 17:17:25 +0100 Subject: [PATCH] parser: fix fibonacci in silent mode (#7240) --- .github/workflows/ci.yml | 1 + cmd/tools/vself.v | 2 +- vlib/v/parser/parser.v | 5 +++-- vlib/v/scanner/scanner.v | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7cad8a56ec..52da24e39e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -608,3 +608,4 @@ jobs: run: | ./v test-parser examples/hello_world.v ./v test-parser examples/hanoi.v + ./v test-parser examples/fibonacci.v diff --git a/cmd/tools/vself.v b/cmd/tools/vself.v index 1114b17e50..7f73256ae5 100644 --- a/cmd/tools/vself.v +++ b/cmd/tools/vself.v @@ -13,7 +13,7 @@ fn main() { args := os.args[1..self_idx] jargs := args.join(' ') obinary := cmdline.option(args, '-o', '') - sargs := if obinary != '' { jargs } else { '$jargs -o v2 ' } + sargs := if obinary != '' { jargs } else { '$jargs -o v2' } cmd := '$vexe $sargs cmd/v' options := if args.len > 0 { '($sargs)' } else { '' } println('V self compiling ${options}...') diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index d7f39a7a45..f2ff629167 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1132,7 +1132,8 @@ pub fn (mut p Parser) name_expr() ast.Expr { if p.tok.lit in p.imports { // mark the imported module as used p.register_used_import(p.tok.lit) - if p.peek_tok.kind == .dot && p.peek_tok2.lit[0].is_capital() { + if p.peek_tok.kind == .dot && + p.peek_tok2.kind != .eof && p.peek_tok2.lit[0].is_capital() { is_mod_cast = true } } @@ -1143,7 +1144,7 @@ pub fn (mut p Parser) name_expr() ast.Expr { p.check(.dot) p.expr_mod = mod } - lit0_is_capital := p.tok.lit[0].is_capital() + lit0_is_capital := if p.tok.kind != .eof { p.tok.lit[0].is_capital() } else { false } // use heuristics to detect `func()` from `var < expr` is_generic_call := !lit0_is_capital && p.peek_tok.kind == .lt && (match p.peek_tok2.kind { .name { diff --git a/vlib/v/scanner/scanner.v b/vlib/v/scanner/scanner.v index 9f6162b053..f0608dc4cf 100644 --- a/vlib/v/scanner/scanner.v +++ b/vlib/v/scanner/scanner.v @@ -798,7 +798,7 @@ fn (mut s Scanner) text_scan() token.Token { `.` { if nextc == `.` { s.pos++ - if s.text[s.pos + 1] == `.` { + if s.pos + 1 < s.text.len && s.text[s.pos + 1] == `.` { s.pos++ return s.new_token(.ellipsis, '', 3) }