Open
Description
Describe the bug
We pass a mutable array to os.walk
closure where the array is appended with content and the array outside the closure is not updated.
Reproduction Steps
import os
fn main() {
mut files := []string{}
os.walk('.', fn[mut files](file string) {
dump('${file}')
files << file
})
dump('${files}') // <- EMPTY!
}
Expected Behavior
[code.v:6] '$file': ./code
[code.v:6] '$file': ./code.v
[code.v:6] '$file': ./.vmodules/.cache/README.md
[code.v:9] '$files': [ code, code.v, README.md ] // <- three files outside the closure
Current Behavior
[code.v:6] '$file': ./code
[code.v:6] '$file': ./code.v
[code.v:6] '$file': ./.vmodules/.cache/README.md
[code.v:9] '$files': [] // no files outside the closure
Possible Solution
No response
Additional Information/Context
Warning: The bug is reproducible in the playground (see link below). Walking the current folder gives three files. Should be checked if the files are secure in case someone goes beyond just printing the names.
V version
V 0.4.8 9e71e32
Environment details (OS name and version, etc.)
https://play.vlang.io/p/6e3acff8fe
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.