From f132ae694cadce5cea5b006969b9b9ad169ecf64 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 26 Aug 2011 06:20:01 -0700 Subject: [PATCH] Make *{undef} self-consistent Commit afd1915d made filehandle vivification work on hash and array elements, but in doing so it accidentally changed *{;undef} = 3; to do the same thing as *{""} = 3; while leaving *{$some_undefined_variable} an error. This commit adjusts the if() conditions in S_rv2gv (formerly in pp_rv2gv) in pp.c to make PL_sv_undef follow the same path as before. It also removes the uninit tests from lib/warnings/pp, since they are now errors. The uninit warning in rv2gv is only triggered now when it is implicit, as in close(). That is already tested in lib/warnings/9uninit. --- pp.c | 4 ++-- t/lib/warnings/pp | 11 ----------- t/op/gv.t | 10 +++++++++- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pp.c b/pp.c index ea6eb00..e2427f8 100644 --- a/pp.c +++ b/pp.c @@ -176,11 +176,11 @@ S_rv2gv(pTHX_ SV *sv, const bool vivify_sv, const bool strict, } else { if (!isGV_with_GP(sv)) { - if (!SvOK(sv) && sv != &PL_sv_undef) { + if (!SvOK(sv)) { /* If this is a 'my' scalar and flag is set then vivify * NI-S 1999/05/07 */ - if (vivify_sv) { + if (vivify_sv && sv != &PL_sv_undef) { GV *gv; if (SvREADONLY(sv)) Perl_croak_no_modify(aTHX); diff --git a/t/lib/warnings/pp b/t/lib/warnings/pp index 2251b94..e6b3802 100644 --- a/t/lib/warnings/pp +++ b/t/lib/warnings/pp @@ -6,9 +6,6 @@ Attempt to use reference as lvalue in substr $a = "ab" ; $b = \$a ; substr($b, 1,1) = $b - Use of uninitialized value in ref-to-glob cast [pp_rv2gv()] - *b = *{ undef()} - Use of uninitialized value in scalar dereference [pp_rv2sv()] my $a = undef ; my $b = $$a @@ -65,14 +62,6 @@ splice() offset past end of array at - line 4. splice() offset past end of array at - line 6. ######## # pp.c -use warnings 'uninitialized' ; -*x = *{ undef() }; -no warnings 'uninitialized' ; -*y = *{ undef() }; -EXPECT -Use of uninitialized value in ref-to-glob cast at - line 3. -######## -# pp.c use warnings 'uninitialized'; $x = undef; $y = $$x; no warnings 'uninitialized' ; diff --git a/t/op/gv.t b/t/op/gv.t index c4570e3..2930e12 100644 --- a/t/op/gv.t +++ b/t/op/gv.t @@ -12,7 +12,7 @@ BEGIN { use warnings; -plan( tests => 234 ); +plan( tests => 236 ); # type coersion on assignment $foo = 'foo'; @@ -898,6 +898,14 @@ ok eval { 'no error when gp_free calls a destructor that assigns to the gv'; } +# *{undef} +eval { *{my $undef} = 3 }; +like $@, qr/^Can't use an undefined value as a symbol reference at /, + '*{ $undef } assignment'; +eval { *{;undef} = 3 }; +like $@, qr/^Can't use an undefined value as a symbol reference at /, + '*{ ;undef } assignment'; + __END__ Perl Rules -- 2.7.4