From 7090e905f78b8396cdf84d0a76cfa44ba107078c Mon Sep 17 00:00:00 2001 From: yuyi Date: Mon, 6 Feb 2023 22:37:37 +0800 Subject: [PATCH] checker: fix array filter of fn mut argument (#17231) --- vlib/v/checker/fn.v | 2 ++ vlib/v/tests/array_filter_of_fn_mut_arg_test.v | 10 ++++++++++ 2 files changed, 12 insertions(+) create mode 100644 vlib/v/tests/array_filter_of_fn_mut_arg_test.v diff --git a/vlib/v/checker/fn.v b/vlib/v/checker/fn.v index eea915efa4..9ef4253166 100644 --- a/vlib/v/checker/fn.v +++ b/vlib/v/checker/fn.v @@ -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'] { diff --git a/vlib/v/tests/array_filter_of_fn_mut_arg_test.v b/vlib/v/tests/array_filter_of_fn_mut_arg_test.v new file mode 100644 index 0000000000..ebe8f83217 --- /dev/null +++ b/vlib/v/tests/array_filter_of_fn_mut_arg_test.v @@ -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 +}