-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
checker: fix assigning array slice (fix #19120) #19137
Conversation
slice2 := unsafe { arr2[..3] } | ||
slice3 := unsafe { arr2[3..] } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should not need unsafe, arr2
is immutable, but slice2
and slice3
are not mutable too -> they can not be used to make modifications to arr2
.
"unsafe" here is not just about not modifying the immutable array. |
That is a valid viewpoint, now that I think about it more. It will make some programs a little more cumbersome, but clearer/less surprising indeed. |
This PR fix assigning array slice (fix #19120).
mut a := arr[..i]
->mut a := arr[..i].clone()
if left var or right var is mut and not inside unsafe.