This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
1c3e50bafd8eb9c25673be892aeefbda4fa4226b
[perl5.git] / lib / B / Deparse.t
1 #!./perl
2
3 BEGIN {
4     unshift @INC, 't';
5     require Config;
6     if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7         print "1..0 # Skip -- Perl configured without B module\n";
8         exit 0;
9     }
10     require 'test.pl';
11 }
12
13 use warnings;
14 use strict;
15
16 my $tests = 36; # not counting those in the __DATA__ section
17
18 use B::Deparse;
19 my $deparse = B::Deparse->new();
20 isa_ok($deparse, 'B::Deparse', 'instantiate a B::Deparse object');
21 my %deparse;
22
23 $/ = "\n####\n";
24 while (<DATA>) {
25     chomp;
26     $tests ++;
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};
36             if ($@) {
37                 die "# In \U$what\E code reason:\n# $meta{$what}\n$@";
38             }
39             $meta{$what} = $temp;
40         }
41     }
42
43     s/^\s*#\s*(.*)$//mg;
44     my $desc = $1;
45     die "Missing name in test $_" unless defined $desc;
46
47     if ($meta{skip}) {
48         SKIP: { skip($meta{skip}) };
49         next;
50     }
51
52     my ($input, $expected);
53     if (/(.*)\n>>>>\n(.*)/s) {
54         ($input, $expected) = ($1, $2);
55     }
56     else {
57         ($input, $expected) = ($_, $_);
58     }
59
60     # parse options if necessary
61     my $deparse = $meta{options}
62         ? $deparse{$meta{options}} ||=
63             new B::Deparse split /,/, $meta{options}
64         : $deparse;
65
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);
69 BEGIN {
70     ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H);
71 }
72 $deparse->ambient_pragmas (
73     hint_bits    => $hint_bits,
74     warning_bits => $warning_bits,
75     '%^H'        => $hinthash,
76 );
77 EOC
78
79     local $::TODO = $meta{todo};
80     if ($@) {
81         is($@, "", "compilation of $desc");
82     }
83     else {
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*\}$';
89
90         like($deparsed, qr/$regex/, $desc);
91     }
92 }
93
94 # Reset the ambient pragmas
95 {
96     my ($b, $w, $h);
97     BEGIN {
98         ($b, $w, $h) = ($^H, ${^WARNING_BITS}, \%^H);
99     }
100     $deparse->ambient_pragmas (
101         hint_bits    => $b,
102         warning_bits => $w,
103         '%^H'        => $h,
104     );
105 }
106
107 use constant 'c', 'stuff';
108 is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
109    'the subroutine generated by use constant deparses');
110
111 my $a = 0;
112 is($deparse->coderef2text(sub{(-1) ** $a }), "{\n    (-1) ** \$a;\n}",
113    'anon sub capturing an external lexical');
114
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');
120
121 my $path = join " ", map { qq["-I$_"] } @INC;
122
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"; }
129 BEGIN { $^W = 1; }
130 BEGIN { $/ = "\n"; $\ = "\n"; }
131 LINE: while (defined($_ = <ARGV>)) {
132     chomp $_;
133     our(@F) = split(' ', $_, 0);
134     '???';
135 }
136 EOF
137 $b =~ s/our\\\(\\\@F\\\)/our[( ]\@F\\)?/; # accept both our @F and our(@F)
138 like($a, qr/$b/,
139    'command line flags deparse as BEGIN blocks setting control variables');
140
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");
145
146 #Re: perlbug #35857, patch #24505
147 #handle warnings::register-ed packages properly.
148 package B::Deparse::Wrapper;
149 use strict;
150 use warnings;
151 use warnings::register;
152 sub getcode {
153    my $deparser = B::Deparse->new();
154    return $deparser->coderef2text(shift);
155 }
156
157 package Moo;
158 use overload '0+' => sub { 42 };
159
160 package main;
161 use strict;
162 use warnings;
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/;
169 sub test {
170    my $val = shift;
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');
174 }
175 my ($q,$p);
176 my $x=sub { ++$q,++$p };
177 test($x);
178 eval <<EOFCODE and test($x);
179    package bar;
180    use strict;
181    use warnings;
182    use warnings::register;
183    package main;
184    1
185 EOFCODE
186
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 ::::::");
191 sub :::: {
192     
193 }
194 sub :::::: {
195     
196 }
197 EOCODG
198
199 # [perl #117311]
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");
203 #line 1 "-e"
204 map {
205 #line 1 "-e"
206 eval 0;} ();
207 EOCODH
208
209 # [perl #33752]
210 {
211   my $code = <<"EOCODE";
212 {
213     our \$\x{1e1f}\x{14d}\x{14d};
214 }
215 EOCODE
216   my $deparsed
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';
220 }
221
222 # [perl #62500]
223 $a =
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");
227 sub BEGIN {
228     *CORE::GLOBAL::require = sub {
229         1;
230     }
231     ;
232 }
233 EOCODF
234
235 # [perl #91384]
236 $a =
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");
240
241 # [perl #93990]
242 @] = ();
243 is($deparse->coderef2text(sub{ print "foo@{]}" }),
244 q<{
245     print "foo@{]}";
246 }>, 'curly around to interpolate "@{]}"');
247 is($deparse->coderef2text(sub{ print "foo@{-}" }),
248 q<{
249     print "foo@-";
250 }>, 'no need to curly around to interpolate "@-"');
251
252 # Strict hints in %^H are mercilessly suppressed
253 $a =
254   `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
255 unlike($a, qr/BEGIN/,
256     "Deparse does not emit strict hh hints");
257
258 # ambient_pragmas should not mess with strict settings.
259 SKIP: {
260     skip "requires 5.11", 1 unless $] >= 5.011;
261     eval q`
262         BEGIN {
263             # Clear out all hints
264             %^H = ();
265             $^H = 0;
266             new B::Deparse -> ambient_pragmas(strict => 'all');
267         }
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';
271    `;
272 }
273
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');
278 format STDOUT =
279 @
280 x(); z()
281 .
282 EOCODH
283
284 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
285            prog => "format =\n\@\n\$;\n.\n"),
286    <<'EOCODM', '$; on format line';
287 format STDOUT =
288 @
289 $;
290 .
291 EOCODM
292
293 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse,-l', $path ],
294            prog => "format =\n\@\n\$foo\n.\n"),
295    <<'EOCODM', 'formats with -l';
296 format STDOUT =
297 @
298 $foo
299 .
300 EOCODM
301
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';
305 {
306     my $x;
307     format STDOUT =
308 @
309 $x
310 .
311 }
312 EOCODN
313
314 # CORE::format
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');
318
319 # literal big chars under 'use utf8'
320 is($deparse->coderef2text(sub{ use utf8; /€/; }),
321 '{
322     /\x{20ac}/;
323 }',
324 "qr/euro/");
325
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()');
331 foo();
332 EOCODI
333
334 # CORE::no
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');
339
340 # CORE::use
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');
345
346 # CORE::__DATA__
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__');
352
353 # sub declarations
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-;
362                     sub f($);
363                     BEGIN { weaken($_=\$::{f}) }'),
364      qr/sub f\s*\(\$\)\s*;/,
365     'prototyped stub with weak reference to the stash entry';
366
367 # BEGIN blocks
368 SKIP : {
369     skip "BEGIN output is wrong on old perls", 1 if $] < 5.021006;
370     my $prog = '
371       BEGIN { pop }
372       {
373         BEGIN { pop }
374         {
375           no overloading;
376           {
377             BEGIN { pop }
378             die
379           }
380         }
381       }';
382     $prog =~ s/\n//g;
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');
386 sub BEGIN {
387     pop @ARGV;
388 }
389 {
390     sub BEGIN {
391         pop @ARGV;
392     }
393     {
394         no overloading;
395         {
396             sub BEGIN {
397                 pop @ARGV;
398             }
399             die;
400         }
401     }
402 }
403 EOCODJ
404 }
405 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ], prog => '
406       {
407         {
408           die;
409           BEGIN { pop }
410         }
411         BEGIN { pop }
412       }
413       BEGIN { pop }
414   '), <<'EOCODL', 'BEGIN blocks at the end of their enclosing blocks';
415 {
416     {
417         die;
418         sub BEGIN {
419             pop @ARGV;
420         }
421     }
422     sub BEGIN {
423         pop @ARGV;
424     }
425 }
426 sub BEGIN {
427     pop @ARGV;
428 }
429 EOCODL
430
431 # [perl #115066]
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 {
436     1
437 });
438 no overloading;
439 die;
440 EOCODK
441
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';
446
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';
451
452 done_testing($tests);
453
454 __DATA__
455 # TODO [perl #120950] This succeeds when run a 2nd time
456 # y/uni/code/
457 tr/\x{345}/\x{370}/;
458 ####
459 # y/uni/code/  [perl #120950] This 2nd instance succeeds
460 tr/\x{345}/\x{370}/;
461 ####
462 # A constant
463 1;
464 ####
465 # Constants in a block
466 # CONTEXT no warnings;
467 {
468     '???';
469     2;
470 }
471 ####
472 # Lexical and simple arithmetic
473 my $test;
474 ++$test and $test /= 2;
475 >>>>
476 my $test;
477 $test /= 2 if ++$test;
478 ####
479 # list x
480 -((1, 2) x 2);
481 ####
482 # Assignment to list x
483 ((undef) x 3) = undef;
484 ####
485 # lvalue sub
486 {
487     my $test = sub : lvalue {
488         my $x;
489     }
490     ;
491 }
492 ####
493 # method
494 {
495     my $test = sub : method {
496         my $x;
497     }
498     ;
499 }
500 ####
501 # anonsub attrs at statement start
502 my $x = do { +sub : lvalue { my $y; } };
503 my $z = do { foo: +sub : method { my $a; } };
504 ####
505 # block with continue
506 {
507     234;
508 }
509 continue {
510     123;
511 }
512 ####
513 # lexical and package scalars
514 my $x;
515 print $main::x;
516 ####
517 # lexical and package arrays
518 my @x;
519 print $main::x[1];
520 ####
521 # lexical and package hashes
522 my %x;
523 $x{warn()};
524 ####
525 # our (LIST)
526 our($foo, $bar, $baz);
527 ####
528 # CONTEXT { package Dog } use feature "state";
529 # variables with declared classes
530 my Dog $spot;
531 our Dog $spotty;
532 state Dog $spotted;
533 my Dog @spot;
534 our Dog @spotty;
535 state Dog @spotted;
536 my Dog %spot;
537 our Dog %spotty;
538 state Dog %spotted;
539 my Dog ($foo, @bar, %baz);
540 our Dog ($phoo, @barr, %bazz);
541 state Dog ($fough, @barre, %bazze);
542 ####
543 # local our
544 local our $rhubarb;
545 local our($rhu, $barb);
546 ####
547 # <>
548 my $foo;
549 $_ .= <ARGV> . <$foo>;
550 ####
551 # \x{}
552 my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
553 my $bar = "\x{100}";
554 ####
555 # s///e
556 s/x/'y';/e;
557 s/x/$a;/e;
558 s/x/complex_expression();/e;
559 ####
560 # block
561 { my $x; }
562 ####
563 # while 1
564 while (1) { my $k; }
565 ####
566 # trailing for
567 my ($x,@a);
568 $x=1 for @a;
569 >>>>
570 my($x, @a);
571 $x = 1 foreach (@a);
572 ####
573 # 2 arguments in a 3 argument for
574 for (my $i = 0; $i < 2;) {
575     my $z = 1;
576 }
577 ####
578 # 3 argument for
579 for (my $i = 0; $i < 2; ++$i) {
580     my $z = 1;
581 }
582 ####
583 # 3 argument for again
584 for (my $i = 0; $i < 2; ++$i) {
585     my $z = 1;
586 }
587 ####
588 # 3-argument for with inverted condition
589 for (my $i; not $i;) {
590     die;
591 }
592 for (my $i; not $i; ++$i) {
593     die;
594 }
595 for (my $a; not +($1 || 2) ** 2;) {
596     die;
597 }
598 Something_to_put_the_loop_in_void_context();
599 ####
600 # while/continue
601 my $i;
602 while ($i) { my $z = 1; } continue { $i = 99; }
603 ####
604 # foreach with my
605 foreach my $i (1, 2) {
606     my $z = 1;
607 }
608 ####
609 # OPTIONS -p
610 # foreach with my under -p
611 foreach my $i (1) {
612     die;
613 }
614 ####
615 # foreach
616 my $i;
617 foreach $i (1, 2) {
618     my $z = 1;
619 }
620 ####
621 # foreach, 2 mys
622 my $i;
623 foreach my $i (1, 2) {
624     my $z = 1;
625 }
626 ####
627 # foreach with our
628 foreach our $i (1, 2) {
629     my $z = 1;
630 }
631 ####
632 # foreach with my and our
633 my $i;
634 foreach our $i (1, 2) {
635     my $z = 1;
636 }
637 ####
638 # foreach with state
639 # CONTEXT use feature "state";
640 foreach state $i (1, 2) {
641     state $z = 1;
642 }
643 ####
644 # foreach with sub call
645 foreach $_ (hcaerof()) {
646     ();
647 }
648 ####
649 # reverse sort
650 my @x;
651 print reverse sort(@x);
652 ####
653 # sort with cmp
654 my @x;
655 print((sort {$b cmp $a} @x));
656 ####
657 # reverse sort with block
658 my @x;
659 print((reverse sort {$b <=> $a} @x));
660 ####
661 # foreach reverse
662 our @a;
663 print $_ foreach (reverse @a);
664 ####
665 # foreach reverse (not inplace)
666 our @a;
667 print $_ foreach (reverse 1, 2..5);
668 ####
669 # bug #38684
670 our @ary;
671 @ary = split(' ', 'foo', 0);
672 ####
673 # Split to our array
674 our @array = split(//, 'foo', 0);
675 ####
676 # Split to my array
677 my @array  = split(//, 'foo', 0);
678 ####
679 # bug #40055
680 do { () }; 
681 ####
682 # bug #40055
683 do { my $x = 1; $x }; 
684 ####
685 # <20061012113037.GJ25805@c4.convolution.nl>
686 my $f = sub {
687     +{[]};
688 } ;
689 ####
690 # bug #43010
691 '!@$%'->();
692 ####
693 # bug #43010
694 ::();
695 ####
696 # bug #43010
697 '::::'->();
698 ####
699 # bug #43010
700 &::::;
701 ####
702 # [perl #77172]
703 package rt77172;
704 sub foo {} foo & & & foo;
705 >>>>
706 package rt77172;
707 foo(&{&} & foo());
708 ####
709 # variables as method names
710 my $bar;
711 'Foo'->$bar('orz');
712 'Foo'->$bar('orz') = 'a stranger stranger than before';
713 ####
714 # constants as method names
715 'Foo'->bar('orz');
716 ####
717 # constants as method names without ()
718 'Foo'->bar;
719 ####
720 # [perl #47359] "indirect" method call notation
721 our @bar;
722 foo{@bar}+1,->foo;
723 (foo{@bar}+1),foo();
724 foo{@bar}1 xor foo();
725 >>>>
726 our @bar;
727 (foo { @bar } 1)->foo;
728 (foo { @bar } 1), foo();
729 foo { @bar } 1 xor foo();
730 ####
731 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
732 # CONTEXT use feature ':5.10';
733 # say
734 say 'foo';
735 ####
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
739 say 'foo';
740 ####
741 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
742 # say with use 5.10.0
743 use 5.10.0;
744 say 'foo';
745 >>>>
746 no feature;
747 use feature ':5.10';
748 say 'foo';
749 ####
750 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
751 # say with use feature ':5.10';
752 use feature ':5.10';
753 say 'foo';
754 >>>>
755 use feature 'say', 'state', 'switch';
756 say 'foo';
757 ####
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
761 use 5.10.0;
762 say 'foo';
763 >>>>
764 no feature;
765 use feature ':5.10';
766 say 'foo';
767 ####
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
771 use feature ':5.10';
772 say 'foo';
773 >>>>
774 say 'foo';
775 ####
776 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
777 # CONTEXT use feature ':5.15';
778 # __SUB__
779 __SUB__;
780 ####
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
784 __SUB__;
785 ####
786 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
787 # __SUB__ with use 5.15.0
788 use 5.15.0;
789 __SUB__;
790 >>>>
791 no feature;
792 use feature ':5.16';
793 __SUB__;
794 ####
795 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
796 # __SUB__ with use feature ':5.15';
797 use feature ':5.15';
798 __SUB__;
799 >>>>
800 use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
801 __SUB__;
802 ####
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
806 use 5.15.0;
807 __SUB__;
808 >>>>
809 no feature;
810 use feature ':5.16';
811 __SUB__;
812 ####
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
816 use feature ':5.15';
817 __SUB__;
818 >>>>
819 __SUB__;
820 ####
821 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
822 # CONTEXT use feature ':5.10';
823 # state vars
824 state $x = 42;
825 ####
826 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
827 # CONTEXT use feature ':5.10';
828 # state var assignment
829 {
830     my $y = (state $x = 42);
831 }
832 ####
833 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
834 # CONTEXT use feature ':5.10';
835 # state vars in anonymous subroutines
836 $a = sub {
837     state $x;
838     return $x++;
839 }
840 ;
841 ####
842 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
843 # each @array;
844 each @ARGV;
845 each @$a;
846 ####
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;
851 ####
852 # Anonymous arrays and hashes, and references to them
853 my $a = {};
854 my $b = \{};
855 my $c = [];
856 my $d = \[];
857 ####
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
861 given ('foo') {
862     when ('bar') { continue; }
863     when ($_ ~~ 'quux') { continue; }
864     default { 0; }
865 }
866 ####
867 # conditions in elsifs (regression in change #33710 which fixed bug #37302)
868 if ($a) { x(); }
869 elsif ($b) { x(); }
870 elsif ($a and $b) { x(); }
871 elsif ($a or $b) { x(); }
872 else { x(); }
873 ####
874 # interpolation in regexps
875 my($y, $t);
876 /x${y}z$t/;
877 ####
878 # TODO new undocumented cpan-bug #33708
879 # cpan-bug #33708
880 %{$_ || {}}
881 ####
882 # TODO hash constants not yet fixed
883 # cpan-bug #33708
884 use constant H => { "#" => 1 }; H->{"#"}
885 ####
886 # TODO optimized away 0 not yet fixed
887 # cpan-bug #33708
888 foreach my $i (@_) { 0 }
889 ####
890 # tests with not, not optimized
891 my $c;
892 x() unless $a;
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;
897 x() if not $a or $b;
898 x() if $a or 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;
909 ####
910 # tests with not, optimized
911 my $c;
912 x() if not $a;
913 x() unless not $a;
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;
927 >>>>
928 my $c;
929 x() unless $a;
930 x() if $a;
931 x() unless $a or $b;
932 x() if $a or $b;
933 x() unless $a and $b;
934 x() if $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;
944 ####
945 # tests that should be constant folded
946 x() if 1;
947 x() if GLIPP;
948 x() if !GLIPP;
949 x() if GLIPP && GLIPP;
950 x() if !GLIPP || GLIPP;
951 x() if do { 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() }
963 >>>>
964 x();
965 x();
966 '???';
967 x();
968 x();
969 x();
970 x();
971 do {
972     '???'
973 };
974 do {
975     x()
976 };
977 do {
978     z()
979 };
980 do {
981     x()
982 };
983 do {
984     z()
985 };
986 do {
987     x()
988 };
989 '???';
990 do {
991     t()
992 };
993 '???';
994 !1;
995 ####
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
1001 x() if $a;
1002 if ($a == 1) { x() } elsif ($b == 2) { z() }
1003 if (do { foo(); GLIPP }) { x() }
1004 if (do { $a++; GLIPP }) { x() }
1005 >>>>
1006 x() if $a;
1007 if ($a == 1) { x(); } elsif ($b == 2) { z(); }
1008 if (do { foo(); GLIPP }) { x(); }
1009 if (do { ++$a; GLIPP }) { x(); }
1010 ####
1011 # TODO constant deparsing has been backed out for 5.12
1012 # tests for deparsing constants
1013 warn PI;
1014 ####
1015 # TODO constant deparsing has been backed out for 5.12
1016 # tests for deparsing imported constants
1017 warn O_TRUNC;
1018 ####
1019 # TODO constant deparsing has been backed out for 5.12
1020 # tests for deparsing re-exported constants
1021 warn O_CREAT;
1022 ####
1023 # TODO constant deparsing has been backed out for 5.12
1024 # tests for deparsing imported constants that got deleted from the original namespace
1025 warn O_APPEND;
1026 ####
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
1032 warn O_EXCL;
1033 eval '@Fcntl::O_EXCL = qw/affe tiger/;';
1034 warn O_EXCL;
1035 ####
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;
1039 ####
1040 # strict
1041 no strict;
1042 print $x;
1043 use strict 'vars';
1044 print $main::x;
1045 use strict 'subs';
1046 print $main::x;
1047 use strict 'refs';
1048 print $main::x;
1049 no strict 'vars';
1050 $x;
1051 ####
1052 # TODO Subsets of warnings could be encoded textually, rather than as bitflips.
1053 # subsets of warnings
1054 no warnings 'deprecated';
1055 my $x;
1056 ####
1057 # TODO Better test for CPAN #33708 - the deparsed code has different behaviour
1058 # CPAN #33708
1059 use strict;
1060 no warnings;
1061
1062 foreach (0..3) {
1063     my $x = 2;
1064     {
1065         my $x if 0;
1066         print ++$x, "\n";
1067     }
1068 }
1069 ####
1070 # no attribute list
1071 my $pi = 4;
1072 ####
1073 # SKIP ?$] > 5.013006 && ":= is now a syntax error"
1074 # := treated as an empty attribute list
1075 no warnings;
1076 my $pi := 4;
1077 >>>>
1078 no warnings;
1079 my $pi = 4;
1080 ####
1081 # : = empty attribute list
1082 my $pi : = 4;
1083 >>>>
1084 my $pi = 4;
1085 ####
1086 # in place sort
1087 our @a;
1088 my @b;
1089 @a = sort @a;
1090 @b = sort @b;
1091 ();
1092 ####
1093 # in place reverse
1094 our @a;
1095 my @b;
1096 @a = reverse @a;
1097 @b = reverse @b;
1098 ();
1099 ####
1100 # #71870 Use of uninitialized value in bitwise and B::Deparse
1101 my($r, $s, @a);
1102 @a = split(/foo/, $s, 0);
1103 $r = qr/foo/;
1104 @a = split(/$r/, $s, 0);
1105 ();
1106 ####
1107 # package declaration before label
1108 {
1109     package Foo;
1110     label: print 123;
1111 }
1112 ####
1113 # shift optimisation
1114 shift;
1115 >>>>
1116 shift();
1117 ####
1118 # shift optimisation
1119 shift @_;
1120 ####
1121 # shift optimisation
1122 pop;
1123 >>>>
1124 pop();
1125 ####
1126 # shift optimisation
1127 pop @_;
1128 ####
1129 #[perl #20444]
1130 "foo" =~ (1 ? /foo/ : /bar/);
1131 "foo" =~ (1 ? y/foo// : /bar/);
1132 "foo" =~ (1 ? y/foo//r : /bar/);
1133 "foo" =~ (1 ? s/foo// : /bar/);
1134 >>>>
1135 'foo' =~ ($_ =~ /foo/);
1136 'foo' =~ ($_ =~ tr/fo//);
1137 'foo' =~ ($_ =~ tr/fo//r);
1138 'foo' =~ ($_ =~ s/foo//);
1139 ####
1140 # The fix for [perl #20444] broke this.
1141 'foo' =~ do { () };
1142 ####
1143 # [perl #81424] match against aelemfast_lex
1144 my @s;
1145 print /$s[1]/;
1146 ####
1147 # /$#a/
1148 print /$#main::a/;
1149 ####
1150 # $lexical =~ //
1151 my $x;
1152 $x =~ //;
1153 ####
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;
1160 {
1161     use feature "unicode_strings";
1162     print /a/d, s/b/c/d;
1163 }
1164 {
1165     use re "/u";
1166     print /a/d, s/b/c/d;
1167 }
1168 {
1169     use 5.012;
1170     print /a/d, s/b/c/d;
1171 }
1172 >>>>
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;
1178 {
1179     use feature 'unicode_strings';
1180     print /a/d, s/b/c/d;
1181 }
1182 {
1183     BEGIN { $^H{'reflags'}         = '0';
1184             $^H{'reflags_charset'} = '2'; }
1185     print /a/d, s/b/c/d;
1186 }
1187 {
1188     no feature;
1189     use feature ':5.12';
1190     print /a/d, s/b/c/d;
1191 }
1192 ####
1193 # [perl #119807] s//\(3)/ge should not warn when deparsed (\3 warns)
1194 s/foo/\(3);/eg;
1195 ####
1196 # [perl #115256]
1197 "" =~ /a(?{ print q|
1198 |})/;
1199 >>>>
1200 '' =~ /a(?{ print "\n"; })/;
1201 ####
1202 # [perl #123217]
1203 $_ = qr/(??{<<END})/
1204 f.o
1205 b.r
1206 END
1207 >>>>
1208 $_ = qr/(??{ "f.o\nb.r\n"; })/;
1209 ####
1210 # More regexp code block madness
1211 my($b, @a);
1212 /(?{ die $b; })/;
1213 /a(?{ die $b; })a/;
1214 /$a(?{ die $b; })/;
1215 /@a(?{ die $b; })/;
1216 /(??{ die $b; })/;
1217 /a(??{ die $b; })a/;
1218 /$a(??{ die $b; })/;
1219 /@a(??{ die $b; })/;
1220 qr/(?{ 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; })/;
1228 s/(?{ 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; })//;
1236 ####
1237 # /(?x)<newline><tab>/
1238 /(?x)
1239         /;
1240 ####
1241 # y///r
1242 tr/a/b/r + $a =~ tr/p/q/r;
1243 ####
1244 # y///d in list [perl #119815]
1245 () = tr/a//d;
1246 ####
1247 # [perl #90898]
1248 <a,>;
1249 ####
1250 # [perl #91008]
1251 # CONTEXT no warnings 'experimental::autoderef';
1252 each $@;
1253 keys $~;
1254 values $!;
1255 ####
1256 # readpipe with complex expression
1257 readpipe $a + $b;
1258 ####
1259 # aelemfast
1260 $b::a[0] = 1;
1261 ####
1262 # aelemfast for a lexical
1263 my @a;
1264 $a[0] = 1;
1265 ####
1266 # feature features without feature
1267 # CONTEXT no warnings 'experimental::smartmatch';
1268 CORE::state $x;
1269 CORE::say $x;
1270 CORE::given ($x) {
1271     CORE::when (3) {
1272         continue;
1273     }
1274     CORE::default {
1275         CORE::break;
1276     }
1277 }
1278 CORE::evalbytes '';
1279 () = CORE::__SUB__;
1280 () = CORE::fc $x;
1281 ####
1282 # feature features when feature has been disabled by use VERSION
1283 # CONTEXT no warnings 'experimental::smartmatch';
1284 use feature (sprintf(":%vd", $^V));
1285 use 1;
1286 CORE::say $_;
1287 CORE::state $x;
1288 CORE::given ($x) {
1289     CORE::when (3) {
1290         continue;
1291     }
1292     CORE::default {
1293         CORE::break;
1294     }
1295 }
1296 CORE::evalbytes '';
1297 () = CORE::__SUB__;
1298 >>>>
1299 CORE::say $_;
1300 CORE::state $x;
1301 CORE::given ($x) {
1302     CORE::when (3) {
1303         continue;
1304     }
1305     CORE::default {
1306         CORE::break;
1307     }
1308 }
1309 CORE::evalbytes '';
1310 () = CORE::__SUB__;
1311 ####
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));
1316 use 1;
1317 CORE::say $_;
1318 CORE::state $x;
1319 CORE::given ($x) {
1320     CORE::when (3) {
1321         continue;
1322     }
1323     CORE::default {
1324         CORE::break;
1325     }
1326 }
1327 CORE::evalbytes '';
1328 () = CORE::__SUB__;
1329 >>>>
1330 no feature;
1331 use feature ':default';
1332 CORE::say $_;
1333 CORE::state $x;
1334 CORE::given ($x) {
1335     CORE::when (3) {
1336         continue;
1337     }
1338     CORE::default {
1339         CORE::break;
1340     }
1341 }
1342 CORE::evalbytes '';
1343 () = CORE::__SUB__;
1344 ####
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';
1348 my sub default;
1349 my sub else;
1350 my sub elsif;
1351 my sub for;
1352 my sub foreach;
1353 my sub given;
1354 my sub if;
1355 my sub m;
1356 my sub no;
1357 my sub package;
1358 my sub q;
1359 my sub qq;
1360 my sub qr;
1361 my sub qx;
1362 my sub require;
1363 my sub s;
1364 my sub sub;
1365 my sub tr;
1366 my sub unless;
1367 my sub until;
1368 my sub use;
1369 my sub when;
1370 my sub while;
1371 CORE::default { die; }
1372 CORE::if ($1) { die; }
1373 CORE::if ($1) { die; }
1374 CORE::elsif ($1) { die; }
1375 CORE::else { die; }
1376 CORE::for (die; $1; die) { die; }
1377 CORE::foreach $_ (1 .. 10) { die; }
1378 die CORE::foreach (1);
1379 CORE::given ($1) { die; }
1380 CORE::m[/];
1381 CORE::m?/?;
1382 CORE::package foo;
1383 CORE::no strict;
1384 () = (CORE::q['], CORE::qq["$_], CORE::qr//, CORE::qx[`]);
1385 CORE::require 1;
1386 CORE::s///;
1387 () = CORE::sub { die; } ;
1388 CORE::tr///;
1389 CORE::unless ($1) { die; }
1390 CORE::until ($1) { die; }
1391 die CORE::until $1;
1392 CORE::use strict;
1393 CORE::when ($1 ~~ $2) { die; }
1394 CORE::while ($1) { die; }
1395 die CORE::while $1;
1396 ####
1397 # Feature hints
1398 use feature 'current_sub', 'evalbytes';
1399 print;
1400 use 1;
1401 print;
1402 use 5.014;
1403 print;
1404 no feature 'unicode_strings';
1405 print;
1406 >>>>
1407 use feature 'current_sub', 'evalbytes';
1408 print $_;
1409 no feature;
1410 use feature ':default';
1411 print $_;
1412 no feature;
1413 use feature ':5.12';
1414 print $_;
1415 no feature 'unicode_strings';
1416 print $_;
1417 ####
1418 # $#- $#+ $#{%} etc.
1419 my @x;
1420 @x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
1421 @x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
1422 @x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
1423 @x = ($#{;}, $#{:});
1424 ####
1425 # ${#} interpolated
1426 # It's a known TODO that warnings are deparsed as bits, not textually.
1427 no warnings;
1428 () = "${#}a";
1429 ####
1430 # [perl #86060] $( $| $) in regexps need braces
1431 /${(}/;
1432 /${|}/;
1433 /${)}/;
1434 /${(}${|}${)}/;
1435 ####
1436 # ()[...]
1437 my(@a) = ()[()];
1438 ####
1439 # sort(foo(bar))
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'));
1444 >>>>
1445 print sort(foo('bar'));
1446 ####
1447 # substr assignment
1448 substr(my $a, 0, 0) = (foo(), bar());
1449 $a++;
1450 ####
1451 # This following line works around an unfixed bug that we are not trying to 
1452 # test for here:
1453 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1454 # hint hash
1455 BEGIN { $^H{'foo'} = undef; }
1456 {
1457  BEGIN { $^H{'bar'} = undef; }
1458  {
1459   BEGIN { $^H{'baz'} = undef; }
1460   {
1461    print $_;
1462   }
1463   print $_;
1464  }
1465  print $_;
1466 }
1467 BEGIN { $^H{q[']} = '('; }
1468 print $_;
1469 ####
1470 # This following line works around an unfixed bug that we are not trying to 
1471 # test for here:
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'; }
1475 {
1476  BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
1477  print $_;
1478 }
1479 print $_;
1480 ####
1481 # [perl #47361] do({}) and do +{} (variants of do-file)
1482 do({});
1483 do +{};
1484 sub foo::do {}
1485 package foo;
1486 CORE::do({});
1487 CORE::do +{};
1488 >>>>
1489 do({});
1490 do({});
1491 package foo;
1492 CORE::do({});
1493 CORE::do({});
1494 ####
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;
1502 () = (goto 1) + 3;
1503 () = (require 'foo') + 3;
1504 () = (require foo) + 3;
1505 () = (CORE::dump 1) + 3;
1506 () = (last 1) + 3;
1507 () = (next 1) + 3;
1508 () = (redo 1) + 3;
1509 () = (-R $_) + 3;
1510 () = (-W $_) + 3;
1511 () = (-X $_) + 3;
1512 () = (-r $_) + 3;
1513 () = (-w $_) + 3;
1514 () = (-x $_) + 3;
1515 ####
1516 # require(foo()) and do(foo())
1517 require (foo());
1518 do (foo());
1519 goto (foo());
1520 CORE::dump (foo());
1521 last (foo());
1522 next (foo());
1523 redo (foo());
1524 ####
1525 # [perl #97476] not() *does* follow the llafr
1526 $_ = ($a xor not +($1 || 2) ** 2);
1527 ####
1528 # Precedence conundrums with argument-less function calls
1529 () = (eof) + 1;
1530 () = (return) + 1;
1531 () = (return, 1);
1532 () = warn;
1533 () = warn() + 1;
1534 () = setpgrp() + 1;
1535 ####
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';
1542 ####
1543 # [perl #63558] open local(*FH)
1544 open local *FH;
1545 pipe local *FH, local *FH;
1546 ####
1547 # [perl #91416] open "string"
1548 open 'open';
1549 open '####';
1550 open '^A';
1551 open "\ca";
1552 >>>>
1553 open *open;
1554 open '####';
1555 open '^A';
1556 open *^A;
1557 ####
1558 # "string"->[] ->{}
1559 no strict 'vars';
1560 () = 'open'->[0]; #aelemfast
1561 () = '####'->[0];
1562 () = '^A'->[0];
1563 () = "\ca"->[0];
1564 () = 'a::]b'->[0];
1565 () = 'open'->[$_]; #aelem
1566 () = '####'->[$_];
1567 () = '^A'->[$_];
1568 () = "\ca"->[$_];
1569 () = 'a::]b'->[$_];
1570 () = 'open'->{0}; #helem
1571 () = '####'->{0};
1572 () = '^A'->{0};
1573 () = "\ca"->{0};
1574 () = 'a::]b'->{0};
1575 >>>>
1576 no strict 'vars';
1577 () = $open[0];
1578 () = '####'->[0];
1579 () = '^A'->[0];
1580 () = $^A[0];
1581 () = 'a::]b'->[0];
1582 () = $open[$_];
1583 () = '####'->[$_];
1584 () = '^A'->[$_];
1585 () = $^A[$_];
1586 () = 'a::]b'->[$_];
1587 () = $open{'0'};
1588 () = '####'->{'0'};
1589 () = '^A'->{'0'};
1590 () = $^A{'0'};
1591 () = 'a::]b'->{'0'};
1592 ####
1593 # [perl #74740] -(f()) vs -f()
1594 $_ = -(f());
1595 ####
1596 # require <binop>
1597 require 'a' . $1;
1598 ####
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' }
1603 >>>>
1604 $_ = 'foo' foreach (my($foo1, $bar1, $baz1));
1605 foreach $_ (my($foo2, $bar2, $baz2)) {
1606     $_ = 'foo';
1607 }
1608 foreach my $i (my($foo3, $bar3, $baz3)) {
1609     $i = 'foo';
1610 }
1611 ####
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 { }
1617 >>>>
1618 foreach $_ (1 .. 3) {
1619     print $_;
1620 }
1621 continue {
1622     print "\n";
1623 }
1624 foreach $_ (1 .. 3) {
1625     ();
1626 }
1627 continue {
1628     ();
1629 }
1630 foreach my $i (1 .. 3) {
1631     print $i;
1632 }
1633 continue {
1634     print "\n";
1635 }
1636 foreach my $i (1 .. 3) {
1637     ();
1638 }
1639 continue {
1640     ();
1641 }
1642 ####
1643 # file handles
1644 no strict;
1645 my $mfh;
1646 open F;
1647 open *F;
1648 open $fh;
1649 open $mfh;
1650 open 'a+b';
1651 select *F;
1652 select F;
1653 select $f;
1654 select $mfh;
1655 select 'a+b';
1656 ####
1657 # 'my' works with padrange op
1658 my($z, @z);
1659 my $m1;
1660 $m1 = 1;
1661 $z = $m1;
1662 my $m2 = 2;
1663 my($m3, $m4);
1664 ($m3, $m4) = (1, 2);
1665 @z = ($m3, $m4);
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);
1670 ####
1671 # 'our/local' works with padrange op
1672 our($z, @z);
1673 our $o1;
1674 no strict;
1675 local $o11;
1676 $o1 = 1;
1677 local $o1 = 1;
1678 $z = $o1;
1679 $z = local $o1;
1680 our $o2 = 2;
1681 our($o3, $o4);
1682 ($o3, $o4) = (1, 2);
1683 local($o3, $o4) = (1, 2);
1684 @z = ($o3, $o4);
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);
1692 ####
1693 # 'state' works with padrange op
1694 # CONTEXT no strict; use feature 'state';
1695 state($z, @z);
1696 state $s1;
1697 $s1 = 1;
1698 $z = $s1;
1699 state $s2 = 2;
1700 state($s3, $s4);
1701 ($s3, $s4) = (1, 2);
1702 @z = ($s3, $s4);
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);
1708 ####
1709 # anon arrays with padrange
1710 my($a, $b);
1711 my $c = [$a, $b];
1712 my $d = {$a, $b};
1713 ####
1714 # slices with padrange
1715 my($a, $b);
1716 my(@x, %y);
1717 @x = @x[$a, $b];
1718 @x = @y{$a, $b};
1719 ####
1720 # binops with padrange
1721 my($a, $b, $c);
1722 $c = $a cmp $b;
1723 $c = $a + $b;
1724 $a += $b;
1725 $c = $a - $b;
1726 $a -= $b;
1727 $c = my $a1 cmp $b;
1728 $c = my $a2 + $b;
1729 $a += my $b1;
1730 $c = my $a3 - $b;
1731 $a -= my $b2;
1732 ####
1733 # 'x' with padrange
1734 my($a, $b, $c, $d, @e);
1735 $c = $a x $b;
1736 $a x= $b;
1737 @e = ($a) x $d;
1738 @e = ($a, $b) x $d;
1739 @e = ($a, $b, $c) x $d;
1740 @e = ($a, 1) x $d;
1741 ####
1742 # @_ with padrange
1743 my($a, $b, $c) = @_;
1744 ####
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";
1749 my sub f {}
1750 print f();
1751 >>>>
1752 use feature 'lexical_subs';
1753 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUUU\005"}
1754 my sub f {
1755     BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUU\005"}
1756     
1757 }
1758 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUU\005"}
1759 print f();
1760 ####
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';
1765 state sub f {}
1766 print f();
1767 >>>>
1768 use feature 'lexical_subs';
1769 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUUU\005"}
1770 CORE::state sub f {
1771     BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUU\005"}
1772     use feature 'state';
1773     
1774 }
1775 BEGIN {${^WARNING_BITS} = "TUUUUUUUUUUUUTUU\005"}
1776 use feature 'state';
1777 print f();
1778 ####
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';
1782 {
1783   {
1784     my sub a { die; }
1785     {
1786       foo();
1787       my sub b;
1788       b();
1789       main::b();
1790       &main::b;
1791       &main::b();
1792       my $b = \&main::b;
1793       sub b { $b; }
1794     }
1795   }
1796   b();
1797 }
1798 ####
1799 # Elements of %# should not be confused with $#{ array }
1800 () = ${#}{'foo'};
1801 ####
1802 # $; [perl #12335]
1803 $_ = $;;
1804 do {
1805     $;
1806 };
1807 ####
1808 # [perl #121050] Prototypes with whitespace
1809 sub _121050(\$ \$) { }
1810 _121050($a,$b);
1811 sub _121050empty( ) {}
1812 () = _121050empty() + 1;
1813 >>>>
1814 _121050 $a, $b;
1815 () = _121050empty + 1;
1816 ####
1817 # Ampersand calls and scalar context
1818 # OPTIONS -P
1819 package prototest;
1820 sub foo($$);
1821 foo(bar(),baz());
1822 >>>>
1823 package prototest;
1824 &foo(scalar bar(), scalar baz());
1825 ####
1826 # ensure aelemfast works in the range -128..127 and that there's no
1827 # funky edge cases
1828 my $x;
1829 no strict 'vars';
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];
1832 my @b;
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];
1835 ####
1836 # 'm' must be preserved in m??
1837 m??;
1838 ####
1839 # \(@array) and \(..., (@array), ...)
1840 my(@array, %hash, @a, @b, %c, %d);
1841 () = \(@array);
1842 () = \(%hash);
1843 () = \(@a, (@b), (%c), %d);
1844 () = \(@Foo::array);
1845 () = \(%Foo::hash);
1846 () = \(@Foo::a, (@Foo::b), (%Foo::c), %Foo::d);
1847 ####
1848 # subs synonymous with keywords
1849 main::our();
1850 main::pop();
1851 state();
1852 use feature 'state';
1853 main::state();
1854 ####
1855 # lvalue references
1856 # CONTEXT use feature "state", 'refaliasing', 'lexical_subs'; no warnings 'experimental';
1857 our $x;
1858 \$x = \$x;
1859 my $m;
1860 \$m = \$x;
1861 \my $n = \$x;
1862 (\$x) = @_;
1863 \($x) = @_;
1864 \($m) = @_;
1865 (\$m) = @_;
1866 \my($p) = @_;
1867 (\my $r) = @_;
1868 \($x, my $a) = @{[\$x, \$x]};
1869 (\$x, \my $b) = @{[\$x, \$x]};
1870 \local $x = \3;
1871 \local($x) = \3;
1872 \state $c = \3;
1873 \state($d) = \3;
1874 \our $e = \3;
1875 \our($f) = \3;
1876 \$_[0] = foo();
1877 \($_[1]) = foo();
1878 my @a;
1879 \$a[0] = foo();
1880 \($a[1]) = foo();
1881 \local($a[1]) = foo();
1882 \@a[0,1] = foo();
1883 \(@a[2,3]) = foo();
1884 \local @a[0,1] = (\$a)x2;
1885 \$_{a} = foo();
1886 \($_{b}) = foo();
1887 my %h;
1888 \$h{a} = foo();
1889 \($h{b}) = foo();
1890 \local $h{a} = \$x;
1891 \local($h{b}) = \$x;
1892 \@h{'a','b'} = foo();
1893 \(@h{2,3}) = foo();
1894 \local @h{'a','b'} = (\$x)x2;
1895 \@_ = foo();
1896 \@a = foo();
1897 (\@_) = foo();
1898 (\@a) = foo();
1899 \my @c = foo();
1900 (\my @d) = foo();
1901 \(@_) = foo();
1902 \(@a) = foo();
1903 \my(@g) = foo();
1904 \local @_ = \@_;
1905 (\local @_) = \@_;
1906 \state @e = [1..3];
1907 \state(@f) = \3;
1908 \our @i = [1..3];
1909 \our(@h) = \3;
1910 \%_ = foo();
1911 \%h = foo();
1912 (\%_) = foo();
1913 (\%h) = foo();
1914 \my %c = foo();
1915 (\my %d) = foo();
1916 \local %_ = \%h;
1917 (\local %_) = \%h;
1918 \state %y = {1,2};
1919 \our %z = {1,2};
1920 (\our %zz) = {1,2};
1921 \&a = foo();
1922 (\&a) = foo();
1923 \(&a) = foo();
1924 {
1925   my sub a;
1926   \&a = foo();
1927   (\&a) = foo();
1928   \(&a) = foo();
1929 }
1930 (\$_, $_) = \(1, 2);
1931 $_ == 3 ? \$_ : $_ = \3;
1932 $_ == 3 ? \$_ : \$x = \3;
1933 \($_ == 3 ? $_ : $x) = \3;
1934 for \my $topic (\$1, \$2) {
1935     die;
1936 }
1937 for \state $topic (\$1, \$2) {
1938     die;
1939 }
1940 for \our $topic (\$1, \$2) {
1941     die;
1942 }
1943 for \$_ (\$1, \$2) {
1944     die;
1945 }
1946 for \my @a ([1,2], [3,4]) {
1947     die;
1948 }
1949 for \state @a ([1,2], [3,4]) {
1950     die;
1951 }
1952 for \our @a ([1,2], [3,4]) {
1953     die;
1954 }
1955 for \@_ ([1,2], [3,4]) {
1956     die;
1957 }
1958 for \my %a ({5,6}, {7,8}) {
1959     die;
1960 }
1961 for \our %a ({5,6}, {7,8}) {
1962     die;
1963 }
1964 for \state %a ({5,6}, {7,8}) {
1965     die;
1966 }
1967 for \%_ ({5,6}, {7,8}) {
1968     die;
1969 }
1970 {
1971     my sub a;
1972     for \&a (sub { 9; }, sub { 10; }) {
1973         die;
1974     }
1975 }
1976 for \&a (sub { 9; }, sub { 10; }) {
1977     die;
1978 }
1979 >>>>
1980 our $x;
1981 \$x = \$x;
1982 my $m;
1983 \$m = \$x;
1984 \my $n = \$x;
1985 (\$x) = @_;
1986 (\$x) = @_;
1987 (\$m) = @_;
1988 (\$m) = @_;
1989 (\my $p) = @_;
1990 (\my $r) = @_;
1991 (\$x, \my $a) = @{[\$x, \$x];};
1992 (\$x, \my $b) = @{[\$x, \$x];};
1993 \local $x = \3;
1994 (\local $x) = \3;
1995 \state $c = \3;
1996 (\state $d) = \3;
1997 \our $e = \3;
1998 (\our $f) = \3;
1999 \$_[0] = foo();
2000 (\$_[1]) = foo();
2001 my @a;
2002 \$a[0] = foo();
2003 (\$a[1]) = foo();
2004 (\local $a[1]) = foo();
2005 (\@a[0, 1]) = foo();
2006 (\@a[2, 3]) = foo();
2007 (\local @a[0, 1]) = (\$a) x 2;
2008 \$_{'a'} = foo();
2009 (\$_{'b'}) = foo();
2010 my %h;
2011 \$h{'a'} = foo();
2012 (\$h{'b'}) = foo();
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;
2018 \@_ = foo();
2019 \@a = foo();
2020 (\@_) = foo();
2021 (\@a) = foo();
2022 \my @c = foo();
2023 (\my @d) = foo();
2024 (\(@_)) = foo();
2025 (\(@a)) = foo();
2026 (\(my @g)) = foo();
2027 \local @_ = \@_;
2028 (\local @_) = \@_;
2029 \state @e = [1..3];
2030 (\(state @f)) = \3;
2031 \our @i = [1..3];
2032 (\(our @h)) = \3;
2033 \%_ = foo();
2034 \%h = foo();
2035 (\%_) = foo();
2036 (\%h) = foo();
2037 \my %c = foo();
2038 (\my %d) = foo();
2039 \local %_ = \%h;
2040 (\local %_) = \%h;
2041 \state %y = {1, 2};
2042 \our %z = {1, 2};
2043 (\our %zz) = {1, 2};
2044 \&a = foo();
2045 (\&a) = foo();
2046 (\&a) = foo();
2047 {
2048   my sub a;
2049   \&a = foo();
2050   (\&a) = foo();
2051   (\&a) = foo();
2052 }
2053 (\$_, $_) = \(1, 2);
2054 $_ == 3 ? \$_ : $_ = \3;
2055 $_ == 3 ? \$_ : \$x = \3;
2056 ($_ == 3 ? \$_ : \$x) = \3;
2057 foreach \my $topic (\$1, \$2) {
2058     die;
2059 }
2060 foreach \state $topic (\$1, \$2) {
2061     die;
2062 }
2063 foreach \our $topic (\$1, \$2) {
2064     die;
2065 }
2066 foreach \$_ (\$1, \$2) {
2067     die;
2068 }
2069 foreach \my @a ([1, 2], [3, 4]) {
2070     die;
2071 }
2072 foreach \state @a ([1, 2], [3, 4]) {
2073     die;
2074 }
2075 foreach \our @a ([1, 2], [3, 4]) {
2076     die;
2077 }
2078 foreach \@_ ([1, 2], [3, 4]) {
2079     die;
2080 }
2081 foreach \my %a ({5, 6}, {7, 8}) {
2082     die;
2083 }
2084 foreach \our %a ({5, 6}, {7, 8}) {
2085     die;
2086 }
2087 foreach \state %a ({5, 6}, {7, 8}) {
2088     die;
2089 }
2090 foreach \%_ ({5, 6}, {7, 8}) {
2091     die;
2092 }
2093 {
2094     my sub a;
2095     foreach \&a (sub { 9; } , sub { 10; } ) {
2096         die;
2097     }
2098 }
2099 foreach \&a (sub { 9; } , sub { 10; } ) {
2100     die;
2101 }
2102 ####
2103 # join $foo, pos
2104 my $foo;
2105 $_ = join $foo, pos
2106 >>>>
2107 my $foo;
2108 $_ = join('???', pos $_);
2109 ####
2110 # exists $a[0]
2111 our @a;
2112 exists $a[0];
2113 ####
2114 # my @a; exists $a[0]
2115 my @a;
2116 exists $a[0];
2117 ####
2118 # delete $a[0]
2119 our @a;
2120 delete $a[0];
2121 ####
2122 # my @a; delete $a[0]
2123 my @a;
2124 delete $a[0];
2125 ####
2126 # $_[0][$_[1]]
2127 $_[0][$_[1]];
2128 ####
2129 # f($a[0]);
2130 my @a;
2131 f($a[0]);
2132 ####
2133 #qr/\Q$h{'key'}\E/;
2134 my %h;
2135 qr/\Q$h{'key'}\E/;
2136 ####
2137 # my $x = "$h{foo}";
2138 my %h;
2139 my $x = "$h{'foo'}";
2140 ####
2141 # weird constant hash key
2142 my %h;
2143 my $x = $h{"\000\t\x{100}"};
2144 ####
2145 # multideref and packages
2146 package foo;
2147 my(%bar) = ('a', 'b');
2148 our(@bar) = (1, 2);
2149 $bar{'k'} = $bar[200];
2150 $main::bar{'k'} = $main::bar[200];
2151 $foo::bar{'k'} = $foo::bar[200];
2152 package foo2;
2153 $bar{'k'} = $bar[200];
2154 $main::bar{'k'} = $main::bar[200];
2155 $foo::bar{'k'} = $foo::bar[200];
2156 >>>>
2157 package foo;
2158 my(%bar) = ('a', 'b');
2159 our(@bar) = (1, 2);
2160 $bar{'k'} = $bar[200];
2161 $main::bar{'k'} = $main::bar[200];
2162 $foo::bar{'k'} = $bar[200];
2163 package foo2;
2164 $bar{'k'} = $foo::bar[200];
2165 $main::bar{'k'} = $main::bar[200];
2166 $foo::bar{'k'} = $foo::bar[200];
2167 ####
2168 # multideref and local
2169 my %h;
2170 local $h{'foo'}[0] = 1;
2171 ####
2172 # multideref and exists
2173 my(%h, $i);
2174 my $e = exists $h{'foo'}[$i];
2175 ####
2176 # multideref and delete
2177 my(%h, $i);
2178 my $e = delete $h{'foo'}[$i];
2179 ####
2180 # multideref with leading expression
2181 my $r;
2182 my $x = ($r // [])->{'foo'}[0];
2183 ####
2184 # multideref with complex middle index
2185 my(%h, $i, $j, $k);
2186 my $x = $h{'foo'}[$i + $j]{$k};