v icon indicating copy to clipboard operation
v copied to clipboard

mut array as parameter

Open dmscripto opened this issue 7 years ago • 7 comments

fn print_array(array mut []int) {
	for n in array {
		println(n)
	}
}

fn main() {
	mut array := [1, 2, 34]
	print_array(mut array)
}

Output: You just found a bug. V can't compile this program, but it should. Please create a GitHub issue.

Without 'mut' it works as expected.

dmscripto avatar Jun 21 '19 09:06 dmscripto

Mutable arguments are a recent addition, and I think it's clear I don't use them at all in my code :)

Will fix after the release.

medvednikov avatar Jun 21 '19 15:06 medvednikov

In the future V should actually not compile this example because array is not modified at all.

medvednikov avatar Jun 21 '19 15:06 medvednikov

In the future V should actually not compile this example because array is not modified at all.

Does it means that i should return a new array if i want modify array?

han2015 avatar Jun 22 '19 12:06 han2015

For now yes, until the bug is fixed.

medvednikov avatar Jun 22 '19 12:06 medvednikov

I think it's clear I don't use them at all in my code :)

Does it mean V has no tests even for basic features?

zenwarr avatar Jun 22 '19 12:06 zenwarr

No it doesn't. But there definitely should be more tests.

medvednikov avatar Jun 22 '19 12:06 medvednikov

Tests have been made and are in active development. The original issue still doesn't work, but that can be discussed in the new issue #652.

Bowero avatar Jun 26 '19 19:06 Bowero