[perl #113576] Restore err msg for &{+undef}
authorFather Chrysostomos <sprout@cpan.org>
Sat, 14 Jul 2012 01:16:43 +0000 (18:16 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 14 Jul 2012 02:58:59 +0000 (19:58 -0700)
This ‘Can't use an undefined value as a subroutine reference’ message
used to occur for &{+undef}, until commit 15ff848f77796 in 1997.

Then it started happening only for magic variables.

Non-magical variables would treat it the same as "", possibly dying
with ‘Undefined subroutine main:: called’, and possibly calling the
subroutine with that name.

Magical variables (&{$tied_undef}) started behaving the same way
(treating undef as "") with commit 7c75014e, in 2010.

This commit restores that message.

pp_hot.c
t/lib/croak/pp_hot
t/lib/warnings/9uninit

index 38c49a0..b2fc84e 100644 (file)
--- a/pp_hot.c
+++ b/pp_hot.c
@@ -2601,9 +2601,9 @@ PP(pp_entersub)
        else {
            const char *sym;
            STRLEN len;
-           sym = SvPV_nomg_const(sv, len);
-           if (!sym)
+           if (!SvOK(sv))
                DIE(aTHX_ PL_no_usym, "a subroutine");
+           sym = SvPV_nomg_const(sv, len);
            if (PL_op->op_private & HINT_STRICT_REFS)
                DIE(aTHX_ "Can't use string (\"%" SVf32 "\"%s) as a subroutine ref while \"strict refs\" in use", sv, len>32 ? "..." : "");
            cv = get_cvn_flags(sym, len, GV_ADD|SvUTF8(sv));
index 1e12fbb..0b65d7c 100644 (file)
@@ -11,3 +11,16 @@ Undefined subroutine &main::foo called at - line 3.
    &$foosub;
 EXPECT
 Undefined subroutine &main::foo called at - line 2.
+########
+# NAME calling undef scalar
+   &{+undef};
+EXPECT
+Can't use an undefined value as a subroutine reference at - line 1.
+########
+# NAME calling undef magical scalar
+   sub TIESCALAR {bless[]}
+   sub FETCH {}
+   tie $tied, "";
+   &$tied;
+EXPECT
+Can't use an undefined value as a subroutine reference at - line 4.
index 177a781..4068fab 100644 (file)
@@ -1225,8 +1225,6 @@ Use of uninitialized value $m1 in splice at - line 10.
 Use of uninitialized value $g1 in splice at - line 10.
 Use of uninitialized value in addition (+) at - line 10.
 Use of uninitialized value $m1 in method lookup at - line 13.
-Use of uninitialized value in subroutine entry at - line 15.
-Use of uninitialized value in subroutine entry at - line 16.
 Use of uninitialized value $m1 in warn at - line 18.
 Use of uninitialized value $g1 in warn at - line 18.
 foo at - line 18.