parser: trigger declaration of array element as error

pull/5442/head
Uwe Krüger 2020-06-20 14:30:03 +02:00 committed by GitHub
parent 76dc7eea50
commit 37927235cd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/array_declare_element_a.v:2:9: error: non-name `arr[0]` on left side of `:=`
1 | fn main() {
2 | arr[0] := 2
| ~~
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
arr[0] := 2
}

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/array_declare_element_b.v:3:9: error: non-name `arr[1]` on left side of `:=`
1 | fn main() {
2 | arr := [1, 2]
3 | arr[1] := 1
| ~~
4 | }

View File

@ -0,0 +1,4 @@
fn main() {
arr := [1, 2]
arr[1] := 1
}

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/array_declare_element_c.v:3:12: error: non-name `arr[1][0]` on left side of `:=`
1 | fn main() {
2 | arr := [[1, 2], [0, 3]]
3 | arr[1][0] := 1
| ~~
4 | }

View File

@ -0,0 +1,4 @@
fn main() {
arr := [[1, 2], [0, 3]]
arr[1][0] := 1
}

View File

@ -111,6 +111,9 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr) ast.Stmt {
}
}
ast.IndexExpr {
if op == .decl_assign {
p.error_with_pos('non-name `$lx.left[$lx.index]` on left side of `:=`', lx.pos)
}
lx.is_setter = true
}
ast.ParExpr {}