1
0
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:
yuyi 2021-11-15 03:00:22 +08:00 committed by GitHub
parent fb997eb5fe
commit 460f4523aa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 0 deletions

View File

@ -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'] { } else if method_name in ['first', 'last', 'pop'] {
node.return_type = array_info.elem_type node.return_type = array_info.elem_type
if method_name == 'pop' { if method_name == 'pop' {
c.fail_if_immutable(node.left)
node.receiver_type = left_type.ref() node.receiver_type = left_type.ref()
} else { } else {
node.receiver_type = left_type node.receiver_type = left_type

View 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 | }

View File

@ -0,0 +1,7 @@
fn main() {
a := [1,2,3]
dump(a)
a.pop()
dump(a)
}