4 splice @INC, 0, 0, 't', '.';
6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
16 my $tests = 52; # 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 $code = "$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,
78 my $coderef = eval $code;
80 local $::TODO = $meta{todo};
82 is($@, "", "compilation of $desc")
83 or diag "=============================================\n"
84 . "CODE:\n--------\n$code\n--------\n"
85 . "=============================================\n";
88 my $deparsed = $deparse->coderef2text( $coderef );
89 my $regex = $expected;
90 $regex =~ s/(\S+)/\Q$1/g;
91 $regex =~ s/\s+/\\s+/g;
92 $regex = '^\{\s*' . $regex . '\s*\}$';
94 like($deparsed, qr/$regex/, $desc)
95 or diag "=============================================\n"
96 . "CODE:\n--------\n$input\n--------\n"
97 . "EXPECTED:\n--------\n{\n$expected\n}\n--------\n"
98 . "GOT:\n--------\n$deparsed\n--------\n"
99 . "=============================================\n";
103 # Reset the ambient pragmas
107 ($b, $w, $h) = ($^H, ${^WARNING_BITS}, \%^H);
109 $deparse->ambient_pragmas (
116 use constant 'c', 'stuff';
117 is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
118 'the subroutine generated by use constant deparses');
121 is($deparse->coderef2text(sub{(-1) ** $a }), "{\n (-1) ** \$a;\n}",
122 'anon sub capturing an external lexical');
124 use constant cr => ['hello'];
125 my $string = "sub " . $deparse->coderef2text(\&cr);
126 my $val = (eval $string)->() or diag $string;
127 is(ref($val), 'ARRAY', 'constant array references deparse');
128 is($val->[0], 'hello', 'and return the correct value');
130 my $path = join " ", map { qq["-I$_"] } @INC;
132 $a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
133 $a =~ s/-e syntax OK\n//g;
134 $a =~ s/.*possible typo.*\n//; # Remove warning line
135 $a =~ s/.*-i used with no filenames.*\n//; # Remove warning line
136 $b = quotemeta <<'EOF';
137 BEGIN { $^I = ".bak"; }
139 BEGIN { $/ = "\n"; $\ = "\n"; }
140 LINE: while (defined($_ = readline ARGV)) {
142 our(@F) = split(' ', $_, 0);
146 $b =~ s/our\\\(\\\@F\\\)/our[( ]\@F\\)?/; # accept both our @F and our(@F)
148 'command line flags deparse as BEGIN blocks setting control variables');
150 $a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`;
151 $a =~ s/-e syntax OK\n//g;
152 is($a, "use constant ('PI', 4);\n",
153 "Proxy Constant Subroutines must not show up as (incorrect) prototypes");
155 $a = `$^X $path "-MO=Deparse" -e "sub foo(){1}" 2>&1`;
156 $a =~ s/-e syntax OK\n//g;
157 is($a, "sub foo () {\n 1;\n}\n",
158 "Main prog consisting of just a constant (via empty proto)");
160 $a = readpipe qq|$^X $path "-MO=Deparse"|
161 .qq| -e "package F; sub f(){0} sub s{}"|
162 .qq| -e "#line 123 four-five-six"|
163 .qq| -e "package G; sub g(){0} sub s{}" 2>&1|;
164 $a =~ s/-e syntax OK\n//g;
165 like($a, qr/sub F::f \(\) \{\s*0;?\s*}/,
166 "Constant is dumped in package in which other subs are dumped");
167 unlike($a, qr/sub g/,
168 "Constant is not dumped in package in which other subs are not dumped");
170 #Re: perlbug #35857, patch #24505
171 #handle warnings::register-ed packages properly.
172 package B::Deparse::Wrapper;
175 use warnings::register;
177 my $deparser = B::Deparse->new();
178 return $deparser->coderef2text(shift);
182 use overload '0+' => sub { 42 };
187 use constant GLIPP => 'glipp';
188 use constant PI => 4;
189 use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
190 use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
191 BEGIN { delete $::Fcntl::{O_APPEND}; }
192 use POSIX qw/O_CREAT/;
195 my $res = B::Deparse::Wrapper::getcode($val);
196 like($res, qr/use warnings/,
197 '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
200 my $x=sub { ++$q,++$p };
202 eval <<EOFCODE and test($x);
206 use warnings::register;
211 # Exotic sub declarations
212 $a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
213 $a =~ s/-e syntax OK\n//g;
214 is($a, <<'EOCODG', "sub :::: and sub ::::::");
224 $a = `$^X $path "-MO=Deparse,-l" -e "map{ eval(0) }()" 2>&1`;
225 $a =~ s/-e syntax OK\n//g;
226 is($a, <<'EOCODH', "[perl #117311] [PATCH] -l option ('#line ...') does not emit ^Ls in the output");
235 my $code = <<"EOCODE";
237 our \$\x{1e1f}\x{14d}\x{14d};
241 = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
242 s/$ \n//x for $deparsed, $code;
243 is $deparsed, $code, 'our $funny_Unicode_chars';
248 `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
249 $a =~ s/-e syntax OK\n//g;
250 is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
252 *CORE::GLOBAL::require = sub {
261 `$^X $path "-MO=Deparse" -e "BEGIN{*Acme::Acme:: = *Acme::}" 2>&1`;
262 like($a, qr/-e syntax OK/,
263 "Deparse does not hang when traversing stash circularities");
267 is($deparse->coderef2text(sub{ print "foo@{]}" }),
270 }>, 'curly around to interpolate "@{]}"');
271 is($deparse->coderef2text(sub{ print "foo@{-}" }),
274 }>, 'no need to curly around to interpolate "@-"');
276 # Strict hints in %^H are mercilessly suppressed
278 `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
279 unlike($a, qr/BEGIN/,
280 "Deparse does not emit strict hh hints");
282 # ambient_pragmas should not mess with strict settings.
284 skip "requires 5.11", 1 unless $] >= 5.011;
287 # Clear out all hints
290 new B::Deparse -> ambient_pragmas(strict => 'all');
292 use 5.011; # should enable strict
293 ok !eval '$do_noT_create_a_variable_with_this_name = 1',
294 'ambient_pragmas do not mess with compiling scope';
298 # multiple statements on format lines
299 $a = `$^X $path "-MO=Deparse" -e "format =" -e "\@" -e "x();z()" -e. 2>&1`;
300 $a =~ s/-e syntax OK\n//g;
301 is($a, <<'EOCODH', 'multiple statements on format lines');
308 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
309 prog => "format =\n\@\n\$;\n.\n"),
310 <<'EOCODM', '$; on format line';
317 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse,-l', $path ],
318 prog => "format =\n\@\n\$foo\n.\n"),
319 <<'EOCODM', 'formats with -l';
326 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
327 prog => "{ my \$x; format =\n\@\n\$x\n.\n}"),
328 <<'EOCODN', 'formats nested inside blocks';
339 $a = readpipe qq`$^X $path "-MO=Deparse" -e "use feature q|:all|;`
340 .qq` my sub format; CORE::format =" -e. 2>&1`;
341 like($a, qr/CORE::format/, 'CORE::format when lex format sub is in scope');
343 # literal big chars under 'use utf8'
344 is($deparse->coderef2text(sub{ use utf8; /€/; }),
350 # STDERR when deparsing sub calls
351 # For a short while the output included 'While deparsing'
352 $a = `$^X $path "-MO=Deparse" -e "foo()" 2>&1`;
353 $a =~ s/-e syntax OK\n//g;
354 is($a, <<'EOCODI', 'no extra output when deparsing foo()');
358 # Sub calls compiled before importation
359 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
362 Test::More::->import;
366 'sub calls compiled before importation of prototype subs';
368 # [perl #121050] Prototypes with whitespace
369 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
371 sub _121050(\$ \$) { }
373 sub _121050empty( ) {}
374 () = _121050empty() + 1;
376 <<'EOCODP', '[perl #121050] prototypes with whitespace';
377 sub _121050 (\$ \$) {
381 sub _121050empty ( ) {
384 () = _121050empty + 1;
388 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
389 .qq`"use feature q|:all|; my sub no; CORE::no less" 2>&1`;
390 like($a, qr/my sub no;\n.*CORE::no less;/s,
391 'CORE::no after my sub no');
394 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
395 .qq`"use feature q|:all|; my sub use; CORE::use less" 2>&1`;
396 like($a, qr/my sub use;\n.*CORE::use less;/s,
397 'CORE::use after my sub use');
400 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
401 .qq`"use feature q|:all|; my sub __DATA__; `
402 .qq`CORE::__DATA__" 2>&1`;
403 like($a, qr/my sub __DATA__;\n.*CORE::__DATA__/s,
404 'CORE::__DATA__ after my sub __DATA__');
407 $a = readpipe qq`$^X $path "-MO=Deparse" -e "sub foo{}" 2>&1`;
408 like($a, qr/sub foo\s*\{\s+\}/, 'sub declarations');
409 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
410 prog => 'sub f($); sub f($){}'),
411 qr/sub f\s*\(\$\)\s*\{\s*\}/,
412 'predeclared prototyped subs';
413 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
414 prog => 'use Scalar::Util q-weaken-;
416 BEGIN { weaken($_=\$::{f}) }'),
417 qr/sub f\s*\(\$\)\s*;/,
418 'prototyped stub with weak reference to the stash entry';
419 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
420 prog => 'sub f () { 42 }'),
421 qr/sub f\s*\(\)\s*\{\s*42;\s*\}/,
422 'constant perl sub declaration';
426 skip "BEGIN output is wrong on old perls", 1 if $] < 5.021006;
440 $a = readpipe qq`$^X $path "-MO=Deparse" -e "$prog" 2>&1`;
441 $a =~ s/-e syntax OK\n//g;
442 is($a, <<'EOCODJ', 'BEGIN blocks');
462 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ], prog => '
471 '), <<'EOCODL', 'BEGIN blocks at the end of their enclosing blocks';
488 # BEGIN blocks should not be called __ANON__
489 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
490 prog => 'sub BEGIN { } CHECK { delete $::{BEGIN} }'),
491 qr/sub BEGIN/, 'anonymised BEGIN';
494 my $prog = 'use constant FOO => do { 1 }; no overloading; die';
495 $a = readpipe qq`$^X $path "-MO=-qq,Deparse" -e "$prog" 2>&1`;
496 is($a, <<'EOCODK', '[perl #115066] use statements accidentally nested');
497 use constant ('FOO', do {
504 # BEGIN blocks inside predeclared subs
505 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
509 sub run_tests { BEGIN { } die }'),
510 qr/sub run_tests \{\s*sub BEGIN/,
511 'BEGIN block inside predeclared sub';
513 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
514 prog => 'package foo; use overload qr=>sub{}'),
515 qr/package foo;\s*use overload/,
518 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
519 prog => 'use feature lexical_subs=>; my sub f;sub main::f{}'),
520 qr/^sub main::f \{/m,
521 'sub decl when lex sub is in scope';
523 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
524 prog => 'sub foo{foo()}'),
525 qr/^sub foo \{\s+foo\(\)/m,
528 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
529 prog => 'use feature lexical_subs=>state=>;
530 state sub sb5; sub { sub sb5 { } }'),
531 qr/sub \{\s*\(\);\s*sub sb5 \{/m,
532 'state sub in anon sub but declared outside';
534 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
535 prog => 'BEGIN { $::{f}=\!0 }'),
536 "sub BEGIN {\n \$main::{'f'} = \\1;\n}\n",
537 '&PL_sv_yes constant (used to croak)';
539 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
540 prog => '$x =~ (1?/$a/:0)'),
541 '$x =~ ($_ =~ /$a/);'."\n",
542 '$foo =~ <branch-folded match> under taint mode';
544 unlike runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-w' ],
545 prog => 'BEGIN { undef &foo }'),
546 qr'Use of uninitialized value',
547 'no warnings for undefined sub';
549 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
550 prog => 'sub f { 1; } BEGIN { *g = \&f; }'),
551 "sub f {\n 1;\n}\nsub BEGIN {\n *g = \\&f;\n}\n",
552 "sub glob alias shouldn't impede emitting original sub";
554 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
555 prog => 'package Foo; sub f { 1; } BEGIN { *g = \&f; }'),
556 "package Foo;\nsub f {\n 1;\n}\nsub BEGIN {\n *g = \\&f;\n}\n",
557 "sub glob alias outside main shouldn't impede emitting original sub";
559 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
560 prog => 'package Foo; sub f { 1; } BEGIN { *Bar::f = \&f; }'),
561 "package Foo;\nsub f {\n 1;\n}\nsub BEGIN {\n *Bar::f = \\&f;\n}\n",
562 "sub glob alias in separate package shouldn't impede emitting original sub";
565 done_testing($tests);
568 # TODO [perl #120950] This succeeds when run a 2nd time
572 # y/uni/code/ [perl #120950] This 2nd instance succeeds
578 # Constants in a block
579 # CONTEXT no warnings;
585 # List of constants in void context
586 # CONTEXT no warnings;
593 # Lexical and simple arithmetic
595 ++$test and $test /= 2;
598 $test /= 2 if ++$test;
603 # Assignment to list x
604 ((undef) x 3) = undef;
608 my $test = sub : lvalue {
616 my $test = sub : method {
622 # anonsub attrs at statement start
623 my $x = do { +sub : lvalue { my $y; } };
624 my $z = do { foo: +sub : method { my $a; } };
626 # block with continue
634 # lexical and package scalars
638 # lexical and package arrays
643 # lexical and package hashes
648 our($foo, $bar, $baz);
650 # CONTEXT { package Dog } use feature "state";
651 # variables with declared classes
661 my Dog ($foo, @bar, %baz);
662 our Dog ($phoo, @barr, %bazz);
663 state Dog ($fough, @barre, %bazze);
667 local our($rhu, $barb);
671 $_ .= <> . <ARGV> . <$foo>;
677 $_ .= readline(ARGV) . readline(ARGV) . readline($foo);
697 my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
701 # TODO ? ord("A") != 65 && "EBCDIC"
702 my $baz = "B\366\x{100}";
703 my $bba = qr/B\366\x{100}/;
708 s/x/complex_expression();/e;
723 # 2 arguments in a 3 argument for
724 for (my $i = 0; $i < 2;) {
729 for (my $i = 0; $i < 2; ++$i) {
733 # 3 argument for again
734 for (my $i = 0; $i < 2; ++$i) {
738 # 3-argument for with inverted condition
739 for (my $i; not $i;) {
742 for (my $i; not $i; ++$i) {
745 for (my $a; not +($1 || 2) ** 2;) {
748 Something_to_put_the_loop_in_void_context();
752 while ($i) { my $z = 1; } continue { $i = 99; }
755 foreach my $i (1, 2) {
760 # foreach with my under -p
773 foreach my $i (1, 2) {
778 foreach our $i (1, 2) {
782 # foreach with my and our
784 foreach our $i (1, 2) {
789 # CONTEXT use feature "state";
790 foreach state $i (1, 2) {
794 # foreach with sub call
795 foreach $_ (hcaerof()) {
801 print reverse sort(@x);
805 print((sort {$b cmp $a} @x));
807 # reverse sort with block
809 print((reverse sort {$b <=> $a} @x));
813 print $_ foreach (reverse @a);
815 # foreach reverse (not inplace)
817 print $_ foreach (reverse 1, 2..5);
821 @ary = split(' ', 'foo', 0);
824 @ary = split(' ', 'foo', 0);
827 our @array = split(//, 'foo', 0);
830 my @array = split(//, 'foo', 0);
834 @array = split(/x(?{ $c++; })y/, 'foo', 0);
838 ($x, $y) = split(/$p(?{ $c++; })y/, 'foo', 2);
842 @ary = split(/$pat/, 'foo', 0);
846 @ary = split(/$pat/, 'foo', 0);
850 local @array = split(/$pat/, 'foo', 0);
853 my @array = split(/$pat/, 'foo', 0);
859 do { my $x = 1; $x };
861 # <20061012113037.GJ25805@c4.convolution.nl>
880 sub foo {} foo & & & foo;
885 # variables as method names
888 'Foo'->$bar('orz') = 'a stranger stranger than before';
890 # constants as method names
893 # constants as method names without ()
896 # [perl #47359] "indirect" method call notation
900 foo{@bar}1 xor foo();
903 (foo { @bar } 1)->foo;
904 (foo { @bar } 1), foo();
905 foo { @bar } 1 xor foo();
907 # indirops with blocks
909 print {*STDOUT;} 'foo';
910 printf {*STDOUT;} 'foo';
911 say {*STDOUT;} 'foo';
912 system {'foo';} '-foo';
913 exec {'foo';} '-foo';
915 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
916 # CONTEXT use feature ':5.10';
920 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
921 # CONTEXT use 5.10.0;
922 # say in the context of use 5.10.0
925 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
926 # say with use 5.10.0
934 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
935 # say with use feature ':5.10';
939 use feature 'say', 'state', 'switch';
942 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
943 # CONTEXT use feature ':5.10';
944 # say with use 5.10.0 in the context of use feature
952 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
953 # CONTEXT use 5.10.0;
954 # say with use feature ':5.10' in the context of use 5.10.0
960 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
961 # CONTEXT use feature ':5.15';
965 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
966 # CONTEXT use 5.15.0;
967 # __SUB__ in the context of use 5.15.0
970 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
971 # __SUB__ with use 5.15.0
979 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
980 # __SUB__ with use feature ':5.15';
984 use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
987 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
988 # CONTEXT use feature ':5.15';
989 # __SUB__ with use 5.15.0 in the context of use feature
997 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
998 # CONTEXT use 5.15.0;
999 # __SUB__ with use feature ':5.15' in the context of use 5.15.0
1000 use feature ':5.15';
1005 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
1006 # CONTEXT use feature ':5.10';
1010 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
1011 # CONTEXT use feature ':5.10';
1012 # state var assignment
1014 my $y = (state $x = 42);
1017 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
1018 # CONTEXT use feature ':5.10';
1019 # state vars in anonymous subroutines
1026 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
1031 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
1032 # keys @array; values @array
1033 keys @$a if keys @ARGV;
1034 values @ARGV if values @$a;
1036 # Anonymous arrays and hashes, and references to them
1042 # SKIP ?$] < 5.010 && "smartmatch and given/whereso not implemented on this Perl version"
1043 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
1044 # implicit smartmatch in given/whereso
1046 whereso ('bar') { continue; }
1047 whereso ($_ == 3) { continue; }
1048 whereis ('quux') { continue; }
1052 # conditions in elsifs (regression in change #33710 which fixed bug #37302)
1055 elsif ($a and $b) { x(); }
1056 elsif ($a or $b) { x(); }
1059 # interpolation in regexps
1063 # TODO new undocumented cpan-bug #33708
1067 # TODO hash constants not yet fixed
1069 use constant H => { "#" => 1 }; H->{"#"}
1071 # TODO optimized away 0 not yet fixed
1073 foreach my $i (@_) { 0 }
1075 # tests with not, not optimized
1078 x() if not $a and $b;
1079 x() if $a and not $b;
1080 x() unless not $a and $b;
1081 x() unless $a and not $b;
1082 x() if not $a or $b;
1083 x() if $a or not $b;
1084 x() unless not $a or $b;
1085 x() unless $a or not $b;
1086 x() if $a and not $b and $c;
1087 x() if not $a and $b and not $c;
1088 x() unless $a and not $b and $c;
1089 x() unless not $a and $b and not $c;
1090 x() if $a or not $b or $c;
1091 x() if not $a or $b or not $c;
1092 x() unless $a or not $b or $c;
1093 x() unless not $a or $b or not $c;
1095 # tests with not, optimized
1099 x() if not $a and not $b;
1100 x() unless not $a and not $b;
1101 x() if not $a or not $b;
1102 x() unless not $a or not $b;
1103 x() if not $a and not $b and $c;
1104 x() unless not $a and not $b and $c;
1105 x() if not $a or not $b or $c;
1106 x() unless not $a or not $b or $c;
1107 x() if not $a and not $b and not $c;
1108 x() unless not $a and not $b and not $c;
1109 x() if not $a or not $b or not $c;
1110 x() unless not $a or not $b or not $c;
1111 x() unless not $a or not $b or not $c;
1116 x() unless $a or $b;
1118 x() unless $a and $b;
1120 x() if not $a || $b and $c;
1121 x() unless not $a || $b and $c;
1122 x() if not $a && $b or $c;
1123 x() unless not $a && $b or $c;
1124 x() unless $a or $b or $c;
1125 x() if $a or $b or $c;
1126 x() unless $a and $b and $c;
1127 x() if $a and $b and $c;
1128 x() unless not $a && $b && $c;
1130 # tests that should be constant folded
1134 x() if GLIPP && GLIPP;
1135 x() if !GLIPP || GLIPP;
1136 x() if do { GLIPP };
1137 x() if do { no warnings 'void'; 5; GLIPP };
1138 x() if do { !GLIPP };
1139 if (GLIPP) { x() } else { z() }
1140 if (!GLIPP) { x() } else { z() }
1141 if (GLIPP) { x() } elsif (GLIPP) { z() }
1142 if (!GLIPP) { x() } elsif (GLIPP) { z() }
1143 if (GLIPP) { x() } elsif (!GLIPP) { z() }
1144 if (!GLIPP) { x() } elsif (!GLIPP) { z() }
1145 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
1146 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
1147 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
1181 # TODO constant deparsing has been backed out for 5.12
1182 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
1183 # tests that shouldn't be constant folded
1184 # It might be fundamentally impossible to make this work on ithreads, in which
1185 # case the TODO should become a SKIP
1187 if ($a == 1) { x() } elsif ($b == 2) { z() }
1188 if (do { foo(); GLIPP }) { x() }
1189 if (do { $a++; GLIPP }) { x() }
1192 if ($a == 1) { x(); } elsif ($b == 2) { z(); }
1193 if (do { foo(); GLIPP }) { x(); }
1194 if (do { ++$a; GLIPP }) { x(); }
1196 # TODO constant deparsing has been backed out for 5.12
1197 # tests for deparsing constants
1200 # TODO constant deparsing has been backed out for 5.12
1201 # tests for deparsing imported constants
1204 # TODO constant deparsing has been backed out for 5.12
1205 # tests for deparsing re-exported constants
1208 # TODO constant deparsing has been backed out for 5.12
1209 # tests for deparsing imported constants that got deleted from the original namespace
1212 # TODO constant deparsing has been backed out for 5.12
1213 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
1214 # tests for deparsing constants which got turned into full typeglobs
1215 # It might be fundamentally impossible to make this work on ithreads, in which
1216 # case the TODO should become a SKIP
1218 eval '@Fcntl::O_EXCL = qw/affe tiger/;';
1221 # TODO constant deparsing has been backed out for 5.12
1222 # tests for deparsing of blessed constant with overloaded numification
1223 warn OVERLOADED_NUMIFICATION;
1237 # TODO Subsets of warnings could be encoded textually, rather than as bitflips.
1238 # subsets of warnings
1239 no warnings 'deprecated';
1242 # TODO Better test for CPAN #33708 - the deparsed code has different behaviour
1258 # SKIP ?$] > 5.013006 && ":= is now a syntax error"
1259 # := treated as an empty attribute list
1266 # : = empty attribute list
1285 # #71870 Use of uninitialized value in bitwise and B::Deparse
1287 @a = split(/foo/, $s, 0);
1289 @a = split(/$r/, $s, 0);
1292 # package declaration before label
1298 # shift optimisation
1303 # shift optimisation
1306 # shift optimisation
1311 # shift optimisation
1315 "foo" =~ (1 ? /foo/ : /bar/);
1316 "foo" =~ (1 ? y/foo// : /bar/);
1317 "foo" =~ (1 ? y/foo//r : /bar/);
1318 "foo" =~ (1 ? s/foo// : /bar/);
1320 'foo' =~ ($_ =~ /foo/);
1321 'foo' =~ ($_ =~ tr/fo//);
1322 'foo' =~ ($_ =~ tr/fo//r);
1323 'foo' =~ ($_ =~ s/foo//);
1325 # The fix for [perl #20444] broke this.
1328 # [perl #81424] match against aelemfast_lex
1344 use constant QR_CONSTANT => qr/a/soupmix;
1353 # [perl #91318] /regexp/applaud
1354 print /a/a, s/b/c/a;
1355 print /a/aa, s/b/c/aa;
1356 print /a/p, s/b/c/p;
1357 print /a/l, s/b/c/l;
1358 print /a/u, s/b/c/u;
1360 use feature "unicode_strings";
1361 print /a/d, s/b/c/d;
1365 print /a/d, s/b/c/d;
1369 print /a/d, s/b/c/d;
1372 print /a/a, s/b/c/a;
1373 print /a/aa, s/b/c/aa;
1374 print /a/p, s/b/c/p;
1375 print /a/l, s/b/c/l;
1376 print /a/u, s/b/c/u;
1378 use feature 'unicode_strings';
1379 print /a/d, s/b/c/d;
1382 BEGIN { $^H{'reflags'} = '0';
1383 $^H{'reflags_charset'} = '2'; }
1384 print /a/d, s/b/c/d;
1388 use feature ':5.12';
1389 print /a/d, s/b/c/d;
1392 # all the flags (qr//)
1404 use feature 'unicode_strings';
1407 # all the flags (m//)
1421 use feature 'unicode_strings';
1424 # all the flags (s///)
1439 use feature 'unicode_strings';
1442 # all the flags (tr///)
1448 # [perl #119807] s//\(3)/ge should not warn when deparsed (\3 warns)
1452 "" =~ /a(?{ print q|
1455 '' =~ /a(?{ print "\n"; })/;
1458 $_ = qr/(??{<<END})/
1463 $_ = qr/(??{ "f.o\nb.r\n"; })/;
1465 # More regexp code block madness
1472 /a(??{ die $b; })a/;
1473 /$a(??{ die $b; })/;
1474 /@a(??{ die $b; })/;
1476 qr/a(?{ die $b; })a/;
1477 qr/$a(?{ die $b; })/;
1478 qr/@a(?{ die $b; })/;
1479 qr/(??{ die $b; })/;
1480 qr/a(??{ die $b; })a/;
1481 qr/$a(??{ die $b; })/;
1482 qr/@a(??{ die $b; })/;
1484 s/a(?{ die $b; })a//;
1485 s/$a(?{ die $b; })//;
1486 s/@a(?{ die $b; })//;
1487 s/(??{ die $b; })//;
1488 s/a(??{ die $b; })a//;
1489 s/$a(??{ die $b; })//;
1490 s/@a(??{ die $b; })//;
1492 # /(?x)<newline><tab>/
1497 tr/a/b/r + $a =~ tr/p/q/r;
1499 # y///d in list [perl #119815]
1510 # SKIP ?$] >= 5.023 && "autoderef deleted in this Perl version"
1511 # CONTEXT no warnings 'experimental::autoderef';
1516 # readpipe with complex expression
1522 # aelemfast for a lexical
1526 # feature features without feature
1527 # CONTEXT no warnings 'experimental::smartmatch';
1543 # feature features when feature has been disabled by use VERSION
1544 # CONTEXT no warnings 'experimental::smartmatch';
1545 use feature (sprintf(":%vd", $^V));
1575 # (the above test with CONTEXT, and the output is equivalent but different)
1576 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
1577 # feature features when feature has been disabled by use VERSION
1578 use feature (sprintf(":%vd", $^V));
1595 use feature ':default';
1610 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1611 # lexical subroutines and keywords of the same name
1612 # CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental';
1636 CORE::if ($1) { die; }
1637 CORE::if ($1) { die; }
1638 CORE::elsif ($1) { die; }
1640 CORE::for (die; $1; die) { die; }
1641 CORE::foreach $_ (1 .. 10) { die; }
1642 die CORE::foreach (1);
1643 CORE::given ($1) { die; }
1648 () = (CORE::q['], CORE::qq["$_], CORE::qr//, CORE::qx[`]);
1651 () = CORE::sub { die; } ;
1653 CORE::unless ($1) { die; }
1654 CORE::until ($1) { die; }
1657 CORE::whereis (5) { die; }
1658 CORE::whereso ($1 ~~ $2) { die; }
1659 CORE::while ($1) { die; }
1663 use feature 'current_sub', 'evalbytes';
1669 no feature 'unicode_strings';
1672 use feature 'current_sub', 'evalbytes';
1675 use feature ':default';
1678 use feature ':5.12';
1680 no feature 'unicode_strings';
1683 # $#- $#+ $#{%} etc.
1685 @x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
1686 @x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
1687 @x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
1688 @x = ($#{;}, $#{:}, $#{1}), $#_;
1691 # It's a known TODO that warnings are deparsed as bits, not textually.
1695 # [perl #86060] $( $| $) in regexps need braces
1706 # sort(foo(bar)) is interpreted as sort &foo(bar)
1707 # sort foo(bar) is interpreted as sort foo bar
1708 # parentheses are not optional in this case
1709 print sort(foo('bar'));
1711 print sort(foo('bar'));
1714 substr(my $a, 0, 0) = (foo(), bar());
1717 # This following line works around an unfixed bug that we are not trying to
1719 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1721 BEGIN { $^H{'foo'} = undef; }
1723 BEGIN { $^H{'bar'} = undef; }
1725 BEGIN { $^H{'baz'} = undef; }
1733 BEGIN { $^H{q[']} = '('; }
1736 # This following line works around an unfixed bug that we are not trying to
1738 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1739 # hint hash changes that serialise the same way with sort %hh
1740 BEGIN { $^H{'a'} = 'b'; }
1742 BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
1747 # [perl #47361] do({}) and do +{} (variants of do-file)
1761 # [perl #77096] functions that do not follow the llafr
1762 () = (return 1) + time;
1763 () = (return ($1 + $2) * $3) + time;
1764 () = (return ($a xor $b)) + time;
1765 () = (do 'file') + time;
1766 () = (do ($1 + $2) * $3) + time;
1767 () = (do ($1 xor $2)) + time;
1769 () = (require 'foo') + 3;
1770 () = (require foo) + 3;
1771 () = (CORE::dump 1) + 3;
1782 # require(foo()) and do(foo())
1794 # [perl #97476] not() *does* follow the llafr
1795 $_ = ($a xor not +($1 || 2) ** 2);
1797 # Precedence conundrums with argument-less function calls
1805 # loopexes have assignment prec
1806 () = (CORE::dump a) | 'b';
1807 () = (goto a) | 'b';
1808 () = (last a) | 'b';
1809 () = (next a) | 'b';
1810 () = (redo a) | 'b';
1812 # [perl #63558] open local(*FH)
1814 pipe local *FH, local *FH;
1816 # [perl #91416] open "string"
1829 () = 'open'->[0]; #aelemfast
1834 () = 'open'->[$_]; #aelem
1839 () = 'open'->{0}; #helem
1860 () = 'a::]b'->{'0'};
1862 # [perl #74740] -(f()) vs -f()
1868 #[perl #30504] foreach-my postfix/prefix difference
1869 $_ = 'foo' foreach my ($foo1, $bar1, $baz1);
1870 foreach (my ($foo2, $bar2, $baz2)) { $_ = 'foo' }
1871 foreach my $i (my ($foo3, $bar3, $baz3)) { $i = 'foo' }
1873 $_ = 'foo' foreach (my($foo1, $bar1, $baz1));
1874 foreach $_ (my($foo2, $bar2, $baz2)) {
1877 foreach my $i (my($foo3, $bar3, $baz3)) {
1881 #[perl #108224] foreach with continue block
1882 foreach (1 .. 3) { print } continue { print "\n" }
1883 foreach (1 .. 3) { } continue { }
1884 foreach my $i (1 .. 3) { print $i } continue { print "\n" }
1885 foreach my $i (1 .. 3) { } continue { }
1887 foreach $_ (1 .. 3) {
1893 foreach $_ (1 .. 3) {
1899 foreach my $i (1 .. 3) {
1905 foreach my $i (1 .. 3) {
1926 # 'my' works with padrange op
1933 ($m3, $m4) = (1, 2);
1935 my($m5, $m6) = (1, 2);
1936 my($m7, undef, $m8) = (1, 2, 3);
1937 @z = ($m7, undef, $m8);
1938 ($m7, undef, $m8) = (1, 2, 3);
1940 # 'our/local' works with padrange op
1951 ($o3, $o4) = (1, 2);
1952 local($o3, $o4) = (1, 2);
1954 @z = local($o3, $o4);
1955 our($o5, $o6) = (1, 2);
1956 our($o7, undef, $o8) = (1, 2, 3);
1957 @z = ($o7, undef, $o8);
1958 @z = local($o7, undef, $o8);
1959 ($o7, undef, $o8) = (1, 2, 3);
1960 local($o7, undef, $o8) = (1, 2, 3);
1962 # 'state' works with padrange op
1963 # CONTEXT no strict; use feature 'state';
1970 ($s3, $s4) = (1, 2);
1972 # assignment of state lists isn't implemented yet
1973 #state($s5, $s6) = (1, 2);
1974 #state($s7, undef, $s8) = (1, 2, 3);
1975 #@z = ($s7, undef, $s8);
1976 ($s7, undef, $s8) = (1, 2, 3);
1978 # anon arrays with padrange
1983 # slices with padrange
1989 # binops with padrange
2003 my($a, $b, $c, $d, @e);
2008 @e = ($a, $b, $c) x $d;
2012 my($a, $b, $c) = @_;
2014 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
2015 # lexical subroutine
2016 # CONTEXT use feature 'lexical_subs';
2017 no warnings "experimental::lexical_subs";
2021 BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"}
2027 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
2028 # lexical "state" subroutine
2029 # CONTEXT use feature 'state', 'lexical_subs';
2030 no warnings 'experimental::lexical_subs';
2034 BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"}
2040 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
2041 # lexical subroutine scoping
2042 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
2060 # self-referential lexical subroutine
2061 # CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
2068 # lexical subroutine with outer declaration and inner definition
2069 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
2077 # TODO only partially fixed
2078 # lexical state subroutine with outer declaration and inner definition
2079 # CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
2092 # Elements of %# should not be confused with $#{ array }
2101 # Ampersand calls and scalar context
2108 &foo(scalar bar(), scalar baz());
2110 # coderef2text and prototyped sub calls [perl #123435]
2113 # prototypes with unary precedence
2116 sub optdollar(;$) {}
2117 sub optoptdollar(;;$) {}
2120 sub optoptsplat(;;*) {}
2123 sub optoptbar(;;_) {}
2126 sub optoptplus(;;+) {}
2129 sub optoptwack(;;\$) {}
2130 sub wackbrack(\[$]) {}
2131 sub optwackbrack(;\[$]) {}
2132 sub optoptwackbrack(;;\[$]) {}
2135 optoptdollar($a < $b);
2136 splat($a < $b); # Some of these deparse with ‘&’; if that changes, just
2137 optsplat($a < $b); # change the tests.
2138 optoptsplat($a < $b);
2144 optoptplus($a < $b);
2147 optoptwack($a = $b);
2149 optwackbrack($a = $b);
2150 optoptwackbrack($a = $b);
2155 optoptdollar($a < $b);
2158 &optoptsplat($a < $b);
2164 &optoptplus($a < $b);
2166 &optwack(\($a = $b));
2167 &optoptwack(\($a = $b));
2168 &wackbrack(\($a = $b));
2169 &optwackbrack(\($a = $b));
2170 &optoptwackbrack(\($a = $b));
2172 # ensure aelemfast works in the range -128..127 and that there's no
2176 $x = $a[-256] + $a[-255] + $a[-129] + $a[-128] + $a[-127] + $a[-1] + $a[0];
2177 $x = $a[1] + $a[126] + $a[127] + $a[128] + $a[255] + $a[256];
2179 $x = $b[-256] + $b[-255] + $b[-129] + $b[-128] + $b[-127] + $b[-1] + $b[0];
2180 $x = $b[1] + $b[126] + $b[127] + $b[128] + $b[255] + $b[256];
2182 # 'm' must be preserved in m??
2185 # \(@array) and \(..., (@array), ...)
2186 my(@array, %hash, @a, @b, %c, %d);
2189 () = \(@a, (@b), (%c), %d);
2190 () = \(@Foo::array);
2192 () = \(@Foo::a, (@Foo::b), (%Foo::c), %Foo::d);
2194 # subs synonymous with keywords
2198 use feature 'state';
2202 # CONTEXT use feature "state", 'refaliasing', 'lexical_subs'; no warnings 'experimental';
2214 \($x, my $a) = @{[\$x, \$x]};
2215 (\$x, \my $b) = @{[\$x, \$x]};
2227 \local($a[1]) = foo();
2230 \local @a[0,1] = (\$a)x2;
2237 \local($h{b}) = \$x;
2238 \@h{'a','b'} = foo();
2240 \local @h{'a','b'} = (\$x)x2;
2276 (\$_, $_) = \(1, 2);
2277 $_ == 3 ? \$_ : $_ = \3;
2278 $_ == 3 ? \$_ : \$x = \3;
2279 \($_ == 3 ? $_ : $x) = \3;
2280 for \my $topic (\$1, \$2) {
2283 for \state $topic (\$1, \$2) {
2286 for \our $topic (\$1, \$2) {
2289 for \$_ (\$1, \$2) {
2292 for \my @a ([1,2], [3,4]) {
2295 for \state @a ([1,2], [3,4]) {
2298 for \our @a ([1,2], [3,4]) {
2301 for \@_ ([1,2], [3,4]) {
2304 for \my %a ({5,6}, {7,8}) {
2307 for \our %a ({5,6}, {7,8}) {
2310 for \state %a ({5,6}, {7,8}) {
2313 for \%_ ({5,6}, {7,8}) {
2318 for \&a (sub { 9; }, sub { 10; }) {
2322 for \&a (sub { 9; }, sub { 10; }) {
2337 (\$x, \my $a) = @{[\$x, \$x];};
2338 (\$x, \my $b) = @{[\$x, \$x];};
2350 (\local $a[1]) = foo();
2351 (\@a[0, 1]) = foo();
2352 (\@a[2, 3]) = foo();
2353 (\local @a[0, 1]) = (\$a) x 2;
2359 \local $h{'a'} = \$x;
2360 (\local $h{'b'}) = \$x;
2361 (\@h{'a', 'b'}) = foo();
2362 (\@h{2, 3}) = foo();
2363 (\local @h{'a', 'b'}) = (\$x) x 2;
2389 (\our %zz) = {1, 2};
2399 (\$_, $_) = \(1, 2);
2400 $_ == 3 ? \$_ : $_ = \3;
2401 $_ == 3 ? \$_ : \$x = \3;
2402 ($_ == 3 ? \$_ : \$x) = \3;
2403 foreach \my $topic (\$1, \$2) {
2406 foreach \state $topic (\$1, \$2) {
2409 foreach \our $topic (\$1, \$2) {
2412 foreach \$_ (\$1, \$2) {
2415 foreach \my @a ([1, 2], [3, 4]) {
2418 foreach \state @a ([1, 2], [3, 4]) {
2421 foreach \our @a ([1, 2], [3, 4]) {
2424 foreach \@_ ([1, 2], [3, 4]) {
2427 foreach \my %a ({5, 6}, {7, 8}) {
2430 foreach \our %a ({5, 6}, {7, 8}) {
2433 foreach \state %a ({5, 6}, {7, 8}) {
2436 foreach \%_ ({5, 6}, {7, 8}) {
2441 foreach \&a (sub { 9; } , sub { 10; } ) {
2445 foreach \&a (sub { 9; } , sub { 10; } ) {
2454 $_ = join('???', pos $_);
2460 # my @a; exists $a[0]
2468 # my @a; delete $a[0]
2483 # my $x = "$h{foo}";
2485 my $x = "$h{'foo'}";
2487 # weird constant hash key
2489 my $x = $h{"\000\t\x{100}"};
2491 # multideref and packages
2493 my(%bar) = ('a', 'b');
2495 $bar{'k'} = $bar[200];
2496 $main::bar{'k'} = $main::bar[200];
2497 $foo::bar{'k'} = $foo::bar[200];
2499 $bar{'k'} = $bar[200];
2500 $main::bar{'k'} = $main::bar[200];
2501 $foo::bar{'k'} = $foo::bar[200];
2504 my(%bar) = ('a', 'b');
2506 $bar{'k'} = $bar[200];
2507 $main::bar{'k'} = $main::bar[200];
2508 $foo::bar{'k'} = $bar[200];
2510 $bar{'k'} = $foo::bar[200];
2511 $main::bar{'k'} = $main::bar[200];
2512 $foo::bar{'k'} = $foo::bar[200];
2514 # multideref and local
2516 local $h{'foo'}[0] = 1;
2518 # multideref and exists
2520 my $e = exists $h{'foo'}[$i];
2522 # multideref and delete
2524 my $e = delete $h{'foo'}[$i];
2526 # multideref with leading expression
2528 my $x = +($r // [])->{'foo'}[0];
2530 # multideref with complex middle index
2532 my $x = $h{'foo'}[$i + $j]{$k};
2534 # multideref with trailing non-simple index that initially looks simple
2535 # (i.e. the constant "3")
2537 my $x = +($r || {})->{'foo'}[$i + $j]{3 + $k};
2545 # CONTEXT use feature "bitwise"; no warnings "experimental::bitwise";
2562 # Should really use 'no warnings "experimental::signatures"',
2563 # but it doesn't yet deparse correctly.
2564 # anon subs used because this test framework doesn't deparse named subs
2565 # in the DATA code snippets.
2569 use feature 'signatures';
2571 sub ($a, $, $b = $glo::bal, $c = $a, $d = 'foo', $e = -37, $f = 0, $g = 1, $h = undef, $i = $a + 1, $j = /foo/, @) {
2577 # Signature and prototype
2579 use feature 'signatures';
2581 sub ($a, $b) : prototype($$) {
2587 # Signature and prototype and attrs
2589 use feature 'signatures';
2591 sub ($a, $b) : prototype($$) lvalue {
2597 # Signature and attrs
2599 use feature 'signatures';
2601 sub ($a, $b) : lvalue method {
2607 # named array slurp, null body
2609 use feature 'signatures';
2617 use feature 'signatures';
2625 use feature 'signatures';
2631 # parenthesised default arg
2633 use feature 'signatures';
2634 sub ($a, $b = (/foo/), $c = 1) {
2639 # parenthesised default arg with TARGMY
2641 use feature 'signatures';
2642 sub ($a, $b = ($a + 1), $c = 1) {
2649 use feature 'signatures';
2655 # padrange op within pattern code blocks
2656 /(?{ my($x, $y) = (); })/;
2658 /$a(?{ my($x, $y) = (); })/;
2659 my $r1 = qr/(?{ my($x, $y) = (); })/;
2660 my $r2 = qr/$a(?{ my($x, $y) = (); })/;
2662 # don't remove pattern whitespace escapes
2669 my $s1 :foo(f1, f2) bar(b1, b2);
2670 my @a1 :foo(f1, f2) bar(b1, b2);
2671 my %h1 :foo(f1, f2) bar(b1, b2);
2672 my($s2, @a2, %h2) :foo(f1, f2) bar(b1, b2);
2674 # my class attributes
2676 my Foo::Bar $s1 :foo(f1, f2) bar(b1, b2);
2677 my Foo::Bar @a1 :foo(f1, f2) bar(b1, b2);
2678 my Foo::Bar %h1 :foo(f1, f2) bar(b1, b2);
2679 my Foo::Bar ($s2, @a2, %h2) :foo(f1, f2) bar(b1, b2);
2681 my Foo::Bar $s3 :foo(f1, f2) bar(b1, b2);
2682 my Foo::Bar @a3 :foo(f1, f2) bar(b1, b2);
2683 my Foo::Bar %h3 :foo(f1, f2) bar(b1, b2);
2684 my Foo::Bar ($s4, @a4, %h4) :foo(f1, f2) bar(b1, b2);
2686 # avoid false positives in my $x :attribute
2687 'attributes'->import('main', \my $x1, 'foo(bar)'), my $y1;
2688 'attributes'->import('Fooo', \my $x2, 'foo(bar)'), my $y2;
2690 # hash slices and hash key/value slices
2693 @a = @h{'foo', 'bar'};
2694 @a = %h{'foo', 'bar'};
2695 @a = delete @h{'foo', 'bar'};
2696 @a = delete %h{'foo', 'bar'};
2697 @oa = @oh{'foo', 'bar'};
2698 @oa = %oh{'foo', 'bar'};
2699 @oa = delete @oh{'foo', 'bar'};
2700 @oa = delete %oh{'foo', 'bar'};
2702 # keys optimised away in void and scalar context
2716 # eq,const optimised away for (index() == -1)
2719 $c = index($a, $b) == 2;
2720 $c = rindex($a, $b) == 2;
2721 $c = index($a, $b) == -1;
2722 $c = rindex($a, $b) == -1;
2723 $c = index($a, $b) != -1;
2724 $c = rindex($a, $b) != -1;
2725 $c = (index($a, $b) == -1);
2726 $c = (rindex($a, $b) == -1);
2727 $c = (index($a, $b) != -1);
2728 $c = (rindex($a, $b) != -1);
2730 # eq,const,sassign,madmy optimised away for (index() == -1)
2733 $c = index($a, $b) == 2;
2734 $c = rindex($a, $b) == 2;
2735 $c = index($a, $b) == -1;
2736 $c = rindex($a, $b) == -1;
2737 $c = index($a, $b) != -1;
2738 $c = rindex($a, $b) != -1;
2739 $c = (index($a, $b) == -1);
2740 $c = (rindex($a, $b) == -1);
2741 $c = (index($a, $b) != -1);
2742 $c = (rindex($a, $b) != -1);
2745 my($a, $b, $c, $d, @a);
2746 $d = length $a . $b . $c;
2747 $d = length($a) . $b . $c;
2749 push @a, ($a . '') * $b;
2750 unshift @a, "$a" * ($b . '');
2751 print $a . 'x' . $b . $c;
2752 print $a . 'x' . $b . $c, $d;
2753 print $b . $c . ($a . $b);
2754 print $b . $c . ($a . $b);
2756 print $a . "\x{100}";
2758 # double-quoted multiconcat
2759 my($a, $b, $c, $d, @a);
2760 print "${a}x\x{100}$b$c";
2761 print "$a\Q$b\E$c\Ua$a\E\Lb$b\uc$c\E$a${b}c$c";
2762 print "A=$a[length 'b' . $c . 'd'] b=$b";
2764 print "\x{101}$a\x{100}";
2772 # sprintf multiconcat
2773 my($a, $b, $c, $d, @a);
2774 print sprintf("%s%s%%%sx%s\x{100}%s", $a, $b, $c, scalar @a, $d);
2776 # multiconcat with lexical assign
2777 my($a, $b, $c, $d, $e, @a);
2781 $d = 'foo' . $a . 'bar';
2784 $d = $a . $b . $c . @a;
2785 $e = ($d = $a . $b . $c);
2787 $a = $b . $c . ($a . $b);
2788 $e = f($d = !$a . $b) . $c;
2789 $d = "${a}x\x{100}$b$c";
2790 f($d = !$a . $b . $c);
2792 # multiconcat with lexical my
2793 my($a, $b, $c, $d, $e, @a);
2794 my $d1 = 'foo' . $a;
2797 my $d4 = 'foo' . $a . 'bar';
2799 my $d6 = $a . $b . $c;
2800 my $e7 = ($d = $a . $b . $c);
2801 my $d8 = !$a . $b . $c;
2802 my $d9 = $b . $c . ($a . $b);
2803 my $da = f($d = !$a . $b) . $c;
2804 my $dc = "${a}x\x{100}$b$c";
2805 f(my $db = !$a . $b . $c);
2806 my $dd = $a . $b . $c . @a;
2808 # multiconcat with lexical append
2809 my($a, $b, $c, $d, $e, @a);
2816 $d .= 'foo' . $a . 'bar';
2820 $e .= ($d = $a . $b . $c);
2821 $d .= !$a . $b . $c;
2822 $a .= $b . $c . ($a . $b);
2823 $e .= f($d .= !$a . $b) . $c;
2824 f($d .= !$a . $b . $c);
2825 $d .= "${a}x\x{100}$b$c";
2827 # multiconcat with expression assign
2833 $d = 'foo' . $a . 'bar';
2837 $e = ($d = $a . $b . $c);
2838 $a["-$b-"] = !$a . $b . $c;
2839 $a[$b]{$c}{$d ? $a : $b . $c} = !$a . $b . $c;
2840 $a = $b . $c . ($a . $b);
2841 $e = f($d = !$a . $b) . $c;
2842 $d = "${a}x\x{100}$b$c";
2843 f($d = !$a . $b . $c);
2845 # multiconcat with expression concat
2851 $d .= 'foo' . $a . 'bar';
2855 $e .= ($d .= $a . $b . $c);
2856 $a["-$b-"] .= !$a . $b . $c;
2857 $a[$b]{$c}{$d ? $a : $b . $c} .= !$a . $b . $c;
2858 $a .= $b . $c . ($a . $b);
2859 $e .= f($d .= !$a . $b) . $c;
2860 $d .= "${a}x\x{100}$b$c";
2861 f($d .= !$a . $b . $c);
2863 # multiconcat with CORE::sprintf
2864 # CONTEXT sub sprintf {}
2866 my $x = CORE::sprintf('%s%s', $a, $b);
2868 # multiconcat with backticks
2873 # multiconcat within qr//
2875 $r = qr/abc\Q$a-$b\Exyz/;
2877 # tr with unprintable characters
2882 # CORE::foo special case in bareword parsing
2883 print $CORE::foo, $CORE::foo::bar;
2884 print @CORE::foo, @CORE::foo::bar;
2885 print %CORE::foo, %CORE::foo::bar;
2886 print $CORE::foo{'a'}, $CORE::foo::bar{'a'};
2887 print &CORE::foo, &CORE::foo::bar;
2888 print &CORE::foo(), &CORE::foo::bar();
2889 print \&CORE::foo, \&CORE::foo::bar;
2890 print *CORE::foo, *CORE::foo::bar;
2891 print stat CORE::foo::, stat CORE::foo::bar;
2892 print CORE::foo:: 1;
2893 print CORE::foo::bar 2;
2895 # trailing colons on glob names
2898 print $foo, $foo::, $foo::::;
2899 print @foo, @foo::, @foo::::;
2900 print %foo, %foo::, %foo::::;
2901 print $foo{'a'}, $foo::{'a'}, $foo::::{'a'};
2902 print &foo, &foo::, &foo::::;
2903 print &foo(), &foo::(), &foo::::();
2904 print \&foo, \&foo::, \&foo::::;
2905 print *foo, *foo::, *foo::::;
2906 print stat Foo, stat Foo::::;
2910 # trailing colons mixed with CORE
2912 print $CORE, $CORE::, $CORE::::;
2913 print @CORE, @CORE::, @CORE::::;
2914 print %CORE, %CORE::, %CORE::::;
2915 print $CORE{'a'}, $CORE::{'a'}, $CORE::::{'a'};
2916 print &CORE, &CORE::, &CORE::::;
2917 print &CORE(), &CORE::(), &CORE::::();
2918 print \&CORE, \&CORE::, \&CORE::::;
2919 print *CORE, *CORE::, *CORE::::;
2920 print stat CORE, stat CORE::::;
2923 print $CORE::foo, $CORE::foo::, $CORE::foo::::;
2924 print @CORE::foo, @CORE::foo::, @CORE::foo::::;
2925 print %CORE::foo, %CORE::foo::, %CORE::foo::::;
2926 print $CORE::foo{'a'}, $CORE::foo::{'a'}, $CORE::foo::::{'a'};
2927 print &CORE::foo, &CORE::foo::, &CORE::foo::::;
2928 print &CORE::foo(), &CORE::foo::(), &CORE::foo::::();
2929 print \&CORE::foo, \&CORE::foo::, \&CORE::foo::::;
2930 print *CORE::foo, *CORE::foo::, *CORE::foo::::;
2931 print stat CORE::foo::, stat CORE::foo::::;
2932 print CORE::foo:: 1;
2933 print CORE::foo:::: 2;
2953 print exists &main::foo;
2954 print exists &{foo};
2957 print exists &main::foo;
2958 print exists &{foo};
2959 print exists &main::bar;
2960 # precedence of optimised-away 'keys' (OPpPADHV_ISKEYS/OPpRV2HV_ISKEYS)
2967 $res = keys(%h1) / 2 - 1;
2968 $res = keys(%h2) / 2 - 1;
2969 $res = keys(%$r1) / 2 - 1;
2970 $res = keys(%$r2) / 2 - 1;
2972 # ditto in presence of sub keys {}
2973 # CONTEXT sub keys {}
2978 CORE::keys(%h1) / 2;
2979 $res = CORE::keys %h1;
2980 $res = CORE::keys %h2;
2981 $res = CORE::keys %$r1;
2982 $res = CORE::keys %$r2;
2983 $res = CORE::keys(%h1) / 2 - 1;
2984 $res = CORE::keys(%h2) / 2 - 1;
2985 $res = CORE::keys(%$r1) / 2 - 1;
2986 $res = CORE::keys(%$r2) / 2 - 1;
2988 # concat: STACKED: ambiguity between .= and optimised nested
2991 (($a .= $a) .= $a) .= $a;
2993 # multiconcat: $$ within string
2998 # single state aggregate assignment
2999 # CONTEXT use feature "state";
3000 state @a = (1, 2, 3);
3001 state %h = ('a', 1, 'b', 2);
3003 # state var with attribute
3004 # CONTEXT use feature "state";
3006 state $y :shared = 1;
3008 state @b :shared = (1, 2);
3010 state %i :shared = ('a', 1, 'b', 2);