mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix anonymous fns parameter checks, behaving differently than named fns (fix #18779) (#18785)
This commit is contained in:
parent
cd6330e218
commit
d851ecffb7
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user