mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: require ++/-- to be on the same line as the previous token (#8621)
This commit is contained in:
parent
367dbc7707
commit
ff1aa06455
@ -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
|
||||
|
5
vlib/v/parser/tests/postfix_inc.out
Normal file
5
vlib/v/parser/tests/postfix_inc.out
Normal file
@ -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
|
||||
| ~~
|
3
vlib/v/parser/tests/postfix_inc.vv
Normal file
3
vlib/v/parser/tests/postfix_inc.vv
Normal file
@ -0,0 +1,3 @@
|
||||
mut v := 4
|
||||
_ = v
|
||||
++v
|
Loading…
Reference in New Issue
Block a user