Skip to content

Commit

Permalink
Don't autovivify stashes as soon as the lexer sees them.
Browse files Browse the repository at this point in the history
This makes defined %foo::bar:: work again.
Add tests for it, remove note in perldelta about having broken it.

p4raw-id: //depot/perl@26370
  • Loading branch information
rgs committed Dec 15, 2005
1 parent 4634a85 commit adc51b9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 15 deletions.
10 changes: 0 additions & 10 deletions pod/perl593delta.pod
Expand Up @@ -15,16 +15,6 @@ L<perl592delta> for the differences between 5.8.0 and 5.9.2.
C<_> is now forced to be a bareword after a filetest operator. This solves
a number of misparsing issues when a global C<_> subroutine is defined.

=head2 C<defined %foo::bar::>

This used to report whether the C<foo::bar> package was created. Now it's
always true, as a side-effect of a change to shrink the internal size of
hash structures. Note that using C<defined> on hashes was deprecated
anyway. To achieve the same result, you can use a symbolic reference
instead (and this is backwards-compatible):

defined %{"foo::bar::"}

=head1 Core Enhancements

=head1 Modules and Pragmata
Expand Down
14 changes: 13 additions & 1 deletion t/op/stash.t
Expand Up @@ -7,7 +7,7 @@ BEGIN {

require "./test.pl";

plan( tests => 2 );
plan( tests => 8 );

# Used to segfault (bug #15479)
fresh_perl_is(
Expand All @@ -24,3 +24,15 @@ fresh_perl_is(
{ switches => [ '-w' ] },
q(Insert a non-GV in a stash, under warnings 'once'),
);

ok( !defined %oedipa::maas::, q(stashes aren't defined if not used) );
ok( !defined %{"oedipa::maas::"}, q(- work with hard refs too) );

ok( defined %tyrone::slothrop::, q(stashes are defined if seen at compile time) );
ok( defined %{"tyrone::slothrop::"}, q(- work with hard refs too) );

ok( defined %bongo::shaftsbury::, q(stashes are defined if a var is seen at compile time) );
ok( defined %{"bongo::shaftsbury::"}, q(- work with hard refs too) );

package tyrone::slothrop;
$bongo::shaftsbury::scalar = 1;
13 changes: 9 additions & 4 deletions toke.c
Expand Up @@ -5661,10 +5661,15 @@ S_pending_ident(pTHX)
/* build ops for a bareword */
yylval.opval = (OP*)newSVOP(OP_CONST, 0, newSVpv(PL_tokenbuf+1, 0));
yylval.opval->op_private = OPpCONST_ENTERED;
gv_fetchpv(PL_tokenbuf+1, PL_in_eval ? (GV_ADDMULTI | GV_ADDINEVAL) : TRUE,
((PL_tokenbuf[0] == '$') ? SVt_PV
: (PL_tokenbuf[0] == '@') ? SVt_PVAV
: SVt_PVHV));
gv_fetchpv(
PL_tokenbuf+1,
PL_in_eval
? (GV_ADDMULTI | GV_ADDINEVAL)
/* if the identifier refers to a stash, don't autovivify it */
: !(*PL_tokenbuf == '%' && *(d = PL_tokenbuf + strlen(PL_tokenbuf) - 1) == ':' && d[-1] == ':'),
((PL_tokenbuf[0] == '$') ? SVt_PV
: (PL_tokenbuf[0] == '@') ? SVt_PVAV
: SVt_PVHV));
return WORD;
}

Expand Down

0 comments on commit adc51b9

Please sign in to comment.