checker: fix index expr that left is if expr (fix #22654)#22661
checker: fix index expr that left is if expr (fix #22654)#22661medvednikov merged 4 commits intovlang:masterfrom
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] = 999better 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