From 5d0af69bfd6a6e5003dac7fe99d1ab8745c8f84f Mon Sep 17 00:00:00 2001 From: Turiiya <34311583+tobealive@users.noreply.github.com> Date: Fri, 16 Jun 2023 08:45:50 +0200 Subject: [PATCH] parser: fix dump removing empty lines (#18452) --- vlib/v/fmt/tests/empty_lines_expected.vv | 2 ++ vlib/v/fmt/tests/empty_lines_input.vv | 2 ++ vlib/v/fmt/tests/empty_lines_keep.vv | 3 +++ vlib/v/parser/expr.v | 4 +++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/vlib/v/fmt/tests/empty_lines_expected.vv b/vlib/v/fmt/tests/empty_lines_expected.vv index 605c552c09..164661a4b5 100644 --- a/vlib/v/fmt/tests/empty_lines_expected.vv +++ b/vlib/v/fmt/tests/empty_lines_expected.vv @@ -10,6 +10,8 @@ fn squash_multiple_empty_lines() { println('b') + dump('c') + c := 0 d := 0 diff --git a/vlib/v/fmt/tests/empty_lines_input.vv b/vlib/v/fmt/tests/empty_lines_input.vv index f8eee66b9e..4430f646c6 100644 --- a/vlib/v/fmt/tests/empty_lines_input.vv +++ b/vlib/v/fmt/tests/empty_lines_input.vv @@ -8,6 +8,8 @@ fn squash_multiple_empty_lines() { println('b') + dump('c') + c := 0 diff --git a/vlib/v/fmt/tests/empty_lines_keep.vv b/vlib/v/fmt/tests/empty_lines_keep.vv index f0272789a7..d62ca129ef 100644 --- a/vlib/v/fmt/tests/empty_lines_keep.vv +++ b/vlib/v/fmt/tests/empty_lines_keep.vv @@ -33,12 +33,15 @@ fn keep_single_empty_line() { println('c') + dump('d') + d := 0 if true { println('e') } + dump('f') f := 0 arr << MyStruct{} diff --git a/vlib/v/parser/expr.v b/vlib/v/parser/expr.v index b5c8860b20..30f3f71923 100644 --- a/vlib/v/parser/expr.v +++ b/vlib/v/parser/expr.v @@ -328,9 +328,11 @@ fn (mut p Parser) check_expr(precedence int) !ast.Expr { p.next() } p.check(.rpar) + mut pos := p.tok.pos() + pos.update_last_line(p.prev_tok.line_nr) node = ast.DumpExpr{ expr: expr - pos: spos.extend(p.tok.pos()) + pos: spos.extend(pos) } } .key_offsetof {