mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: missing mutability check for array.delete calls (#18096)
This commit is contained in:
parent
5631e2f01d
commit
063dfa0ab9
@ -2535,6 +2535,7 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
|
||||
node.receiver_type = left_type
|
||||
}
|
||||
} else if method_name == 'delete' {
|
||||
c.fail_if_immutable(node.left)
|
||||
unwrapped_left_sym := c.table.sym(c.unwrap_generic(left_type))
|
||||
if method := c.table.find_method(unwrapped_left_sym, method_name) {
|
||||
node.receiver_type = method.receiver_type
|
||||
|
7
vlib/v/checker/tests/array_delete_imut_err.out
Normal file
7
vlib/v/checker/tests/array_delete_imut_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/array_delete_imut_err.vv:5:2: error: `a` is immutable, declare it with `mut` to make it mutable
|
||||
3 | println(a)
|
||||
4 |
|
||||
5 | a.delete(1)
|
||||
| ^
|
||||
6 | println(a)
|
||||
7 | }
|
7
vlib/v/checker/tests/array_delete_imut_err.vv
Normal file
7
vlib/v/checker/tests/array_delete_imut_err.vv
Normal file
@ -0,0 +1,7 @@
|
||||
fn main() {
|
||||
a := [1, 2, 3, 4]
|
||||
println(a)
|
||||
|
||||
a.delete(1)
|
||||
println(a)
|
||||
}
|
@ -1,12 +1,12 @@
|
||||
vlib/v/checker/tests/array_delete_print_err.vv:3:2: error: `println` can not print void expressions
|
||||
1 | fn main() {
|
||||
2 | a := []string{}
|
||||
2 | mut a := []string{}
|
||||
3 | println(a.delete(0))
|
||||
| ~~~~~~~~~~~~~~~~~~~~
|
||||
4 | println('${a.delete(0)}')
|
||||
5 | }
|
||||
vlib/v/checker/tests/array_delete_print_err.vv:4:15: error: expression does not return a value
|
||||
2 | a := []string{}
|
||||
2 | mut a := []string{}
|
||||
3 | println(a.delete(0))
|
||||
4 | println('${a.delete(0)}')
|
||||
| ~~~~~~~~~
|
||||
|
@ -1,5 +1,5 @@
|
||||
fn main() {
|
||||
a := []string{}
|
||||
mut a := []string{}
|
||||
println(a.delete(0))
|
||||
println('${a.delete(0)}')
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user