parser: fix the position of the multi variable += assign error (#7584)

pull/7587/head
Swastik Baranwal 2020-12-26 23:18:58 +05:30 committed by GitHub
parent 90175e95d3
commit e27252bef5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 1 deletions

View File

@ -106,7 +106,7 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr, left_comments []ast.Comme
for r in right {
has_cross_var = p.check_cross_variables(left, r)
if op !in [.assign, .decl_assign] {
p.error('unexpected $op.str(), expecting := or = or comma')
p.error_with_pos('unexpected $op.str(), expecting := or = or comma', pos)
return ast.Stmt{}
}
if has_cross_var {

View File

@ -0,0 +1,7 @@
vlib/v/parser/tests/multi_argumented_assign_err.vv:3:10: error: unexpected +=, expecting := or = or comma
1 | fn main() {
2 | mut a, mut b, mut c := 0,1, 2
3 | a, b, c += 1, 2, 4
| ~~
4 | println('$a $b $c')
5 | }

View File

@ -0,0 +1,5 @@
fn main() {
mut a, mut b, mut c := 0,1, 2
a, b, c += 1, 2, 4
println('$a $b $c')
}