summaryrefslogtreecommitdiff
path: root/lib/B/Deparse.t
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2014-12-30 16:32:59 -0800
committerFather Chrysostomos <sprout@cpan.org>2015-02-16 02:17:37 -0800
commit2c5ddcd35d33d3b4d96c9015e680cb83a18afa91 (patch)
tree56c36f6c13b977985fd02c5317e290b89ae4214e /lib/B/Deparse.t
parent5abe6a2ac7cf4da6de3b04c8d87fd4568b271236 (diff)
downloadperl-2c5ddcd35d33d3b4d96c9015e680cb83a18afa91.tar.gz
Deparse state sub defined in inner subs
When we have ‘state sub x; sub { sub x { ... } }’, the actual &x sub- routine is not contained in the pad of the anonymous sub. There is only a pad entry pointing to the outer pad. So we have go digging for it by following ->OUTSIDE pointers. This is only a partial fix. If you wrap the code above in eval 'sub{...}' and deparse it, the state sub definition is missing, because it is not available via ->OUTSIDE pointers. I do not know yet whether it is possible to get to it. The to-do test in Deparse.t used to croak.
Diffstat (limited to 'lib/B/Deparse.t')
-rw-r--r--lib/B/Deparse.t23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/B/Deparse.t b/lib/B/Deparse.t
index d1c9f6c30e..01954759e8 100644
--- a/lib/B/Deparse.t
+++ b/lib/B/Deparse.t
@@ -13,7 +13,7 @@ BEGIN {
use warnings;
use strict;
-my $tests = 45; # not counting those in the __DATA__ section
+my $tests = 46; # not counting those in the __DATA__ section
use B::Deparse;
my $deparse = B::Deparse->new();
@@ -501,6 +501,12 @@ like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
qr/^sub foo \{\s+foo\(\)/m,
'recursive sub';
+like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
+ prog => 'use feature lexical_subs=>state=>;
+ state sub sb5; sub { sub sb5 { } }'),
+ qr/sub \{\s*\(\);\s*sub sb5 {/m,
+ 'state sub in anon sub but declared outside';
+
is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
prog => 'BEGIN { $::{f}=\!0 }'),
"sub BEGIN {\n \$main::{'f'} = \\1;\n}\n",
@@ -1925,6 +1931,21 @@ my sub g {
sub f { }
}
####
+# TODO only partially fixed
+# lexical state subroutine with outer declaration and inner definition
+# CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
+();
+state sub sb4;
+state sub a {
+ ();
+ sub sb4 { }
+}
+state sub sb5;
+sub {
+ ();
+ sub sb5 { }
+} ;
+####
# Elements of %# should not be confused with $#{ array }
() = ${#}{'foo'};
####