mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: check array pop immutable (#12458)
This commit is contained in:
parent
fb997eb5fe
commit
460f4523aa
@ -2493,6 +2493,7 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
|
||||
} else if method_name in ['first', 'last', 'pop'] {
|
||||
node.return_type = array_info.elem_type
|
||||
if method_name == 'pop' {
|
||||
c.fail_if_immutable(node.left)
|
||||
node.receiver_type = left_type.ref()
|
||||
} else {
|
||||
node.receiver_type = left_type
|
||||
|
7
vlib/v/checker/tests/array_pop_immutable_err.out
Normal file
7
vlib/v/checker/tests/array_pop_immutable_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/array_pop_immutable_err.vv:5:2: error: `a` is immutable, declare it with `mut` to make it mutable
|
||||
3 | dump(a)
|
||||
4 |
|
||||
5 | a.pop()
|
||||
| ^
|
||||
6 | dump(a)
|
||||
7 | }
|
7
vlib/v/checker/tests/array_pop_immutable_err.vv
Normal file
7
vlib/v/checker/tests/array_pop_immutable_err.vv
Normal file
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
a := [1,2,3]
|
||||
dump(a)
|
||||
|
||||
a.pop()
|
||||
dump(a)
|
||||
}
|
Loading…
Reference in New Issue
Block a user