diff --git a/vlib/v/parser/pratt.v b/vlib/v/parser/pratt.v index d8f9b31761..e69a8e162a 100644 --- a/vlib/v/parser/pratt.v +++ b/vlib/v/parser/pratt.v @@ -377,6 +377,10 @@ pub fn (mut p Parser) expr_with_left(left ast.Expr, precedence int, is_stmt_iden p.warn_with_pos('`$p.tok.kind` operator can only be used as a statement', p.peek_tok.position()) } + if p.tok.kind in [.inc, .dec] && p.prev_tok.line_nr != p.tok.line_nr { + p.error_with_pos('$p.tok must be on the same line as the previous token', + p.tok.position()) + } node = ast.PostfixExpr{ op: p.tok.kind expr: node diff --git a/vlib/v/parser/tests/postfix_inc.out b/vlib/v/parser/tests/postfix_inc.out new file mode 100644 index 0000000000..91cbf89b4d --- /dev/null +++ b/vlib/v/parser/tests/postfix_inc.out @@ -0,0 +1,5 @@ +vlib/v/parser/tests/postfix_inc.vv:3:1: error: `++` must be on the same line as the previous token + 1 | mut v := 4 + 2 | _ = v + 3 | ++v + | ~~ diff --git a/vlib/v/parser/tests/postfix_inc.vv b/vlib/v/parser/tests/postfix_inc.vv new file mode 100644 index 0000000000..3f2fd06335 --- /dev/null +++ b/vlib/v/parser/tests/postfix_inc.vv @@ -0,0 +1,3 @@ +mut v := 4 +_ = v +++v