Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mutating array methods like insert and prepend work without mut declaration #22850

Closed
ttytm opened this issue Nov 13, 2024 · 0 comments · Fixed by #22853
Closed

Mutating array methods like insert and prepend work without mut declaration #22850

ttytm opened this issue Nov 13, 2024 · 0 comments · Fixed by #22853
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@ttytm
Copy link
Member

ttytm commented Nov 13, 2024

Describe the bug

a0 := [1, 2]
a1 := [3, 4]
a2 := [5, 6]

a2.prepend(a1)
a1.insert(0, a0)

dump(a2)
dump(a1)
a2: [3, 4, 5, 6]
a1: [1, 2, 3, 4]

Expected Behavior

Arrays that are mutated require a mut declaration like the methods function signature and examples indicate.

pub fn (mut a array) insert(i int, val voidptr)
// ...
// Example:
mut a := [1, 2, 4]
a.insert(2, 3)          // a now is [1, 2, 3, 4]
mut b := [3, 4]
b.insert(0, [1, 2])     // b now is [1, 2, 3, 4]

E.g. working mut requirement for the pop method:

a := [1, 2]
a.pop() // Diagnostics: `a1` is immutable, declare it with `mut` to make it mutable []

Possible Solution

No response

Additional Information/Context

No response

V version

⬇️

Environment details (OS name and version, etc.)

V full version: V 0.4.8 988f8b4.ee3a182
OS: linux, "EndeavourOS Linux"
Processor: 16 cpus, 64bit, little endian, 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz

getwd: /home/t/Sync/Dev/V/projects/grd
vexe: /home/t/Sync/Dev/V/v/v
vexe mtime: 2024-11-13 18:52:01

vroot: OK, value: /home/t/Sync/Dev/V/v
VMODULES: OK, value: /home/t/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.47.0
Git vroot status: weekly.2024.46-18-gee3a182d-dirty
.git/config present: true

CC version: cc (GCC) 14.2.1 20240910
emcc version: N/A
thirdparty/tcc status: thirdparty-linux-amd64 0134e9b9

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.

Huly®: V_0.6-21295

@ttytm ttytm added the Bug This tag is applied to issues which reports bugs. label Nov 13, 2024
spytheman pushed a commit that referenced this issue Nov 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant