You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The code example was stored on my machine in a file named main.v. The contents of the file were as follows:
modulemainfnmain() {
muta:= [0, 1, 2, 3, 4, 5]
mutb:= a[2..4]
b[0] =7// `b[0]` is referring to `a[2]`println(a) // `[0, 1, 7, 3, 4, 5]`
b <<9// `b` has been reallocated and is now independent from `a`println(a) // `[0, 1, 7, 3, 4, 5]` - no changeprintln(b) // `[7, 3, 9]`
}
After I tried compiling the code above using the following command:
v run .
I got the following output:
src/main.v:6:12: notice: an implicit clone of the slice was done here
4 |
5 | mut a := [0, 1, 2, 3, 4, 5]
6 | mut b := a[2..4]
|~~~~~~
7 | b[0] = 7 // `b[0]` is referring to `a[2]`
8 | println(a) // `[0, 1, 7, 3, 4, 5]`
Details: src/main.v:6:12: details: To silence this notice, use either an explicit `a[..].clone()`,or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice. 4 | 5 | mut a := [0, 1, 2, 3, 4, 5] 6 | mut b := a[2..4]|~~~~~~ 7 | b[0] = 7 // `b[0]` is referring to `a[2]` 8 | println(a) // `[0, 1, 7, 3, 4, 5]`[0, 1, 2, 3, 4, 5][0, 1, 2, 3, 4, 5][7, 3, 9]
As you can see from the output above, the output of the two println(a) statements was the original unmodified array a:
[0, 1, 2, 3, 4, 5]
[0, 1, 2, 3, 4, 5]
The documentation, however, states that the output should have been the following:
Describe the issue
Operating System used: Linux Mint 21.2 Cinnamon Edition
Linux Kernel: 5.15.0-105-generic
V Language version installed: V 0.4.5 6a6d8e0
Code Editor used: Visual Studio Code with the V Programming Language plugin
The code example was stored on my machine in a file named main.v. The contents of the file were as follows:
After I tried compiling the code above using the following command:
v run .
I got the following output:
As you can see from the output above, the output of the two
println(a)
statements was the original unmodified array a:The documentation, however, states that the output should have been the following:
Links
https://github.com/vlang/v/blob/master/doc/docs.md#array-slices
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.
The text was updated successfully, but these errors were encountered: