diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index 18c6c995fc..a4aa42b306 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -764,6 +764,7 @@ fn (mut p Parser) anon_fn() ast.AnonFn { name: arg.name typ: arg.typ is_mut: arg.is_mut + is_auto_deref: arg.is_mut || arg.is_auto_rec pos: arg.pos is_used: true is_arg: true diff --git a/vlib/v/tests/anon_fn_test.v b/vlib/v/tests/anon_fn_test.v index 20c22138d7..ba5b4790c6 100644 --- a/vlib/v/tests/anon_fn_test.v +++ b/vlib/v/tests/anon_fn_test.v @@ -21,3 +21,23 @@ fn test_anon_assign_struct() { } assert w.fn_() } + +// + +fn fnormal(mut acc []string, e int) []string { + acc << e.str() + return acc +} + +fn test_anon_fn_returning_a_mut_parameter_should_act_the_same_as_normal_fn_returning_a_mut_parameter() { + fanon := fn (mut acc []string, e int) []string { + acc << e.str() + return acc + } + assert '${fanon}' == '${fnormal}' + mut a := ['a', 'b', 'c'] + mut b := a.clone() + x := fanon(mut a, 123) + y := fnormal(mut b, 123) + assert a == b +}