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

Modifications to mutable slices affect non-mut arrays #19120

Closed
uinz opened this issue Aug 12, 2023 · 0 comments · Fixed by #19137
Closed

Modifications to mutable slices affect non-mut arrays #19120

uinz opened this issue Aug 12, 2023 · 0 comments · Fixed by #19137
Labels
Bug This tag is applied to issues which reports bugs. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Type System Bugs/feature requests, that are related to the V types system.

Comments

@uinz
Copy link

uinz commented Aug 12, 2023

Describe the bug

Non-mut variables should not be modified

Expected Behavior

cannot declare a mut slice from a non-mut array

Current Behavior

Modifications to mutable slices affect non-mut arrays

Reproduction Steps

module main

fn main() {
	xs := [1, 2, 3, 4, 5, 6, 7, 8]

	mut s := xs[1..]

	s.sort(a > b)

	println(xs) // [1, 8, 7, 6, 5, 4, 3, 2]
}

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.0 3c26bff

Environment details (OS name and version, etc.)

V full version: V 0.4.0 4cf8328.3c26bff
OS: macos, macOS, 13.4.1, 22F82
Processor: 10 cpus, 64bit, little endian, Apple M1 Pro

getwd: /Users/xxx/Desktop/test_v
vexe: /opt/homebrew/Cellar/vlang/0.4/libexec/v
vexe mtime: 2023-08-12 00:33:32

vroot: OK, value: /opt/homebrew/Cellar/vlang/0.4/libexec
VMODULES: OK, value: /Users/xxx/.vmodules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.39.2 (Apple Git-143)
Git vroot status: weekly.2023.31-43-g3c26bfff
.git/config present: true

CC version: Apple clang version 14.0.3 (clang-1403.0.22.14.1)
thirdparty/tcc status: thirdparty-macos-arm64 a668e5a0
@uinz uinz added the Bug This tag is applied to issues which reports bugs. label Aug 12, 2023
@spytheman spytheman added Unit: Type System Bugs/feature requests, that are related to the V types system. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. labels Aug 13, 2023
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. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Type System Bugs/feature requests, that are related to the V types system.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants