6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
16 my $tests = 36; # not counting those in the __DATA__ section
19 my $deparse = B::Deparse->new();
20 isa_ok($deparse, 'B::Deparse', 'instantiate a B::Deparse object');
27 # This code is pinched from the t/lib/common.pl for TODO.
28 # It's not clear how to avoid duplication
29 my %meta = (context => '');
30 foreach my $what (qw(skip todo context options)) {
31 s/^#\s*\U$what\E\s*(.*)\n//m and $meta{$what} = $1;
32 # If the SKIP reason starts ? then it's taken as a code snippet to
33 # evaluate. This provides the flexibility to have conditional SKIPs
34 if ($meta{$what} && $meta{$what} =~ s/^\?//) {
35 my $temp = eval $meta{$what};
37 die "# In \U$what\E code reason:\n# $meta{$what}\n$@";
45 die "Missing name in test $_" unless defined $desc;
48 SKIP: { skip($meta{skip}) };
52 my ($input, $expected);
53 if (/(.*)\n>>>>\n(.*)/s) {
54 ($input, $expected) = ($1, $2);
57 ($input, $expected) = ($_, $_);
60 # parse options if necessary
61 my $deparse = $meta{options}
62 ? $deparse{$meta{options}} ||=
63 new B::Deparse split /,/, $meta{options}
66 my $coderef = eval "$meta{context};\n" . <<'EOC' . "sub {$input\n}";
67 # Tell B::Deparse about our ambient pragmas
68 my ($hint_bits, $warning_bits, $hinthash);
70 ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H);
72 $deparse->ambient_pragmas (
73 hint_bits => $hint_bits,
74 warning_bits => $warning_bits,
79 local $::TODO = $meta{todo};
81 is($@, "", "compilation of $desc");
84 my $deparsed = $deparse->coderef2text( $coderef );
85 my $regex = $expected;
86 $regex =~ s/(\S+)/\Q$1/g;
87 $regex =~ s/\s+/\\s+/g;
88 $regex = '^\{\s*' . $regex . '\s*\}$';
90 like($deparsed, qr/$regex/, $desc);
94 # Reset the ambient pragmas
98 ($b, $w, $h) = ($^H, ${^WARNING_BITS}, \%^H);
100 $deparse->ambient_pragmas (
107 use constant 'c', 'stuff';
108 is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
109 'the subroutine generated by use constant deparses');
112 is($deparse->coderef2text(sub{(-1) ** $a }), "{\n (-1) ** \$a;\n}",
113 'anon sub capturing an external lexical');
115 use constant cr => ['hello'];
116 my $string = "sub " . $deparse->coderef2text(\&cr);
117 my $val = (eval $string)->() or diag $string;
118 is(ref($val), 'ARRAY', 'constant array references deparse');
119 is($val->[0], 'hello', 'and return the correct value');
121 my $path = join " ", map { qq["-I$_"] } @INC;
123 $a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
124 $a =~ s/-e syntax OK\n//g;
125 $a =~ s/.*possible typo.*\n//; # Remove warning line
126 $a =~ s/.*-i used with no filenames.*\n//; # Remove warning line
127 $b = quotemeta <<'EOF';
128 BEGIN { $^I = ".bak"; }
130 BEGIN { $/ = "\n"; $\ = "\n"; }
131 LINE: while (defined($_ = <ARGV>)) {
133 our(@F) = split(' ', $_, 0);
137 $b =~ s/our\\\(\\\@F\\\)/our[( ]\@F\\)?/; # accept both our @F and our(@F)
139 'command line flags deparse as BEGIN blocks setting control variables');
141 $a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`;
142 $a =~ s/-e syntax OK\n//g;
143 is($a, "use constant ('PI', 4);\n",
144 "Proxy Constant Subroutines must not show up as (incorrect) prototypes");
146 #Re: perlbug #35857, patch #24505
147 #handle warnings::register-ed packages properly.
148 package B::Deparse::Wrapper;
151 use warnings::register;
153 my $deparser = B::Deparse->new();
154 return $deparser->coderef2text(shift);
158 use overload '0+' => sub { 42 };
163 use constant GLIPP => 'glipp';
164 use constant PI => 4;
165 use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
166 use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
167 BEGIN { delete $::Fcntl::{O_APPEND}; }
168 use POSIX qw/O_CREAT/;
171 my $res = B::Deparse::Wrapper::getcode($val);
172 like($res, qr/use warnings/,
173 '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
176 my $x=sub { ++$q,++$p };
178 eval <<EOFCODE and test($x);
182 use warnings::register;
187 # Exotic sub declarations
188 $a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
189 $a =~ s/-e syntax OK\n//g;
190 is($a, <<'EOCODG', "sub :::: and sub ::::::");
200 $a = `$^X $path "-MO=Deparse,-l" -e "map{ eval(0) }()" 2>&1`;
201 $a =~ s/-e syntax OK\n//g;
202 is($a, <<'EOCODH', "[perl #117311] [PATCH] -l option ('#line ...') does not emit ^Ls in the output");
211 my $code = <<"EOCODE";
213 our \$\x{1e1f}\x{14d}\x{14d};
217 = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
218 s/$ \n//x for $deparsed, $code;
219 is $deparsed, $code, 'our $funny_Unicode_chars';
224 `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
225 $a =~ s/-e syntax OK\n//g;
226 is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
228 *CORE::GLOBAL::require = sub {
237 `$^X $path "-MO=Deparse" -e "BEGIN{*Acme::Acme:: = *Acme::}" 2>&1`;
238 like($a, qr/-e syntax OK/,
239 "Deparse does not hang when traversing stash circularities");
243 is($deparse->coderef2text(sub{ print "foo@{]}" }),
246 }>, 'curly around to interpolate "@{]}"');
247 is($deparse->coderef2text(sub{ print "foo@{-}" }),
250 }>, 'no need to curly around to interpolate "@-"');
252 # Strict hints in %^H are mercilessly suppressed
254 `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
255 unlike($a, qr/BEGIN/,
256 "Deparse does not emit strict hh hints");
258 # ambient_pragmas should not mess with strict settings.
260 skip "requires 5.11", 1 unless $] >= 5.011;
263 # Clear out all hints
266 new B::Deparse -> ambient_pragmas(strict => 'all');
268 use 5.011; # should enable strict
269 ok !eval '$do_noT_create_a_variable_with_this_name = 1',
270 'ambient_pragmas do not mess with compiling scope';
274 # multiple statements on format lines
275 $a = `$^X $path "-MO=Deparse" -e "format =" -e "\@" -e "x();z()" -e. 2>&1`;
276 $a =~ s/-e syntax OK\n//g;
277 is($a, <<'EOCODH', 'multiple statements on format lines');
284 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
285 prog => "format =\n\@\n\$;\n.\n"),
286 <<'EOCODM', '$; on format line';
293 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse,-l', $path ],
294 prog => "format =\n\@\n\$foo\n.\n"),
295 <<'EOCODM', 'formats with -l';
302 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
303 prog => "{ my \$x; format =\n\@\n\$x\n.\n}"),
304 <<'EOCODN', 'formats nested inside blocks';
315 $a = readpipe qq`$^X $path "-MO=Deparse" -e "use feature q|:all|;`
316 .qq` my sub format; CORE::format =" -e. 2>&1`;
317 like($a, qr/CORE::format/, 'CORE::format when lex format sub is in scope');
319 # literal big chars under 'use utf8'
320 is($deparse->coderef2text(sub{ use utf8; /€/; }),
326 # STDERR when deparsing sub calls
327 # For a short while the output included 'While deparsing'
328 $a = `$^X $path "-MO=Deparse" -e "foo()" 2>&1`;
329 $a =~ s/-e syntax OK\n//g;
330 is($a, <<'EOCODI', 'no extra output when deparsing foo()');
335 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
336 .qq`"use feature q|:all|; my sub no; CORE::no less" 2>&1`;
337 like($a, qr/my sub no;\nCORE::no less;/,
338 'CORE::no after my sub no');
341 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
342 .qq`"use feature q|:all|; my sub use; CORE::use less" 2>&1`;
343 like($a, qr/my sub use;\nCORE::use less;/,
344 'CORE::use after my sub use');
347 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
348 .qq`"use feature q|:all|; my sub __DATA__; `
349 .qq`CORE::__DATA__" 2>&1`;
350 like($a, qr/my sub __DATA__;\n.*\nCORE::__DATA__/s,
351 'CORE::__DATA__ after my sub __DATA__');
354 $a = readpipe qq`$^X $path "-MO=Deparse" -e "sub foo{}" 2>&1`;
355 like($a, qr/sub foo\s*\{\s+\}/, 'sub declarations');
356 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
357 prog => 'sub f($); sub f($){}'),
358 qr/sub f\s*\(\$\)\s*\{\s*\}/,
359 'predeclared prototyped subs';
360 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
361 prog => 'use Scalar::Util q-weaken-;
363 BEGIN { weaken($_=\$::{f}) }'),
364 qr/sub f\s*\(\$\)\s*;/,
365 'prototyped stub with weak reference to the stash entry';
369 skip "BEGIN output is wrong on old perls", 1 if $] < 5.021006;
383 $a = readpipe qq`$^X $path "-MO=Deparse" -e "$prog" 2>&1`;
384 $a =~ s/-e syntax OK\n//g;
385 is($a, <<'EOCODJ', 'BEGIN blocks');
405 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ], prog => '
414 '), <<'EOCODL', 'BEGIN blocks at the end of their enclosing blocks';
432 my $prog = 'use constant FOO => do { 1 }; no overloading; die';
433 $a = readpipe qq`$^X $path "-MO=-qq,Deparse" -e "$prog" 2>&1`;
434 is($a, <<'EOCODK', '[perl #115066] use statements accidentally nested');
435 use constant ('FOO', do {
442 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
443 prog => 'use feature lexical_subs=>; my sub f;sub main::f{}'),
444 qr/^sub main::f \{/m,
445 'sub decl when lex sub is in scope';
447 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
448 prog => '$x =~ (1?/$a/:0)'),
449 '$x =~ ($_ =~ /$a/);'."\n",
450 '$foo =~ <branch-folded match> under taint mode';
452 done_testing($tests);
455 # TODO [perl #120950] This succeeds when run a 2nd time
459 # y/uni/code/ [perl #120950] This 2nd instance succeeds
465 # Constants in a block
466 # CONTEXT no warnings;
472 # Lexical and simple arithmetic
474 ++$test and $test /= 2;
477 $test /= 2 if ++$test;
482 # Assignment to list x
483 ((undef) x 3) = undef;
487 my $test = sub : lvalue {
495 my $test = sub : method {
501 # anonsub attrs at statement start
502 my $x = do { +sub : lvalue { my $y; } };
503 my $z = do { foo: +sub : method { my $a; } };
505 # block with continue
513 # lexical and package scalars
517 # lexical and package arrays
521 # lexical and package hashes
526 our($foo, $bar, $baz);
528 # CONTEXT { package Dog } use feature "state";
529 # variables with declared classes
539 my Dog ($foo, @bar, %baz);
540 our Dog ($phoo, @barr, %bazz);
541 state Dog ($fough, @barre, %bazze);
545 local our($rhu, $barb);
549 $_ .= <ARGV> . <$foo>;
552 my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
558 s/x/complex_expression();/e;
573 # 2 arguments in a 3 argument for
574 for (my $i = 0; $i < 2;) {
579 for (my $i = 0; $i < 2; ++$i) {
583 # 3 argument for again
584 for (my $i = 0; $i < 2; ++$i) {
588 # 3-argument for with inverted condition
589 for (my $i; not $i;) {
592 for (my $i; not $i; ++$i) {
595 for (my $a; not +($1 || 2) ** 2;) {
598 Something_to_put_the_loop_in_void_context();
602 while ($i) { my $z = 1; } continue { $i = 99; }
605 foreach my $i (1, 2) {
610 # foreach with my under -p
623 foreach my $i (1, 2) {
628 foreach our $i (1, 2) {
632 # foreach with my and our
634 foreach our $i (1, 2) {
639 # CONTEXT use feature "state";
640 foreach state $i (1, 2) {
644 # foreach with sub call
645 foreach $_ (hcaerof()) {
651 print reverse sort(@x);
655 print((sort {$b cmp $a} @x));
657 # reverse sort with block
659 print((reverse sort {$b <=> $a} @x));
663 print $_ foreach (reverse @a);
665 # foreach reverse (not inplace)
667 print $_ foreach (reverse 1, 2..5);
671 @ary = split(' ', 'foo', 0);
674 our @array = split(//, 'foo', 0);
677 my @array = split(//, 'foo', 0);
683 do { my $x = 1; $x };
685 # <20061012113037.GJ25805@c4.convolution.nl>
704 sub foo {} foo & & & foo;
709 # variables as method names
712 'Foo'->$bar('orz') = 'a stranger stranger than before';
714 # constants as method names
717 # constants as method names without ()
720 # [perl #47359] "indirect" method call notation
724 foo{@bar}1 xor foo();
727 (foo { @bar } 1)->foo;
728 (foo { @bar } 1), foo();
729 foo { @bar } 1 xor foo();
731 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
732 # CONTEXT use feature ':5.10';
736 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
737 # CONTEXT use 5.10.0;
738 # say in the context of use 5.10.0
741 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
742 # say with use 5.10.0
750 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
751 # say with use feature ':5.10';
755 use feature 'say', 'state', 'switch';
758 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
759 # CONTEXT use feature ':5.10';
760 # say with use 5.10.0 in the context of use feature
768 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
769 # CONTEXT use 5.10.0;
770 # say with use feature ':5.10' in the context of use 5.10.0
776 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
777 # CONTEXT use feature ':5.15';
781 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
782 # CONTEXT use 5.15.0;
783 # __SUB__ in the context of use 5.15.0
786 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
787 # __SUB__ with use 5.15.0
795 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
796 # __SUB__ with use feature ':5.15';
800 use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
803 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
804 # CONTEXT use feature ':5.15';
805 # __SUB__ with use 5.15.0 in the context of use feature
813 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
814 # CONTEXT use 5.15.0;
815 # __SUB__ with use feature ':5.15' in the context of use 5.15.0
821 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
822 # CONTEXT use feature ':5.10';
826 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
827 # CONTEXT use feature ':5.10';
828 # state var assignment
830 my $y = (state $x = 42);
833 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
834 # CONTEXT use feature ':5.10';
835 # state vars in anonymous subroutines
842 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
847 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
848 # keys @array; values @array
849 keys @$a if keys @ARGV;
850 values @ARGV if values @$a;
852 # Anonymous arrays and hashes, and references to them
858 # SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
859 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
860 # implicit smartmatch in given/when
862 when ('bar') { continue; }
863 when ($_ ~~ 'quux') { continue; }
867 # conditions in elsifs (regression in change #33710 which fixed bug #37302)
870 elsif ($a and $b) { x(); }
871 elsif ($a or $b) { x(); }
874 # interpolation in regexps
878 # TODO new undocumented cpan-bug #33708
882 # TODO hash constants not yet fixed
884 use constant H => { "#" => 1 }; H->{"#"}
886 # TODO optimized away 0 not yet fixed
888 foreach my $i (@_) { 0 }
890 # tests with not, not optimized
893 x() if not $a and $b;
894 x() if $a and not $b;
895 x() unless not $a and $b;
896 x() unless $a and not $b;
899 x() unless not $a or $b;
900 x() unless $a or not $b;
901 x() if $a and not $b and $c;
902 x() if not $a and $b and not $c;
903 x() unless $a and not $b and $c;
904 x() unless not $a and $b and not $c;
905 x() if $a or not $b or $c;
906 x() if not $a or $b or not $c;
907 x() unless $a or not $b or $c;
908 x() unless not $a or $b or not $c;
910 # tests with not, optimized
914 x() if not $a and not $b;
915 x() unless not $a and not $b;
916 x() if not $a or not $b;
917 x() unless not $a or not $b;
918 x() if not $a and not $b and $c;
919 x() unless not $a and not $b and $c;
920 x() if not $a or not $b or $c;
921 x() unless not $a or not $b or $c;
922 x() if not $a and not $b and not $c;
923 x() unless not $a and not $b and not $c;
924 x() if not $a or not $b or not $c;
925 x() unless not $a or not $b or not $c;
926 x() unless not $a or not $b or not $c;
933 x() unless $a and $b;
935 x() if not $a || $b and $c;
936 x() unless not $a || $b and $c;
937 x() if not $a && $b or $c;
938 x() unless not $a && $b or $c;
939 x() unless $a or $b or $c;
940 x() if $a or $b or $c;
941 x() unless $a and $b and $c;
942 x() if $a and $b and $c;
943 x() unless not $a && $b && $c;
945 # tests that should be constant folded
949 x() if GLIPP && GLIPP;
950 x() if !GLIPP || GLIPP;
952 x() if do { no warnings 'void'; 5; GLIPP };
953 x() if do { !GLIPP };
954 if (GLIPP) { x() } else { z() }
955 if (!GLIPP) { x() } else { z() }
956 if (GLIPP) { x() } elsif (GLIPP) { z() }
957 if (!GLIPP) { x() } elsif (GLIPP) { z() }
958 if (GLIPP) { x() } elsif (!GLIPP) { z() }
959 if (!GLIPP) { x() } elsif (!GLIPP) { z() }
960 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
961 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
962 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
996 # TODO constant deparsing has been backed out for 5.12
997 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
998 # tests that shouldn't be constant folded
999 # It might be fundamentally impossible to make this work on ithreads, in which
1000 # case the TODO should become a SKIP
1002 if ($a == 1) { x() } elsif ($b == 2) { z() }
1003 if (do { foo(); GLIPP }) { x() }
1004 if (do { $a++; GLIPP }) { x() }
1007 if ($a == 1) { x(); } elsif ($b == 2) { z(); }
1008 if (do { foo(); GLIPP }) { x(); }
1009 if (do { ++$a; GLIPP }) { x(); }
1011 # TODO constant deparsing has been backed out for 5.12
1012 # tests for deparsing constants
1015 # TODO constant deparsing has been backed out for 5.12
1016 # tests for deparsing imported constants
1019 # TODO constant deparsing has been backed out for 5.12
1020 # tests for deparsing re-exported constants
1023 # TODO constant deparsing has been backed out for 5.12
1024 # tests for deparsing imported constants that got deleted from the original namespace
1027 # TODO constant deparsing has been backed out for 5.12
1028 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
1029 # tests for deparsing constants which got turned into full typeglobs
1030 # It might be fundamentally impossible to make this work on ithreads, in which
1031 # case the TODO should become a SKIP
1033 eval '@Fcntl::O_EXCL = qw/affe tiger/;';
1036 # TODO constant deparsing has been backed out for 5.12
1037 # tests for deparsing of blessed constant with overloaded numification
1038 warn OVERLOADED_NUMIFICATION;
1052 # TODO Subsets of warnings could be encoded textually, rather than as bitflips.
1053 # subsets of warnings
1054 no warnings 'deprecated';
1057 # TODO Better test for CPAN #33708 - the deparsed code has different behaviour
1073 # SKIP ?$] > 5.013006 && ":= is now a syntax error"
1074 # := treated as an empty attribute list
1081 # : = empty attribute list
1100 # #71870 Use of uninitialized value in bitwise and B::Deparse
1102 @a = split(/foo/, $s, 0);
1104 @a = split(/$r/, $s, 0);
1107 # package declaration before label
1113 # shift optimisation
1118 # shift optimisation
1121 # shift optimisation
1126 # shift optimisation
1130 "foo" =~ (1 ? /foo/ : /bar/);
1131 "foo" =~ (1 ? y/foo// : /bar/);
1132 "foo" =~ (1 ? y/foo//r : /bar/);
1133 "foo" =~ (1 ? s/foo// : /bar/);
1135 'foo' =~ ($_ =~ /foo/);
1136 'foo' =~ ($_ =~ tr/fo//);
1137 'foo' =~ ($_ =~ tr/fo//r);
1138 'foo' =~ ($_ =~ s/foo//);
1140 # The fix for [perl #20444] broke this.
1143 # [perl #81424] match against aelemfast_lex
1154 # [perl #91318] /regexp/applaud
1155 print /a/a, s/b/c/a;
1156 print /a/aa, s/b/c/aa;
1157 print /a/p, s/b/c/p;
1158 print /a/l, s/b/c/l;
1159 print /a/u, s/b/c/u;
1161 use feature "unicode_strings";
1162 print /a/d, s/b/c/d;
1166 print /a/d, s/b/c/d;
1170 print /a/d, s/b/c/d;
1173 print /a/a, s/b/c/a;
1174 print /a/aa, s/b/c/aa;
1175 print /a/p, s/b/c/p;
1176 print /a/l, s/b/c/l;
1177 print /a/u, s/b/c/u;
1179 use feature 'unicode_strings';
1180 print /a/d, s/b/c/d;
1183 BEGIN { $^H{'reflags'} = '0';
1184 $^H{'reflags_charset'} = '2'; }
1185 print /a/d, s/b/c/d;
1189 use feature ':5.12';
1190 print /a/d, s/b/c/d;
1193 # [perl #119807] s//\(3)/ge should not warn when deparsed (\3 warns)
1197 "" =~ /a(?{ print q|
1200 '' =~ /a(?{ print "\n"; })/;
1203 $_ = qr/(??{<<END})/
1208 $_ = qr/(??{ "f.o\nb.r\n"; })/;
1210 # More regexp code block madness
1217 /a(??{ die $b; })a/;
1218 /$a(??{ die $b; })/;
1219 /@a(??{ die $b; })/;
1221 qr/a(?{ die $b; })a/;
1222 qr/$a(?{ die $b; })/;
1223 qr/@a(?{ die $b; })/;
1224 qr/(??{ die $b; })/;
1225 qr/a(??{ die $b; })a/;
1226 qr/$a(??{ die $b; })/;
1227 qr/@a(??{ die $b; })/;
1229 s/a(?{ die $b; })a//;
1230 s/$a(?{ die $b; })//;
1231 s/@a(?{ die $b; })//;
1232 s/(??{ die $b; })//;
1233 s/a(??{ die $b; })a//;
1234 s/$a(??{ die $b; })//;
1235 s/@a(??{ die $b; })//;
1237 # /(?x)<newline><tab>/
1242 tr/a/b/r + $a =~ tr/p/q/r;
1244 # y///d in list [perl #119815]
1251 # CONTEXT no warnings 'experimental::autoderef';
1256 # readpipe with complex expression
1262 # aelemfast for a lexical
1266 # feature features without feature
1267 # CONTEXT no warnings 'experimental::smartmatch';
1282 # feature features when feature has been disabled by use VERSION
1283 # CONTEXT no warnings 'experimental::smartmatch';
1284 use feature (sprintf(":%vd", $^V));
1312 # (the above test with CONTEXT, and the output is equivalent but different)
1313 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
1314 # feature features when feature has been disabled by use VERSION
1315 use feature (sprintf(":%vd", $^V));
1331 use feature ':default';
1345 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1346 # lexical subroutines and keywords of the same name
1347 # CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental';
1371 CORE::default { die; }
1372 CORE::if ($1) { die; }
1373 CORE::if ($1) { die; }
1374 CORE::elsif ($1) { die; }
1376 CORE::for (die; $1; die) { die; }
1377 CORE::foreach $_ (1 .. 10) { die; }
1378 die CORE::foreach (1);
1379 CORE::given ($1) { die; }
1384 () = (CORE::q['], CORE::qq["$_], CORE::qr//, CORE::qx[`]);
1387 () = CORE::sub { die; } ;
1389 CORE::unless ($1) { die; }
1390 CORE::until ($1) { die; }
1393 CORE::when ($1 ~~ $2) { die; }
1394 CORE::while ($1) { die; }
1398 use feature 'current_sub', 'evalbytes';
1404 no feature 'unicode_strings';
1407 use feature 'current_sub', 'evalbytes';
1410 use feature ':default';
1413 use feature ':5.12';
1415 no feature 'unicode_strings';
1418 # $#- $#+ $#{%} etc.
1420 @x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
1421 @x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
1422 @x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
1423 @x = ($#{;}, $#{:});
1426 # It's a known TODO that warnings are deparsed as bits, not textually.
1430 # [perl #86060] $( $| $) in regexps need braces
1440 # sort(foo(bar)) is interpreted as sort &foo(bar)
1441 # sort foo(bar) is interpreted as sort foo bar
1442 # parentheses are not optional in this case
1443 print sort(foo('bar'));
1445 print sort(foo('bar'));
1448 substr(my $a, 0, 0) = (foo(), bar());
1451 # This following line works around an unfixed bug that we are not trying to
1453 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1455 BEGIN { $^H{'foo'} = undef; }
1457 BEGIN { $^H{'bar'} = undef; }
1459 BEGIN { $^H{'baz'} = undef; }
1467 BEGIN { $^H{q[']} = '('; }
1470 # This following line works around an unfixed bug that we are not trying to
1472 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1473 # hint hash changes that serialise the same way with sort %hh
1474 BEGIN { $^H{'a'} = 'b'; }
1476 BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
1481 # [perl #47361] do({}) and do +{} (variants of do-file)
1495 # [perl #77096] functions that do not follow the llafr
1496 () = (return 1) + time;
1497 () = (return ($1 + $2) * $3) + time;
1498 () = (return ($a xor $b)) + time;
1499 () = (do 'file') + time;
1500 () = (do ($1 + $2) * $3) + time;
1501 () = (do ($1 xor $2)) + time;
1503 () = (require 'foo') + 3;
1504 () = (require foo) + 3;
1505 () = (CORE::dump 1) + 3;
1516 # require(foo()) and do(foo())
1525 # [perl #97476] not() *does* follow the llafr
1526 $_ = ($a xor not +($1 || 2) ** 2);
1528 # Precedence conundrums with argument-less function calls
1536 # loopexes have assignment prec
1537 () = (CORE::dump a) | 'b';
1538 () = (goto a) | 'b';
1539 () = (last a) | 'b';
1540 () = (next a) | 'b';
1541 () = (redo a) | 'b';
1543 # [perl #63558] open local(*FH)
1545 pipe local *FH, local *FH;
1547 # [perl #91416] open "string"
1560 () = 'open'->[0]; #aelemfast
1565 () = 'open'->[$_]; #aelem
1570 () = 'open'->{0}; #helem
1591 () = 'a::]b'->{'0'};
1593 # [perl #74740] -(f()) vs -f()
1599 #[perl #30504] foreach-my postfix/prefix difference
1600 $_ = 'foo' foreach my ($foo1, $bar1, $baz1);
1601 foreach (my ($foo2, $bar2, $baz2)) { $_ = 'foo' }
1602 foreach my $i (my ($foo3, $bar3, $baz3)) { $i = 'foo' }
1604 $_ = 'foo' foreach (my($foo1, $bar1, $baz1));
1605 foreach $_ (my($foo2, $bar2, $baz2)) {
1608 foreach my $i (my($foo3, $bar3, $baz3)) {
1612 #[perl #108224] foreach with continue block
1613 foreach (1 .. 3) { print } continue { print "\n" }
1614 foreach (1 .. 3) { } continue { }
1615 foreach my $i (1 .. 3) { print $i } continue { print "\n" }
1616 foreach my $i (1 .. 3) { } continue { }
1618 foreach $_ (1 .. 3) {
1624 foreach $_ (1 .. 3) {
1630 foreach my $i (1 .. 3) {
1636 foreach my $i (1 .. 3) {
1657 # 'my' works with padrange op
1664 ($m3, $m4) = (1, 2);
1666 my($m5, $m6) = (1, 2);
1667 my($m7, undef, $m8) = (1, 2, 3);
1668 @z = ($m7, undef, $m8);
1669 ($m7, undef, $m8) = (1, 2, 3);
1671 # 'our/local' works with padrange op
1682 ($o3, $o4) = (1, 2);
1683 local($o3, $o4) = (1, 2);
1685 @z = local($o3, $o4);
1686 our($o5, $o6) = (1, 2);
1687 our($o7, undef, $o8) = (1, 2, 3);
1688 @z = ($o7, undef, $o8);
1689 @z = local($o7, undef, $o8);
1690 ($o7, undef, $o8) = (1, 2, 3);
1691 local($o7, undef, $o8) = (1, 2, 3);
1693 # 'state' works with padrange op
1694 # CONTEXT no strict; use feature 'state';
1701 ($s3, $s4) = (1, 2);
1703 # assignment of state lists isn't implemented yet
1704 #state($s5, $s6) = (1, 2);
1705 #state($s7, undef, $s8) = (1, 2, 3);
1706 #@z = ($s7, undef, $s8);
1707 ($s7, undef, $s8) = (1, 2, 3);
1709 # anon arrays with padrange
1714 # slices with padrange
1720 # binops with padrange
1734 my($a, $b, $c, $d, @e);
1739 @e = ($a, $b, $c) x $d;
1743 my($a, $b, $c) = @_;
1745 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1746 # lexical subroutine
1747 use feature 'lexical_subs';
1748 no warnings "experimental::lexical_subs";
1752 use feature 'lexical_subs';
1753 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUUU\005"}
1755 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUU\005"}
1758 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUU\005"}
1761 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1762 # lexical "state" subroutine
1763 use feature 'state', 'lexical_subs';
1764 no warnings 'experimental::lexical_subs';
1768 use feature 'lexical_subs';
1769 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUUU\005"}
1771 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUU\005"}
1772 use feature 'state';
1775 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUU\005"}
1776 use feature 'state';
1779 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1780 # lexical subroutine scoping
1781 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
1799 # Elements of %# should not be confused with $#{ array }
1808 # [perl #121050] Prototypes with whitespace
1809 sub _121050(\$ \$) { }
1811 sub _121050empty( ) {}
1812 () = _121050empty() + 1;
1815 () = _121050empty + 1;
1817 # Ampersand calls and scalar context
1824 &foo(scalar bar(), scalar baz());
1826 # ensure aelemfast works in the range -128..127 and that there's no
1830 $x = $a[-256] + $a[-255] + $a[-129] + $a[-128] + $a[-127] + $a[-1] + $a[0];
1831 $x = $a[1] + $a[126] + $a[127] + $a[128] + $a[255] + $a[256];
1833 $x = $b[-256] + $b[-255] + $b[-129] + $b[-128] + $b[-127] + $b[-1] + $b[0];
1834 $x = $b[1] + $b[126] + $b[127] + $b[128] + $b[255] + $b[256];
1836 # 'm' must be preserved in m??
1839 # \(@array) and \(..., (@array), ...)
1840 my(@array, %hash, @a, @b, %c, %d);
1843 () = \(@a, (@b), (%c), %d);
1844 () = \(@Foo::array);
1846 () = \(@Foo::a, (@Foo::b), (%Foo::c), %Foo::d);
1848 # subs synonymous with keywords
1852 use feature 'state';
1856 # CONTEXT use feature "state", 'refaliasing', 'lexical_subs'; no warnings 'experimental';
1868 \($x, my $a) = @{[\$x, \$x]};
1869 (\$x, \my $b) = @{[\$x, \$x]};
1881 \local($a[1]) = foo();
1884 \local @a[0,1] = (\$a)x2;
1891 \local($h{b}) = \$x;
1892 \@h{'a','b'} = foo();
1894 \local @h{'a','b'} = (\$x)x2;
1930 (\$_, $_) = \(1, 2);
1931 $_ == 3 ? \$_ : $_ = \3;
1932 $_ == 3 ? \$_ : \$x = \3;
1933 \($_ == 3 ? $_ : $x) = \3;
1934 for \my $topic (\$1, \$2) {
1937 for \state $topic (\$1, \$2) {
1940 for \our $topic (\$1, \$2) {
1943 for \$_ (\$1, \$2) {
1946 for \my @a ([1,2], [3,4]) {
1949 for \state @a ([1,2], [3,4]) {
1952 for \our @a ([1,2], [3,4]) {
1955 for \@_ ([1,2], [3,4]) {
1958 for \my %a ({5,6}, {7,8}) {
1961 for \our %a ({5,6}, {7,8}) {
1964 for \state %a ({5,6}, {7,8}) {
1967 for \%_ ({5,6}, {7,8}) {
1972 for \&a (sub { 9; }, sub { 10; }) {
1976 for \&a (sub { 9; }, sub { 10; }) {
1991 (\$x, \my $a) = @{[\$x, \$x];};
1992 (\$x, \my $b) = @{[\$x, \$x];};
2004 (\local $a[1]) = foo();
2005 (\@a[0, 1]) = foo();
2006 (\@a[2, 3]) = foo();
2007 (\local @a[0, 1]) = (\$a) x 2;
2013 \local $h{'a'} = \$x;
2014 (\local $h{'b'}) = \$x;
2015 (\@h{'a', 'b'}) = foo();
2016 (\@h{2, 3}) = foo();
2017 (\local @h{'a', 'b'}) = (\$x) x 2;
2043 (\our %zz) = {1, 2};
2053 (\$_, $_) = \(1, 2);
2054 $_ == 3 ? \$_ : $_ = \3;
2055 $_ == 3 ? \$_ : \$x = \3;
2056 ($_ == 3 ? \$_ : \$x) = \3;
2057 foreach \my $topic (\$1, \$2) {
2060 foreach \state $topic (\$1, \$2) {
2063 foreach \our $topic (\$1, \$2) {
2066 foreach \$_ (\$1, \$2) {
2069 foreach \my @a ([1, 2], [3, 4]) {
2072 foreach \state @a ([1, 2], [3, 4]) {
2075 foreach \our @a ([1, 2], [3, 4]) {
2078 foreach \@_ ([1, 2], [3, 4]) {
2081 foreach \my %a ({5, 6}, {7, 8}) {
2084 foreach \our %a ({5, 6}, {7, 8}) {
2087 foreach \state %a ({5, 6}, {7, 8}) {
2090 foreach \%_ ({5, 6}, {7, 8}) {
2095 foreach \&a (sub { 9; } , sub { 10; } ) {
2099 foreach \&a (sub { 9; } , sub { 10; } ) {
2108 $_ = join('???', pos $_);
2114 # my @a; exists $a[0]
2122 # my @a; delete $a[0]
2137 # my $x = "$h{foo}";
2139 my $x = "$h{'foo'}";
2141 # weird constant hash key
2143 my $x = $h{"\000\t\x{100}"};
2145 # multideref and packages
2147 my(%bar) = ('a', 'b');
2149 $bar{'k'} = $bar[200];
2150 $main::bar{'k'} = $main::bar[200];
2151 $foo::bar{'k'} = $foo::bar[200];
2153 $bar{'k'} = $bar[200];
2154 $main::bar{'k'} = $main::bar[200];
2155 $foo::bar{'k'} = $foo::bar[200];
2158 my(%bar) = ('a', 'b');
2160 $bar{'k'} = $bar[200];
2161 $main::bar{'k'} = $main::bar[200];
2162 $foo::bar{'k'} = $bar[200];
2164 $bar{'k'} = $foo::bar[200];
2165 $main::bar{'k'} = $main::bar[200];
2166 $foo::bar{'k'} = $foo::bar[200];
2168 # multideref and local
2170 local $h{'foo'}[0] = 1;
2172 # multideref and exists
2174 my $e = exists $h{'foo'}[$i];
2176 # multideref and delete
2178 my $e = delete $h{'foo'}[$i];
2180 # multideref with leading expression
2182 my $x = ($r // [])->{'foo'}[0];
2184 # multideref with complex middle index
2186 my $x = $h{'foo'}[$i + $j]{$k};