v
v copied to clipboard
global string array can't be modified in func
Describe the bug
global string array can be modified in main func, but can't be modified via function call
Expected Behavior
['aa', 'bb']
['1', 'bb']
Current Behavior
['aa']
['1', 'bb']
Reproduction Steps
test_globals.v
__global (
s []string
)
fn add_string(mut ss []string) {
ss << 'bb'
}
fn main() {
mut t := []string{}
s << 'aa'
t << '1'
add_string(mut s)
add_string(mut t)
println(s)
println(t)
}
v test_globals.v -enable-globals
Possible Solution
change
add_string(mut s)
to
add_string(mut &s)
can fix the bug
Additional Information/Context
No response
V version
0.3.3 612ac69
Environment details (OS name and version, etc.)
OS: linux, Ubuntu 22.04.1 LTS (WSL 2) Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i7-6500U CPU @ 2.50GHz CC version: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
getwd: /mnt/d/v vmodules: /home/lastgod/.vmodules vroot: /home/lastgod/github/lang/v vexe: /home/lastgod/github/lang/v/v vexe mtime: 2023-02-21 11:11:06 is vroot writable: true is vmodules writable: true V full version: V 0.3.3 612ac69
Git version: git version 2.34.1 Git vroot status: weekly.2023.08-6-g612ac694 .git/config present: true thirdparty/tcc status: thirdparty-linux-amd64 12f392c3