mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix array filter of fn mut argument (#17231)
This commit is contained in:
parent
791ef4b4a6
commit
7090e905f7
@ -2329,6 +2329,8 @@ fn (mut c Checker) array_builtin_method_call(mut node ast.CallExpr, left_type as
|
||||
// check fn
|
||||
if node.return_type.has_flag(.shared_f) {
|
||||
node.return_type = node.return_type.clear_flag(.shared_f).deref()
|
||||
} else if node.left.is_auto_deref_var() {
|
||||
node.return_type = node.return_type.deref()
|
||||
}
|
||||
c.check_map_and_filter(false, elem_typ, node)
|
||||
} else if method_name in ['any', 'all'] {
|
||||
|
10
vlib/v/tests/array_filter_of_fn_mut_arg_test.v
Normal file
10
vlib/v/tests/array_filter_of_fn_mut_arg_test.v
Normal file
@ -0,0 +1,10 @@
|
||||
fn foo(mut arr []&int) {
|
||||
arr = arr.filter(it != unsafe { nil })
|
||||
}
|
||||
|
||||
fn test_array_filter_of_fn_mut_arg() {
|
||||
mut arr := []&int{}
|
||||
foo(mut arr)
|
||||
println(arr.len)
|
||||
assert arr.len == 0
|
||||
}
|
Loading…
Reference in New Issue
Block a user