From 79a3e5ea36208f2f54e36fa3a73c72808a6d0ad8 Mon Sep 17 00:00:00 2001 From: Father Chrysostomos Date: Fri, 13 Jul 2012 18:16:43 -0700 Subject: [PATCH] [perl #113576] Restore err msg for &{+undef} MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 4 ++-- t/lib/croak/pp_hot | 13 +++++++++++++ t/lib/warnings/9uninit | 2 -- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/pp_hot.c b/pp_hot.c index 38c49a0..b2fc84e 100644 --- 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)); diff --git a/t/lib/croak/pp_hot b/t/lib/croak/pp_hot index 1e12fbb..0b65d7c 100644 --- a/t/lib/croak/pp_hot +++ b/t/lib/croak/pp_hot @@ -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. diff --git a/t/lib/warnings/9uninit b/t/lib/warnings/9uninit index 177a781..4068fab 100644 --- a/t/lib/warnings/9uninit +++ b/t/lib/warnings/9uninit @@ -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. -- 2.7.4