-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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 index expr that left is if expr (fix #22654) #22661
Conversation
My question is: Do we really want this to work? To me, it is confusing/unreadable trying to figure out what will happen. If it takes me a minute to figure it out, how much will it affect newer developers? And how is (if true { array_a } else { array_b })[0] = 999 better than if true { array_a[0] = 999 } else { array_b[0] = 999 } other than being a few characters shorter to type?? |
I agree with @JalonSolov here. I'd just make it an error. |
Or, it is better to simply write: mut arr := if true { array_a } else { array_b }
arr[0] = 999 |
@StunxFS not really, because V requires cloning on arr1=arr2, or unsafe references. Better to avoid both. |
I think this is valid usage and should not be reported wrong. |
Yes, it is wrong because, as Alex said, it may require either cloning or unsafe (especially since both arrays shown are immutable). The code as given is incorrect since it does neither. If one of them was declared mutable but the other wasn't, the |
I agree with @yuyi98 - the code is valid, even if it does seem weird. |
This works in C ( (condition) ? arrayA : arrayB )[0] = 999; and in all langs that have if expressions / |
If the concern is about mutability, we can check that both arrays are mutable for the simple case of |
This PR fix index expr that left is if expr (fix #22654).
Huly®: V_0.6-21110