Skip to content
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

Global refalias access from sub #17002

Open
p5pRT opened this issue May 16, 2019 · 5 comments
Open

Global refalias access from sub #17002

p5pRT opened this issue May 16, 2019 · 5 comments

Comments

@p5pRT
Copy link

p5pRT commented May 16, 2019

Migrated from rt.perl.org#134111 (status was 'open')

Searchable as RT134111$

@p5pRT
Copy link
Author

p5pRT commented May 16, 2019

From Thomas.Schweiger@rohde-schwarz.com

I am not sure whether i have missed something maybe this little demo script demonstrates a bug​:
I expect SomeSub to print
SomeSub​: hashRef​: a
SomeSub​: hash​: a
but it does print​:
SomeSub​: hashRef​: a
SomeSub​: hash​:

I tested it against perl 5.30-RC1 and 5.28.1 and both show the same behavior.

#!/usr/bin/env perl

use feature 'declared_refs';
use feature 'refaliasing';
no warnings "experimental​::refaliasing";
no warnings "experimental​::declared_refs";

# Define a hash and assign it to a hashRef
my $hashRef={ '1' => 'a' };

# Alias %hash to the previously defined hashRef
\my %hash=$hashRef;

# Access the (global) $hashRef and the (global) aliased %hash.
# This works fine. Both print the same.
print "hashRef​: ${$hashRef}{'1'}\n";
print "hash​: $hash{'1'}\n";

# Call SomeSub
SomeSub();

# A sub that accesses the (global) $hashRef and the (global) aliased %hash.
# Here is the problem​: access via $hashRef works, but access via %hash does not.
# Did I miss something here or could this be a bug?
sub SomeSub {
  print "SomeSub​: hashRef​: ${$hashRef}{'1'}\n";
  print "SomeSub​: hash​: $hash{'1'}\n";
}

# In the latest perl 5.30-RC1, this prints​:
# hashRef​: a
# hash​: a
# SomeSub​: hashRef​: a
# SomeSub​: hash​:

@p5pRT
Copy link
Author

p5pRT commented May 16, 2019

From @jkeenan

[This didn't show up well in RT, so I'm showing it here. -- JK]

On Thu, 16 May 2019 14​:48​:03 GMT, Thomas.Schweiger@​rohde-schwarz.com wrote​:

I am not sure whether i have missed something maybe this little demo
script demonstrates a bug​:
I expect SomeSub to print
SomeSub​: hashRef​: a
SomeSub​: hash​: a
but it does print​:
SomeSub​: hashRef​: a
SomeSub​: hash​:

I tested it against perl 5.30-RC1 and 5.28.1 and both show the same
behavior.

#!/usr/bin/env perl

use feature 'declared_refs';
use feature 'refaliasing';
no warnings "experimental​::refaliasing";
no warnings "experimental​::declared_refs";

# Define a hash and assign it to a hashRef
my $hashRef={ '1' => 'a' };

# Alias %hash to the previously defined hashRef
\my %hash=$hashRef;

# Access the (global) $hashRef and the (global) aliased %hash.
# This works fine. Both print the same.
print "hashRef​: ${$hashRef}{'1'}\n";
print "hash​: $hash{'1'}\n";

# Call SomeSub
SomeSub();

# A sub that accesses the (global) $hashRef and the (global) aliased
%hash.
# Here is the problem​: access via $hashRef works, but access via %hash
does not.
# Did I miss something here or could this be a bug?
sub SomeSub {
print "SomeSub​: hashRef​: ${$hashRef}{'1'}\n";
print "SomeSub​: hash​: $hash{'1'}\n";
}

# In the latest perl 5.30-RC1, this prints​:
# hashRef​: a
# hash​: a
# SomeSub​: hashRef​: a
# SomeSub​: hash​:

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented May 16, 2019

From [Unknown Contact. See original ticket]

[This didn't show up well in RT, so I'm showing it here. -- JK]

On Thu, 16 May 2019 14​:48​:03 GMT, Thomas.Schweiger@​rohde-schwarz.com wrote​:

I am not sure whether i have missed something maybe this little demo
script demonstrates a bug​:
I expect SomeSub to print
SomeSub​: hashRef​: a
SomeSub​: hash​: a
but it does print​:
SomeSub​: hashRef​: a
SomeSub​: hash​:

I tested it against perl 5.30-RC1 and 5.28.1 and both show the same
behavior.

#!/usr/bin/env perl

use feature 'declared_refs';
use feature 'refaliasing';
no warnings "experimental​::refaliasing";
no warnings "experimental​::declared_refs";

# Define a hash and assign it to a hashRef
my $hashRef={ '1' => 'a' };

# Alias %hash to the previously defined hashRef
\my %hash=$hashRef;

# Access the (global) $hashRef and the (global) aliased %hash.
# This works fine. Both print the same.
print "hashRef​: ${$hashRef}{'1'}\n";
print "hash​: $hash{'1'}\n";

# Call SomeSub
SomeSub();

# A sub that accesses the (global) $hashRef and the (global) aliased
%hash.
# Here is the problem​: access via $hashRef works, but access via %hash
does not.
# Did I miss something here or could this be a bug?
sub SomeSub {
print "SomeSub​: hashRef​: ${$hashRef}{'1'}\n";
print "SomeSub​: hash​: $hash{'1'}\n";
}

# In the latest perl 5.30-RC1, this prints​:
# hashRef​: a
# hash​: a
# SomeSub​: hashRef​: a
# SomeSub​: hash​:

--
James E Keenan (jkeenan@​cpan.org)

@p5pRT
Copy link
Author

p5pRT commented May 19, 2019

From @davidnicol

looks like a bug to me, although I haven't studied how lexical aliases are
documented. I'd guess that the lexical getting closed over in somesub is
the compile-time placeholder, rather than the new meaning for the name
assigned at aliasing time, which is runtime. If I'm right you should be
able to use BEGIN blocks to make the aliasing happen before the compilation
of the closure. That wouldn't mean it isn't a bug though, as its reasonable
to expect aliasing a lexical to alias other instances of the same name too.

On Thu, May 16, 2019 at 2​:47 PM Thomas Schweiger (via RT) <
perlbug-followup@​perl.org> wrote​:

# New Ticket Created by Thomas Schweiger
# Please include the string​: [perl #134111]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl5/Ticket/Display.html?id=134111 >

I am not sure whether i have missed something maybe this little demo
script demonstrates a bug​:
I expect SomeSub to print
SomeSub​: hashRef​: a
SomeSub​: hash​: a
but it does print​:
SomeSub​: hashRef​: a
SomeSub​: hash​:

I tested it against perl 5.30-RC1 and 5.28.1 and both show the same
behavior.

#!/usr/bin/env perl

use feature 'declared_refs';
use feature 'refaliasing';
no warnings "experimental​::refaliasing";
no warnings "experimental​::declared_refs";

# Define a hash and assign it to a hashRef
my $hashRef={ '1' => 'a' };

# Alias %hash to the previously defined hashRef
\my %hash=$hashRef;

# Access the (global) $hashRef and the (global) aliased %hash.
# This works fine. Both print the same.
print "hashRef​: ${$hashRef}{'1'}\n";
print "hash​: $hash{'1'}\n";

# Call SomeSub
SomeSub();

# A sub that accesses the (global) $hashRef and the (global) aliased %hash.
# Here is the problem​: access via $hashRef works, but access via %hash
does not.
# Did I miss something here or could this be a bug?
sub SomeSub {
print "SomeSub​: hashRef​: ${$hashRef}{'1'}\n";
print "SomeSub​: hash​: $hash{'1'}\n";
}

# In the latest perl 5.30-RC1, this prints​:
# hashRef​: a
# hash​: a
# SomeSub​: hashRef​: a
# SomeSub​: hash​:

--
"Plant yourself like a tree beside the river of truth and tell the whole
world​: No, you move."

@p5pRT
Copy link
Author

p5pRT commented May 19, 2019

The RT System itself - Status changed from 'new' to 'open'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants