1
0
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:
Delyan Angelov 2023-07-06 02:30:26 +03:00 committed by GitHub
parent cd6330e218
commit d851ecffb7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 0 deletions

View File

@ -764,6 +764,7 @@ fn (mut p Parser) anon_fn() ast.AnonFn {
name: arg.name name: arg.name
typ: arg.typ typ: arg.typ
is_mut: arg.is_mut is_mut: arg.is_mut
is_auto_deref: arg.is_mut || arg.is_auto_rec
pos: arg.pos pos: arg.pos
is_used: true is_used: true
is_arg: true is_arg: true

View File

@ -21,3 +21,23 @@ fn test_anon_assign_struct() {
} }
assert w.fn_() 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
}