parser: trigger declaration of array element as error
parent
76dc7eea50
commit
37927235cd
|
@ -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 | }
|
|
@ -0,0 +1,3 @@
|
||||||
|
fn main() {
|
||||||
|
arr[0] := 2
|
||||||
|
}
|
|
@ -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 | }
|
|
@ -0,0 +1,4 @@
|
||||||
|
fn main() {
|
||||||
|
arr := [1, 2]
|
||||||
|
arr[1] := 1
|
||||||
|
}
|
|
@ -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 | }
|
|
@ -0,0 +1,4 @@
|
||||||
|
fn main() {
|
||||||
|
arr := [[1, 2], [0, 3]]
|
||||||
|
arr[1][0] := 1
|
||||||
|
}
|
|
@ -111,6 +111,9 @@ fn (mut p Parser) partial_assign_stmt(left []ast.Expr) ast.Stmt {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ast.IndexExpr {
|
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
|
lx.is_setter = true
|
||||||
}
|
}
|
||||||
ast.ParExpr {}
|
ast.ParExpr {}
|
||||||
|
|
Loading…
Reference in New Issue