mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add an error for assigning to array slices a[..2] = [0, 0]
(#10412)
This commit is contained in:
parent
5be982d63e
commit
10b9ea3258
@ -3268,6 +3268,11 @@ pub fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
||||
if left is ast.CallExpr {
|
||||
c.error('cannot call function `${left.name}()` on the left side of an assignment',
|
||||
left.pos)
|
||||
} else if left is ast.IndexExpr {
|
||||
if left.index is ast.RangeExpr {
|
||||
c.error('cannot reassign using range expression on the left side of an assignment',
|
||||
left.pos)
|
||||
}
|
||||
}
|
||||
is_blank_ident := left.is_blank_ident()
|
||||
mut left_type := ast.void_type
|
||||
|
7
vlib/v/checker/tests/slice_reassignment.out
Normal file
7
vlib/v/checker/tests/slice_reassignment.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/slice_reassignment.vv:3:5: error: cannot reassign using range expression on the left side of an assignment
|
||||
1 | fn main() {
|
||||
2 | mut arr := [1, 2, 3, 4, 5]
|
||||
3 | arr[..2] = [0, 0]
|
||||
| ~~~~~
|
||||
4 | println(arr)
|
||||
5 | }
|
5
vlib/v/checker/tests/slice_reassignment.vv
Normal file
5
vlib/v/checker/tests/slice_reassignment.vv
Normal file
@ -0,0 +1,5 @@
|
||||
fn main() {
|
||||
mut arr := [1, 2, 3, 4, 5]
|
||||
arr[..2] = [0, 0]
|
||||
println(arr)
|
||||
}
|
Loading…
Reference in New Issue
Block a user