Fix scoping and slice update in Array.reserve#22351
Conversation
|
Thanks for your pull request and interest in making D better, @gorsing! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#22351" |
|
I don't understand the justification; the common line of code was factored out of the two version branches, now it's duplicated again. How does this improve 'correctness and robustness'? |
|
@dkorpel Thanks for your time |
|
|
|
Thanks — you’re right that The reason I kept the slice update inside each branch is to make the storage’s lifetime and ownership explicit: in |
|
I don't think this is worth discussing at length so I'll just merge this, but in the future please make code changes based on actual issues from dmd usage, instead of perceived (lifetime) issues that are actually not causing any problems at all. |
This MR fixes a correctness issue in Array.reserve(), where the slice was rebound
using a pointer declared in a narrower scope.
The code now explicitly updates
datato point to the newly allocated orreallocated storage in each branch, ensuring correct variable lifetime and
well-defined behavior.
There is no behavioral change:
This change improves correctness and robustness without affecting semantics.
#22327
#22284