-
Notifications
You must be signed in to change notification settings - Fork 558
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
array element lazily created at wrong index #16364
Comments
From zefram@fysh.orgCreated by zefram@fysh.orgSimple test case for some array operations: $ perl -lwe '$a[0] = undef; $a[1] = 1; sub foo { unshift @a, 7; $_[0] = 3; } foo($a[0]); print map { $_ // "u" } @a;' The above works as expected. Note that the sub call aliases $_[0] But if the initial $a[0] isn't explicitly initialised, this goes awry: $ perl -lwe '$a[1] = 1; sub foo { unshift @a, 7; $_[0] = 3; } foo($a[0]); print map { $_ // "u" } @a;' This time, $_[0] after the unshift is aliasing the *new* $a[0], which The same effect can be seen by using foreach(@a) to set up an alias: $ perl -lwe '$a[0] = undef; $a[1] = 1; foreach(@a) { unshift @a, 7; $_ = 3; last; } print map { $_ // "u" } @a;' The documentation for foreach has a caveat about it getting confused Perl Info
|
From @cpansproutOn Tue, 16 Jan 2018 16:42:53 -0800, zefram@fysh.org wrote:
The branch merged as 2a05854 includes a partial fix for the bug. It applies to nonexistent elements within the array. The fix doesn’t apply to elements outside the array. -- Father Chrysostomos |
The RT System itself - Status changed from 'new' to 'open' |
Migrated from rt.perl.org#132729 (status was 'open')
Searchable as RT132729$
The text was updated successfully, but these errors were encountered: