Skip to content

Commit 257296e

Browse files
author
Zefram
committed
restore deparsing style for \&foo
When deparsing a reference to a sub in the current package, other than in a call expression, with "use strict 'vars'" in effect and no lexical sub of the same name in scope, commit dd66616 accidentally changed the deparsing from "&main::foo" to "&foo". Both deparsings are correct, and the short one arguably preferable. In fact, the deparsing was originally of the short form, but changed to the long form (probably accidentally) in Perl 5.21.7, when the deparser started adding the package to distinguish package subs from lexical subs of the same name. Nevertheless, it was not the intention to change this output in that edit, and it broke a CPAN module's tests. Consequently, this commit restores the long-form deparsing in this case.
1 parent e2091bb commit 257296e

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

lib/B/Deparse.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,7 +1878,7 @@ sub maybe_qualify {
18781878
if
18791879
$name =~ /^(?!\d)\w/ # alphabetic
18801880
&& $v !~ /^\$[ab]\z/ # not $a or $b
1881-
&& $v =~ /\A[\$\@\%]/ # scalar, array, or hash
1881+
&& $v =~ /\A[\$\@\%\&]/ # scalar, array, hash, or sub
18821882
&& !$globalnames{$name} # not a global name
18831883
&& $self->{hints} & $strict_bits{vars} # strict vars
18841884
&& !$self->lex_in_scope($v,1) # no "our"
@@ -4883,7 +4883,7 @@ sub pp_entersub {
48834883
$proto = $cv->PV if $cv->FLAGS & SVf_POK;
48844884
}
48854885
$simple = 1; # only calls of named functions can be prototyped
4886-
$kid = $self->maybe_qualify("&", $self->gv_name($gv));
4886+
$kid = $self->maybe_qualify("!", $self->gv_name($gv));
48874887
my $fq;
48884888
# Fully qualify any sub name that conflicts with a lexical.
48894889
if ($self->lex_in_scope("&$kid")

lib/B/Deparse.t

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2864,6 +2864,7 @@ print %CORE::foo, %CORE::foo::bar;
28642864
print $CORE::foo{'a'}, $CORE::foo::bar{'a'};
28652865
print &CORE::foo, &CORE::foo::bar;
28662866
print &CORE::foo(), &CORE::foo::bar();
2867+
print \&CORE::foo, \&CORE::foo::bar;
28672868
print *CORE::foo, *CORE::foo::bar;
28682869
print stat CORE::foo::, stat CORE::foo::bar;
28692870
print CORE::foo:: 1;
@@ -2878,6 +2879,7 @@ print %foo, %foo::, %foo::::;
28782879
print $foo{'a'}, $foo::{'a'}, $foo::::{'a'};
28792880
print &foo, &foo::, &foo::::;
28802881
print &foo(), &foo::(), &foo::::();
2882+
print \&foo, \&foo::, \&foo::::;
28812883
print *foo, *foo::, *foo::::;
28822884
print stat Foo, stat Foo::::;
28832885
print Foo 1;
@@ -2891,6 +2893,7 @@ print %CORE, %CORE::, %CORE::::;
28912893
print $CORE{'a'}, $CORE::{'a'}, $CORE::::{'a'};
28922894
print &CORE, &CORE::, &CORE::::;
28932895
print &CORE(), &CORE::(), &CORE::::();
2896+
print \&CORE, \&CORE::, \&CORE::::;
28942897
print *CORE, *CORE::, *CORE::::;
28952898
print stat CORE, stat CORE::::;
28962899
print CORE 1;
@@ -2901,7 +2904,34 @@ print %CORE::foo, %CORE::foo::, %CORE::foo::::;
29012904
print $CORE::foo{'a'}, $CORE::foo::{'a'}, $CORE::foo::::{'a'};
29022905
print &CORE::foo, &CORE::foo::, &CORE::foo::::;
29032906
print &CORE::foo(), &CORE::foo::(), &CORE::foo::::();
2907+
print \&CORE::foo, \&CORE::foo::, \&CORE::foo::::;
29042908
print *CORE::foo, *CORE::foo::, *CORE::foo::::;
29052909
print stat CORE::foo::, stat CORE::foo::::;
29062910
print CORE::foo:: 1;
29072911
print CORE::foo:::: 2;
2912+
####
2913+
# \&foo
2914+
my sub foo {
2915+
1;
2916+
}
2917+
no strict 'vars';
2918+
print \&main::foo;
2919+
print \&{foo};
2920+
print \&bar;
2921+
use strict 'vars';
2922+
print \&main::foo;
2923+
print \&{foo};
2924+
print \&main::bar;
2925+
####
2926+
# exists(&foo)
2927+
my sub foo {
2928+
1;
2929+
}
2930+
no strict 'vars';
2931+
print exists &main::foo;
2932+
print exists &{foo};
2933+
print exists &bar;
2934+
use strict 'vars';
2935+
print exists &main::foo;
2936+
print exists &{foo};
2937+
print exists &main::bar;

0 commit comments

Comments
 (0)