parser: require ++/-- to be on the same line as the previous token (#8621)

pull/8631/head
Nick Treleaven 2021-02-07 22:10:16 +00:00 committed by GitHub
parent 367dbc7707
commit ff1aa06455
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 0 deletions

View File

@ -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

View 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
| ~~

View File

@ -0,0 +1,3 @@
mut v := 4
_ = v
++v