From 558a7564317fd7ab9b00a3d2c3219648227226d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20D=C3=A4schle?= Date: Thu, 3 Dec 2020 10:25:06 +0100 Subject: [PATCH] parser: fix position offset by 1 (#7099) --- vlib/v/checker/tests/match_sumtype_multiple_types.out | 2 +- vlib/v/parser/fn.v | 6 +----- vlib/v/parser/parser.v | 8 ++------ 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/vlib/v/checker/tests/match_sumtype_multiple_types.out b/vlib/v/checker/tests/match_sumtype_multiple_types.out index ddc0a61e39..9f2201f41f 100644 --- a/vlib/v/checker/tests/match_sumtype_multiple_types.out +++ b/vlib/v/checker/tests/match_sumtype_multiple_types.out @@ -9,6 +9,6 @@ vlib/v/checker/tests/match_sumtype_multiple_types.vv:27:13: error: unknown metho 25 | Alfa, Charlie { 26 | assert l.char == `a` 27 | assert l.letter() == 'a' - | ~~~~~~~~~ + | ~~~~~~~~ 28 | } 29 | Bravo { \ No newline at end of file diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 2b97b431df..c0bfa6a500 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -50,11 +50,7 @@ pub fn (mut p Parser) call_expr(language table.Language, mod string) ast.CallExp if p.tok.kind == .not { p.next() } - pos := token.Position{ - line_nr: first_pos.line_nr - pos: first_pos.pos - len: last_pos.pos - first_pos.pos + last_pos.len - } + pos := first_pos.extend(last_pos) mut or_stmts := []ast.Stmt{} mut or_pos := p.tok.position() if p.tok.kind == .key_orelse { diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 1508a21b85..d2a9c3f33c 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -1351,12 +1351,8 @@ fn (mut p Parser) dot_expr(left ast.Expr) ast.Expr { or_kind = .propagate } // - end_pos := p.tok.position() - pos := token.Position{ - line_nr: name_pos.line_nr - pos: name_pos.pos - len: end_pos.pos - name_pos.pos - } + end_pos := p.prev_tok.position() + pos := name_pos.extend(end_pos) mcall_expr := ast.CallExpr{ left: left name: field_name