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
Experimental refaliasing with local not restoring values when scope exited #14765
Comments
From kencotterill@netspace.net.au
In the original, I chose:
Category: core Severity: medium
This bug relates to the experimental feature 'refaliasing'
My expectation was that using the " \local our " form would restore values when the scope of the ' local ' was exited.
This wasn't the case and the observed behaviour was identical to
Test code: ------------------------------- use 5.022; @::data = (1 .. 3); say "Data before pop_sum: @::data"; sub pop_sum { my $total = 0; say "\tTotal: $total; Data: @data"; while (1) { return $total; sub pop_sum_ref { my $total = 0; say "\tTotal: $total; Data: @data"; while (1) { return $total; -------------------------------
Output: ------------------------------- Data before pop_sum_ref: 1 2 3 -------------------------------
My (unrealised) expectation for the ------------------------------- -------------------------------
Changing ------------------------------ sub \local our @data = shift; ------------------------------- to ------------------------------- sub \our @data = shift; ------------------------------- made
perl ------------------------------- Characteristics of this binary (from libperl): -------------------------------
Not sure how useful
Additional information available on request if required.
|
From @iabynOn Thu, Jun 18, 2015 at 07:12:12PM -0700, Ken Cotterill wrote:
I don't think its a bug. The first form is doing the equivalent of: @data = (1,2,3); which * creates a temporary new array; and then and which on scope exit: * frees the new temporary array and any elements it contains (which is The second form is doing the equivalent of: @data = (1,2,3); which * temporarily saves the old pointer to @data in the symbol table and then and which on scope exit: * restores the pointer in the symbol table to its original value Note that if you did something like @data = (1,2,3); then @data *would* contain (1,2,3) at the end. Or to put it another way, \local @data = \XXX localises the symbol table entry to whatever XXX is, while local @data = XXX localises the symbol table entry to a new array, and then populates the (In the above, whenever I've referred to 'symbol table entry', technically -- |
The RT System itself - Status changed from 'new' to 'open' |
From @ikegamiOn Tue, Jun 23, 2015 at 7:46 AM, Dave Mitchell <davem@iabyn.com> wrote:
I agree. `local our $x` is an attempt to approximate `my $x` using package variables. If you change `local our @data` for `my @data` in the program, the #!/usr/bin/env perl use 5.022; my @data = (1 .. 3); say "Data before pop_sum: @data"; sub pop_sum { my $total = 0; say "\tTotal: $total; Data: @data"; while (1) { return $total; sub pop_sum_ref { my $total = 0; say "\tTotal: $total; Data: @data"; while (1) { return $total; |
@iabyn - Status changed from 'open' to 'rejected' |
Migrated from rt.perl.org#125436 (status was 'rejected')
Searchable as RT125436$
The text was updated successfully, but these errors were encountered: