Skip to content

modification of a global array variable does not succeed, when passed with mut x to an initialisation function #23873

Description

@spytheman
V version: V 0.4.9 f8b70b7, press to see full `v doctor` output
V full version V 0.4.9 52cd627.f8b70b7
OS linux, Ubuntu 20.04.6 LTS
Processor 4 cpus, 64bit, little endian, Intel(R) Core(TM) i3-3225 CPU @ 3.30GHz
Memory 0.31GB/15.05GB
V executable /home/delian/code/v/v
V last modified time 2025-03-06 11:20:58
V home dir OK, value: /home/delian/code/v
VMODULES OK, value: /home/delian/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/delian/code/v
env VFLAGS "-no-parallel"
Git version git version 2.48.1
V git status weekly.2025.10-21-gf8b70b72
.git/config present true
cc version cc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
gcc version gcc (Ubuntu 10.5.0-1ubuntu1~20.04) 10.5.0
clang version clang version 10.0.0-4ubuntu1
tcc version tcc version 0.9.28rc 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
tcc git status thirdparty-linux-amd64 0134e9b9
emcc version N/A
glibc version ldd (Ubuntu GLIBC 2.31-0ubuntu9.16) 2.31

What did you do?
./v -g -o vdbg cmd/v && ./vdbg x.v && x

@[has_globals]
module main

struct Rectangle {
	x int
	y int
	w int
	h int
}

__global bricks = []Rectangle{}

fn init_bricks(mut bricks []Rectangle) {
	for i in 0..5 {
		bricks << Rectangle{i, 2*i, 3*i, 4*i}		
	}
	dump(bricks.len)
}

fn main() {
	dump(bricks.len)
	init_bricks(mut bricks)
	dump(bricks.len)
}

What did you see?

[x.v:21] bricks.len: 0
[x.v:17] bricks.len: 5
[x.v:23] bricks.len: 0

What did you expect to see?

[x.v:21] bricks.len: 0
[x.v:17] bricks.len: 5
[x.v:23] bricks.len: 5

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.

Metadata

Metadata

Assignees

Labels

BugThis tag is applied to issues which reports bugs.Unit: CompilerBugs/feature requests, that are related to the V compiler in general.Unit: cgenBugs/feature requests, that are related to the default C generating backend.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions