1
0
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:
yuyi 2023-02-06 22:37:37 +08:00 committed by GitHub
parent 791ef4b4a6
commit 7090e905f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 0 deletions

View File

@ -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'] {

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