Stop undef &foo from crashing on lex subs
authorFather Chrysostomos <sprout@cpan.org>
Sun, 23 Jun 2013 19:06:11 +0000 (12:06 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 23 Jun 2013 19:06:11 +0000 (12:06 -0700)
pp.c
t/op/lexsub.t

diff --git a/pp.c b/pp.c
index 77a9f01..f8a31e2 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -973,7 +973,12 @@ PP(pp_undef)
                           "Constant subroutine %"SVf" undefined",
                           SVfARG(CvANON((const CV *)sv)
                              ? newSVpvs_flags("(anonymous)", SVs_TEMP)
-                             : sv_2mortal(newSVhek(GvENAME_HEK(CvGV((const CV *)sv))))));
+                             : sv_2mortal(newSVhek(
+                                CvNAMED(sv)
+                                 ? CvNAME_HEK((CV *)sv)
+                                 : GvENAME_HEK(CvGV((const CV *)sv))
+                               ))
+                           ));
        /* FALLTHROUGH */
     case SVt_PVFM:
        {
index 27b6de7..0141399 100644 (file)
@@ -8,7 +8,7 @@ BEGIN {
     *bar::like = *like;
 }
 no warnings 'deprecated';
-plan 135;
+plan 136;
 
 # -------------------- Errors with feature disabled -------------------- #
 
@@ -703,3 +703,11 @@ like runperl(
      ),
      qr/Deep recursion on subroutine "foo"/,
     'deep recursion warnings for lexical subs do not crash';
+
+like runperl(
+      switches => [ '-Mfeature=:all', '-Mwarnings=FATAL,all', '-M-warnings=experimental::lexical_subs' ],
+      prog     => 'my sub foo() { 42 } undef &foo',
+      stderr   => 1
+     ),
+     qr/Constant subroutine foo undefined at /,
+    'constant undefinition warnings for lexical subs do not crash';