diff options
author | Father Chrysostomos <sprout@cpan.org> | 2014-08-28 06:31:48 -0700 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2014-08-28 06:33:25 -0700 |
commit | 18691622911f2e18df42a5a98ea4c42386f4e558 (patch) | |
tree | ee9295e715ff4c67d5cc3620170a57dd2c6dae62 | |
parent | 4dda930beadeaf9376af54b63f1b18c3c4b4f23a (diff) | |
download | perl-18691622911f2e18df42a5a98ea4c42386f4e558.tar.gz |
Fix crash when lex subs are used for AUTOLOAD
-rw-r--r-- | gv.c | 2 | ||||
-rw-r--r-- | t/op/lexsub.t | 20 |
2 files changed, 20 insertions, 2 deletions
@@ -1198,7 +1198,7 @@ Perl_gv_autoload_pvn(pTHX_ HV *stash, const char *name, STRLEN len, U32 flags) * use that, but for lack of anything better we will use the sub's * original package to look up $AUTOLOAD. */ - varstash = GvSTASH(CvGV(cv)); + varstash = CvNAMED(cv) ? CvSTASH(cv) : GvSTASH(CvGV(cv)); vargv = *(GV**)hv_fetch(varstash, S_autoload, S_autolen, TRUE); ENTER; diff --git a/t/op/lexsub.t b/t/op/lexsub.t index d5fdcb1374..54bb985f7d 100644 --- a/t/op/lexsub.t +++ b/t/op/lexsub.t @@ -7,7 +7,7 @@ BEGIN { *bar::is = *is; *bar::like = *like; } -plan 120; +plan 122; # -------------------- Errors with feature disabled -------------------- # @@ -313,6 +313,15 @@ like runperl( ), qr/syntax error/, 'referencing a state sub after a syntax error does not crash'; +{ + state $stuff; + package A { + state sub foo{ $stuff .= our $AUTOLOAD } + *A::AUTOLOAD = \&foo; + } + A::bar(); + is $stuff, 'A::bar', 'state sub assigned to *AUTOLOAD can autoload'; +} # -------------------- my -------------------- # @@ -606,6 +615,15 @@ like runperl( ), qr/syntax error/, 'referencing a my sub after a syntax error does not crash'; +{ + state $stuff; + package A { + my sub foo{ $stuff .= our $AUTOLOAD } + *A::AUTOLOAD = \&foo; + } + A::bar(); + is $stuff, 'A::bar', 'my sub assigned to *AUTOLOAD can autoload'; +} # -------------------- Interactions (and misc tests) -------------------- # |