This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Let Deparse.t be run from the top-level
[perl5.git] / lib / B / Deparse.t
1 #!./perl
2
3 BEGIN {
4     splice @INC, 0, 0, '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 = 46; # 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 $code = "$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     my $coderef = eval $code;
79
80     local $::TODO = $meta{todo};
81     if ($@) {
82         is($@, "", "compilation of $desc")
83             or diag "=============================================\n"
84                   . "CODE:\n--------\n$code\n--------\n"
85                   . "=============================================\n";
86     }
87     else {
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*\}$';
93
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";
100     }
101 }
102
103 # Reset the ambient pragmas
104 {
105     my ($b, $w, $h);
106     BEGIN {
107         ($b, $w, $h) = ($^H, ${^WARNING_BITS}, \%^H);
108     }
109     $deparse->ambient_pragmas (
110         hint_bits    => $b,
111         warning_bits => $w,
112         '%^H'        => $h,
113     );
114 }
115
116 use constant 'c', 'stuff';
117 is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
118    'the subroutine generated by use constant deparses');
119
120 my $a = 0;
121 is($deparse->coderef2text(sub{(-1) ** $a }), "{\n    (-1) ** \$a;\n}",
122    'anon sub capturing an external lexical');
123
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');
129
130 my $path = join " ", map { qq["-I$_"] } @INC;
131
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"; }
138 BEGIN { $^W = 1; }
139 BEGIN { $/ = "\n"; $\ = "\n"; }
140 LINE: while (defined($_ = readline ARGV)) {
141     chomp $_;
142     our(@F) = split(' ', $_, 0);
143     '???';
144 }
145 EOF
146 $b =~ s/our\\\(\\\@F\\\)/our[( ]\@F\\)?/; # accept both our @F and our(@F)
147 like($a, qr/$b/,
148    'command line flags deparse as BEGIN blocks setting control variables');
149
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");
154
155 #Re: perlbug #35857, patch #24505
156 #handle warnings::register-ed packages properly.
157 package B::Deparse::Wrapper;
158 use strict;
159 use warnings;
160 use warnings::register;
161 sub getcode {
162    my $deparser = B::Deparse->new();
163    return $deparser->coderef2text(shift);
164 }
165
166 package Moo;
167 use overload '0+' => sub { 42 };
168
169 package main;
170 use strict;
171 use warnings;
172 use constant GLIPP => 'glipp';
173 use constant PI => 4;
174 use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
175 use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
176 BEGIN { delete $::Fcntl::{O_APPEND}; }
177 use POSIX qw/O_CREAT/;
178 sub test {
179    my $val = shift;
180    my $res = B::Deparse::Wrapper::getcode($val);
181    like($res, qr/use warnings/,
182         '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
183 }
184 my ($q,$p);
185 my $x=sub { ++$q,++$p };
186 test($x);
187 eval <<EOFCODE and test($x);
188    package bar;
189    use strict;
190    use warnings;
191    use warnings::register;
192    package main;
193    1
194 EOFCODE
195
196 # Exotic sub declarations
197 $a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
198 $a =~ s/-e syntax OK\n//g;
199 is($a, <<'EOCODG', "sub :::: and sub ::::::");
200 sub :::: {
201     
202 }
203 sub :::::: {
204     
205 }
206 EOCODG
207
208 # [perl #117311]
209 $a = `$^X $path "-MO=Deparse,-l" -e "map{ eval(0) }()" 2>&1`;
210 $a =~ s/-e syntax OK\n//g;
211 is($a, <<'EOCODH', "[perl #117311] [PATCH] -l option ('#line ...') does not emit ^Ls in the output");
212 #line 1 "-e"
213 map {
214 #line 1 "-e"
215 eval 0;} ();
216 EOCODH
217
218 # [perl #33752]
219 {
220   my $code = <<"EOCODE";
221 {
222     our \$\x{1e1f}\x{14d}\x{14d};
223 }
224 EOCODE
225   my $deparsed
226    = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
227   s/$ \n//x for $deparsed, $code;
228   is $deparsed, $code, 'our $funny_Unicode_chars';
229 }
230
231 # [perl #62500]
232 $a =
233   `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
234 $a =~ s/-e syntax OK\n//g;
235 is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
236 sub BEGIN {
237     *CORE::GLOBAL::require = sub {
238         1;
239     }
240     ;
241 }
242 EOCODF
243
244 # [perl #91384]
245 $a =
246   `$^X $path "-MO=Deparse" -e "BEGIN{*Acme::Acme:: = *Acme::}" 2>&1`;
247 like($a, qr/-e syntax OK/,
248     "Deparse does not hang when traversing stash circularities");
249
250 # [perl #93990]
251 @] = ();
252 is($deparse->coderef2text(sub{ print "foo@{]}" }),
253 q<{
254     print "foo@{]}";
255 }>, 'curly around to interpolate "@{]}"');
256 is($deparse->coderef2text(sub{ print "foo@{-}" }),
257 q<{
258     print "foo@-";
259 }>, 'no need to curly around to interpolate "@-"');
260
261 # Strict hints in %^H are mercilessly suppressed
262 $a =
263   `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
264 unlike($a, qr/BEGIN/,
265     "Deparse does not emit strict hh hints");
266
267 # ambient_pragmas should not mess with strict settings.
268 SKIP: {
269     skip "requires 5.11", 1 unless $] >= 5.011;
270     eval q`
271         BEGIN {
272             # Clear out all hints
273             %^H = ();
274             $^H = 0;
275             new B::Deparse -> ambient_pragmas(strict => 'all');
276         }
277         use 5.011;  # should enable strict
278         ok !eval '$do_noT_create_a_variable_with_this_name = 1',
279           'ambient_pragmas do not mess with compiling scope';
280    `;
281 }
282
283 # multiple statements on format lines
284 $a = `$^X $path "-MO=Deparse" -e "format =" -e "\@" -e "x();z()" -e. 2>&1`;
285 $a =~ s/-e syntax OK\n//g;
286 is($a, <<'EOCODH', 'multiple statements on format lines');
287 format STDOUT =
288 @
289 x(); z()
290 .
291 EOCODH
292
293 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
294            prog => "format =\n\@\n\$;\n.\n"),
295    <<'EOCODM', '$; on format line';
296 format STDOUT =
297 @
298 $;
299 .
300 EOCODM
301
302 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse,-l', $path ],
303            prog => "format =\n\@\n\$foo\n.\n"),
304    <<'EOCODM', 'formats with -l';
305 format STDOUT =
306 @
307 $foo
308 .
309 EOCODM
310
311 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
312            prog => "{ my \$x; format =\n\@\n\$x\n.\n}"),
313    <<'EOCODN', 'formats nested inside blocks';
314 {
315     my $x;
316     format STDOUT =
317 @
318 $x
319 .
320 }
321 EOCODN
322
323 # CORE::format
324 $a = readpipe qq`$^X $path "-MO=Deparse" -e "use feature q|:all|;`
325              .qq` my sub format; CORE::format =" -e. 2>&1`;
326 like($a, qr/CORE::format/, 'CORE::format when lex format sub is in scope');
327
328 # literal big chars under 'use utf8'
329 is($deparse->coderef2text(sub{ use utf8; /€/; }),
330 '{
331     /\x{20ac}/;
332 }',
333 "qr/euro/");
334
335 # STDERR when deparsing sub calls
336 # For a short while the output included 'While deparsing'
337 $a = `$^X $path "-MO=Deparse" -e "foo()" 2>&1`;
338 $a =~ s/-e syntax OK\n//g;
339 is($a, <<'EOCODI', 'no extra output when deparsing foo()');
340 foo();
341 EOCODI
342
343 # Sub calls compiled before importation
344 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
345              prog => 'BEGIN {
346                        require Test::More;
347                        Test::More::->import;
348                        is(*foo, *foo)
349                      }'),
350      qr/&is\(/,
351     'sub calls compiled before importation of prototype subs';
352
353 # [perl #121050] Prototypes with whitespace
354 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
355            prog => <<'EOCODO'),
356 sub _121050(\$ \$) { }
357 _121050($a,$b);
358 sub _121050empty( ) {}
359 () = _121050empty() + 1;
360 EOCODO
361    <<'EOCODP', '[perl #121050] prototypes with whitespace';
362 sub _121050 (\$ \$) {
363     
364 }
365 _121050 $a, $b;
366 sub _121050empty ( ) {
367     
368 }
369 () = _121050empty + 1;
370 EOCODP
371
372 # CORE::no
373 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
374              .qq`"use feature q|:all|; my sub no; CORE::no less" 2>&1`;
375 like($a, qr/my sub no;\n.*CORE::no less;/s,
376     'CORE::no after my sub no');
377
378 # CORE::use
379 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
380              .qq`"use feature q|:all|; my sub use; CORE::use less" 2>&1`;
381 like($a, qr/my sub use;\n.*CORE::use less;/s,
382     'CORE::use after my sub use');
383
384 # CORE::__DATA__
385 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
386              .qq`"use feature q|:all|; my sub __DATA__; `
387              .qq`CORE::__DATA__" 2>&1`;
388 like($a, qr/my sub __DATA__;\n.*CORE::__DATA__/s,
389     'CORE::__DATA__ after my sub __DATA__');
390
391 # sub declarations
392 $a = readpipe qq`$^X $path "-MO=Deparse" -e "sub foo{}" 2>&1`;
393 like($a, qr/sub foo\s*\{\s+\}/, 'sub declarations');
394 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
395            prog => 'sub f($); sub f($){}'),
396      qr/sub f\s*\(\$\)\s*\{\s*\}/,
397     'predeclared prototyped subs';
398 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
399            prog => 'use Scalar::Util q-weaken-;
400                     sub f($);
401                     BEGIN { weaken($_=\$::{f}) }'),
402      qr/sub f\s*\(\$\)\s*;/,
403     'prototyped stub with weak reference to the stash entry';
404 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
405            prog => 'sub f () { 42 }'),
406      qr/sub f\s*\(\)\s*\{\s*42;\s*\}/,
407     'constant perl sub declaration';
408
409 # BEGIN blocks
410 SKIP : {
411     skip "BEGIN output is wrong on old perls", 1 if $] < 5.021006;
412     my $prog = '
413       BEGIN { pop }
414       {
415         BEGIN { pop }
416         {
417           no overloading;
418           {
419             BEGIN { pop }
420             die
421           }
422         }
423       }';
424     $prog =~ s/\n//g;
425     $a = readpipe qq`$^X $path "-MO=Deparse" -e "$prog" 2>&1`;
426     $a =~ s/-e syntax OK\n//g;
427     is($a, <<'EOCODJ', 'BEGIN blocks');
428 sub BEGIN {
429     pop @ARGV;
430 }
431 {
432     sub BEGIN {
433         pop @ARGV;
434     }
435     {
436         no overloading;
437         {
438             sub BEGIN {
439                 pop @ARGV;
440             }
441             die;
442         }
443     }
444 }
445 EOCODJ
446 }
447 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ], prog => '
448       {
449         {
450           die;
451           BEGIN { pop }
452         }
453         BEGIN { pop }
454       }
455       BEGIN { pop }
456   '), <<'EOCODL', 'BEGIN blocks at the end of their enclosing blocks';
457 {
458     {
459         die;
460         sub BEGIN {
461             pop @ARGV;
462         }
463     }
464     sub BEGIN {
465         pop @ARGV;
466     }
467 }
468 sub BEGIN {
469     pop @ARGV;
470 }
471 EOCODL
472
473 # BEGIN blocks should not be called __ANON__
474 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
475              prog => 'sub BEGIN { } CHECK { delete $::{BEGIN} }'),
476      qr/sub BEGIN/, 'anonymised BEGIN';
477
478 # [perl #115066]
479 my $prog = 'use constant FOO => do { 1 }; no overloading; die';
480 $a = readpipe qq`$^X $path "-MO=-qq,Deparse" -e "$prog" 2>&1`;
481 is($a, <<'EOCODK', '[perl #115066] use statements accidentally nested');
482 use constant ('FOO', do {
483     1
484 });
485 no overloading;
486 die;
487 EOCODK
488
489 # BEGIN blocks inside predeclared subs
490 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
491              prog => '
492                  sub run_tests;
493                  run_tests();
494                  sub run_tests { BEGIN { } die }'),
495      qr/sub run_tests \{\s*sub BEGIN/,
496     'BEGIN block inside predeclared sub';
497
498 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
499              prog => 'package foo; use overload qr=>sub{}'),
500      qr/package foo;\s*use overload/,
501     'package, then use';
502
503 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
504              prog => 'use feature lexical_subs=>; my sub f;sub main::f{}'),
505      qr/^sub main::f \{/m,
506     'sub decl when lex sub is in scope';
507
508 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
509              prog => 'sub foo{foo()}'),
510      qr/^sub foo \{\s+foo\(\)/m,
511     'recursive sub';
512
513 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
514              prog => 'use feature lexical_subs=>state=>;
515                       state sub sb5; sub { sub sb5 { } }'),
516      qr/sub \{\s*\(\);\s*sub sb5 \{/m,
517     'state sub in anon sub but declared outside';
518
519 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
520              prog => 'BEGIN { $::{f}=\!0 }'),
521    "sub BEGIN {\n    \$main::{'f'} = \\1;\n}\n",
522    '&PL_sv_yes constant (used to croak)';
523
524 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
525            prog => '$x =~ (1?/$a/:0)'),
526   '$x =~ ($_ =~ /$a/);'."\n",
527   '$foo =~ <branch-folded match> under taint mode';
528
529 unlike runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-w' ],
530                prog => 'BEGIN { undef &foo }'),
531        qr'Use of uninitialized value',
532       'no warnings for undefined sub';
533
534 done_testing($tests);
535
536 __DATA__
537 # TODO [perl #120950] This succeeds when run a 2nd time
538 # y/uni/code/
539 tr/\x{345}/\x{370}/;
540 ####
541 # y/uni/code/  [perl #120950] This 2nd instance succeeds
542 tr/\x{345}/\x{370}/;
543 ####
544 # A constant
545 1;
546 ####
547 # Constants in a block
548 # CONTEXT no warnings;
549 {
550     '???';
551     2;
552 }
553 ####
554 # List of constants in void context
555 # CONTEXT no warnings;
556 (1,2,3);
557 0;
558 >>>>
559 '???', '???', '???';
560 0;
561 ####
562 # Lexical and simple arithmetic
563 my $test;
564 ++$test and $test /= 2;
565 >>>>
566 my $test;
567 $test /= 2 if ++$test;
568 ####
569 # list x
570 -((1, 2) x 2);
571 ####
572 # Assignment to list x
573 ((undef) x 3) = undef;
574 ####
575 # lvalue sub
576 {
577     my $test = sub : lvalue {
578         my $x;
579     }
580     ;
581 }
582 ####
583 # method
584 {
585     my $test = sub : method {
586         my $x;
587     }
588     ;
589 }
590 ####
591 # anonsub attrs at statement start
592 my $x = do { +sub : lvalue { my $y; } };
593 my $z = do { foo: +sub : method { my $a; } };
594 ####
595 # block with continue
596 {
597     234;
598 }
599 continue {
600     123;
601 }
602 ####
603 # lexical and package scalars
604 my $x;
605 print $main::x;
606 ####
607 # lexical and package arrays
608 my @x;
609 print $main::x[1];
610 print \my @a;
611 ####
612 # lexical and package hashes
613 my %x;
614 $x{warn()};
615 ####
616 # our (LIST)
617 our($foo, $bar, $baz);
618 ####
619 # CONTEXT { package Dog } use feature "state";
620 # variables with declared classes
621 my Dog $spot;
622 our Dog $spotty;
623 state Dog $spotted;
624 my Dog @spot;
625 our Dog @spotty;
626 state Dog @spotted;
627 my Dog %spot;
628 our Dog %spotty;
629 state Dog %spotted;
630 my Dog ($foo, @bar, %baz);
631 our Dog ($phoo, @barr, %bazz);
632 state Dog ($fough, @barre, %bazze);
633 ####
634 # local our
635 local our $rhubarb;
636 local our($rhu, $barb);
637 ####
638 # <>
639 my $foo;
640 $_ .= <> . <ARGV> . <$foo>;
641 <$foo>;
642 <${foo}>;
643 <$ foo>;
644 >>>>
645 my $foo;
646 $_ .= readline(ARGV) . readline(ARGV) . readline($foo);
647 readline $foo;
648 glob $foo;
649 glob $foo;
650 ####
651 # readline
652 readline 'FH';
653 readline *$_;
654 readline *{$_};
655 readline ${"a"};
656 >>>>
657 readline 'FH';
658 readline *$_;
659 readline *{$_;};
660 readline ${'a';};
661 ####
662 # <<>>
663 $_ = <<>>;
664 ####
665 # \x{}
666 my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
667 my $bar = "\x{100}";
668 ####
669 # Latin-1 chars
670 # TODO ? ord("A") != 65 && "EBCDIC"
671 my $baz = "B\366\x{100}";
672 my $bba = qr/B\366\x{100}/;
673 ####
674 # s///e
675 s/x/'y';/e;
676 s/x/$a;/e;
677 s/x/complex_expression();/e;
678 ####
679 # block
680 { my $x; }
681 ####
682 # while 1
683 while (1) { my $k; }
684 ####
685 # trailing for
686 my ($x,@a);
687 $x=1 for @a;
688 >>>>
689 my($x, @a);
690 $x = 1 foreach (@a);
691 ####
692 # 2 arguments in a 3 argument for
693 for (my $i = 0; $i < 2;) {
694     my $z = 1;
695 }
696 ####
697 # 3 argument for
698 for (my $i = 0; $i < 2; ++$i) {
699     my $z = 1;
700 }
701 ####
702 # 3 argument for again
703 for (my $i = 0; $i < 2; ++$i) {
704     my $z = 1;
705 }
706 ####
707 # 3-argument for with inverted condition
708 for (my $i; not $i;) {
709     die;
710 }
711 for (my $i; not $i; ++$i) {
712     die;
713 }
714 for (my $a; not +($1 || 2) ** 2;) {
715     die;
716 }
717 Something_to_put_the_loop_in_void_context();
718 ####
719 # while/continue
720 my $i;
721 while ($i) { my $z = 1; } continue { $i = 99; }
722 ####
723 # foreach with my
724 foreach my $i (1, 2) {
725     my $z = 1;
726 }
727 ####
728 # OPTIONS -p
729 # foreach with my under -p
730 foreach my $i (1) {
731     die;
732 }
733 ####
734 # foreach
735 my $i;
736 foreach $i (1, 2) {
737     my $z = 1;
738 }
739 ####
740 # foreach, 2 mys
741 my $i;
742 foreach my $i (1, 2) {
743     my $z = 1;
744 }
745 ####
746 # foreach with our
747 foreach our $i (1, 2) {
748     my $z = 1;
749 }
750 ####
751 # foreach with my and our
752 my $i;
753 foreach our $i (1, 2) {
754     my $z = 1;
755 }
756 ####
757 # foreach with state
758 # CONTEXT use feature "state";
759 foreach state $i (1, 2) {
760     state $z = 1;
761 }
762 ####
763 # foreach with sub call
764 foreach $_ (hcaerof()) {
765     ();
766 }
767 ####
768 # reverse sort
769 my @x;
770 print reverse sort(@x);
771 ####
772 # sort with cmp
773 my @x;
774 print((sort {$b cmp $a} @x));
775 ####
776 # reverse sort with block
777 my @x;
778 print((reverse sort {$b <=> $a} @x));
779 ####
780 # foreach reverse
781 our @a;
782 print $_ foreach (reverse @a);
783 ####
784 # foreach reverse (not inplace)
785 our @a;
786 print $_ foreach (reverse 1, 2..5);
787 ####
788 # bug #38684
789 our @ary;
790 @ary = split(' ', 'foo', 0);
791 ####
792 my @ary;
793 @ary = split(' ', 'foo', 0);
794 ####
795 # Split to our array
796 our @array = split(//, 'foo', 0);
797 ####
798 # Split to my array
799 my @array  = split(//, 'foo', 0);
800 ####
801 our @array;
802 my $c;
803 @array = split(/x(?{ $c++; })y/, 'foo', 0);
804 ####
805 my($x, $y, $p);
806 our $c;
807 ($x, $y) = split(/$p(?{ $c++; })y/, 'foo', 2);
808 ####
809 our @ary;
810 my $pat;
811 @ary = split(/$pat/, 'foo', 0);
812 ####
813 my @ary;
814 our $pat;
815 @ary = split(/$pat/, 'foo', 0);
816 ####
817 our @array;
818 my $pat;
819 local @array = split(/$pat/, 'foo', 0);
820 ####
821 our $pat;
822 my @array  = split(/$pat/, 'foo', 0);
823 ####
824 # bug #40055
825 do { () }; 
826 ####
827 # bug #40055
828 do { my $x = 1; $x }; 
829 ####
830 # <20061012113037.GJ25805@c4.convolution.nl>
831 my $f = sub {
832     +{[]};
833 } ;
834 ####
835 # bug #43010
836 '!@$%'->();
837 ####
838 # bug #43010
839 ::();
840 ####
841 # bug #43010
842 '::::'->();
843 ####
844 # bug #43010
845 &::::;
846 ####
847 # [perl #77172]
848 package rt77172;
849 sub foo {} foo & & & foo;
850 >>>>
851 package rt77172;
852 foo(&{&} & foo());
853 ####
854 # variables as method names
855 my $bar;
856 'Foo'->$bar('orz');
857 'Foo'->$bar('orz') = 'a stranger stranger than before';
858 ####
859 # constants as method names
860 'Foo'->bar('orz');
861 ####
862 # constants as method names without ()
863 'Foo'->bar;
864 ####
865 # [perl #47359] "indirect" method call notation
866 our @bar;
867 foo{@bar}+1,->foo;
868 (foo{@bar}+1),foo();
869 foo{@bar}1 xor foo();
870 >>>>
871 our @bar;
872 (foo { @bar } 1)->foo;
873 (foo { @bar } 1), foo();
874 foo { @bar } 1 xor foo();
875 ####
876 # indirops with blocks
877 # CONTEXT use 5.01;
878 print {*STDOUT;} 'foo';
879 printf {*STDOUT;} 'foo';
880 say {*STDOUT;} 'foo';
881 system {'foo';} '-foo';
882 exec {'foo';} '-foo';
883 ####
884 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
885 # CONTEXT use feature ':5.10';
886 # say
887 say 'foo';
888 ####
889 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
890 # CONTEXT use 5.10.0;
891 # say in the context of use 5.10.0
892 say 'foo';
893 ####
894 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
895 # say with use 5.10.0
896 use 5.10.0;
897 say 'foo';
898 >>>>
899 no feature ':all';
900 use feature ':5.10';
901 say 'foo';
902 ####
903 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
904 # say with use feature ':5.10';
905 use feature ':5.10';
906 say 'foo';
907 >>>>
908 use feature 'say', 'state', 'switch';
909 say 'foo';
910 ####
911 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
912 # CONTEXT use feature ':5.10';
913 # say with use 5.10.0 in the context of use feature
914 use 5.10.0;
915 say 'foo';
916 >>>>
917 no feature ':all';
918 use feature ':5.10';
919 say 'foo';
920 ####
921 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
922 # CONTEXT use 5.10.0;
923 # say with use feature ':5.10' in the context of use 5.10.0
924 use feature ':5.10';
925 say 'foo';
926 >>>>
927 say 'foo';
928 ####
929 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
930 # CONTEXT use feature ':5.15';
931 # __SUB__
932 __SUB__;
933 ####
934 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
935 # CONTEXT use 5.15.0;
936 # __SUB__ in the context of use 5.15.0
937 __SUB__;
938 ####
939 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
940 # __SUB__ with use 5.15.0
941 use 5.15.0;
942 __SUB__;
943 >>>>
944 no feature ':all';
945 use feature ':5.16';
946 __SUB__;
947 ####
948 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
949 # __SUB__ with use feature ':5.15';
950 use feature ':5.15';
951 __SUB__;
952 >>>>
953 use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
954 __SUB__;
955 ####
956 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
957 # CONTEXT use feature ':5.15';
958 # __SUB__ with use 5.15.0 in the context of use feature
959 use 5.15.0;
960 __SUB__;
961 >>>>
962 no feature ':all';
963 use feature ':5.16';
964 __SUB__;
965 ####
966 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
967 # CONTEXT use 5.15.0;
968 # __SUB__ with use feature ':5.15' in the context of use 5.15.0
969 use feature ':5.15';
970 __SUB__;
971 >>>>
972 __SUB__;
973 ####
974 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
975 # CONTEXT use feature ':5.10';
976 # state vars
977 state $x = 42;
978 ####
979 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
980 # CONTEXT use feature ':5.10';
981 # state var assignment
982 {
983     my $y = (state $x = 42);
984 }
985 ####
986 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
987 # CONTEXT use feature ':5.10';
988 # state vars in anonymous subroutines
989 $a = sub {
990     state $x;
991     return $x++;
992 }
993 ;
994 ####
995 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
996 # each @array;
997 each @ARGV;
998 each @$a;
999 ####
1000 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
1001 # keys @array; values @array
1002 keys @$a if keys @ARGV;
1003 values @ARGV if values @$a;
1004 ####
1005 # Anonymous arrays and hashes, and references to them
1006 my $a = {};
1007 my $b = \{};
1008 my $c = [];
1009 my $d = \[];
1010 ####
1011 # SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
1012 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
1013 # implicit smartmatch in given/when
1014 given ('foo') {
1015     when ('bar') { continue; }
1016     when ($_ ~~ 'quux') { continue; }
1017     default { 0; }
1018 }
1019 ####
1020 # conditions in elsifs (regression in change #33710 which fixed bug #37302)
1021 if ($a) { x(); }
1022 elsif ($b) { x(); }
1023 elsif ($a and $b) { x(); }
1024 elsif ($a or $b) { x(); }
1025 else { x(); }
1026 ####
1027 # interpolation in regexps
1028 my($y, $t);
1029 /x${y}z$t/;
1030 ####
1031 # TODO new undocumented cpan-bug #33708
1032 # cpan-bug #33708
1033 %{$_ || {}}
1034 ####
1035 # TODO hash constants not yet fixed
1036 # cpan-bug #33708
1037 use constant H => { "#" => 1 }; H->{"#"}
1038 ####
1039 # TODO optimized away 0 not yet fixed
1040 # cpan-bug #33708
1041 foreach my $i (@_) { 0 }
1042 ####
1043 # tests with not, not optimized
1044 my $c;
1045 x() unless $a;
1046 x() if not $a and $b;
1047 x() if $a and not $b;
1048 x() unless not $a and $b;
1049 x() unless $a and not $b;
1050 x() if not $a or $b;
1051 x() if $a or not $b;
1052 x() unless not $a or $b;
1053 x() unless $a or not $b;
1054 x() if $a and not $b and $c;
1055 x() if not $a and $b and not $c;
1056 x() unless $a and not $b and $c;
1057 x() unless not $a and $b and not $c;
1058 x() if $a or not $b or $c;
1059 x() if not $a or $b or not $c;
1060 x() unless $a or not $b or $c;
1061 x() unless not $a or $b or not $c;
1062 ####
1063 # tests with not, optimized
1064 my $c;
1065 x() if not $a;
1066 x() unless not $a;
1067 x() if not $a and not $b;
1068 x() unless not $a and not $b;
1069 x() if not $a or not $b;
1070 x() unless not $a or not $b;
1071 x() if not $a and not $b and $c;
1072 x() unless not $a and not $b and $c;
1073 x() if not $a or not $b or $c;
1074 x() unless not $a or not $b or $c;
1075 x() if not $a and not $b and not $c;
1076 x() unless not $a and not $b and not $c;
1077 x() if not $a or not $b or not $c;
1078 x() unless not $a or not $b or not $c;
1079 x() unless not $a or not $b or not $c;
1080 >>>>
1081 my $c;
1082 x() unless $a;
1083 x() if $a;
1084 x() unless $a or $b;
1085 x() if $a or $b;
1086 x() unless $a and $b;
1087 x() if $a and $b;
1088 x() if not $a || $b and $c;
1089 x() unless not $a || $b and $c;
1090 x() if not $a && $b or $c;
1091 x() unless not $a && $b or $c;
1092 x() unless $a or $b or $c;
1093 x() if $a or $b or $c;
1094 x() unless $a and $b and $c;
1095 x() if $a and $b and $c;
1096 x() unless not $a && $b && $c;
1097 ####
1098 # tests that should be constant folded
1099 x() if 1;
1100 x() if GLIPP;
1101 x() if !GLIPP;
1102 x() if GLIPP && GLIPP;
1103 x() if !GLIPP || GLIPP;
1104 x() if do { GLIPP };
1105 x() if do { no warnings 'void'; 5; GLIPP };
1106 x() if do { !GLIPP };
1107 if (GLIPP) { x() } else { z() }
1108 if (!GLIPP) { x() } else { z() }
1109 if (GLIPP) { x() } elsif (GLIPP) { z() }
1110 if (!GLIPP) { x() } elsif (GLIPP) { z() }
1111 if (GLIPP) { x() } elsif (!GLIPP) { z() }
1112 if (!GLIPP) { x() } elsif (!GLIPP) { z() }
1113 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
1114 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
1115 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
1116 >>>>
1117 x();
1118 x();
1119 '???';
1120 x();
1121 x();
1122 x();
1123 x();
1124 do {
1125     '???'
1126 };
1127 do {
1128     x()
1129 };
1130 do {
1131     z()
1132 };
1133 do {
1134     x()
1135 };
1136 do {
1137     z()
1138 };
1139 do {
1140     x()
1141 };
1142 '???';
1143 do {
1144     t()
1145 };
1146 '???';
1147 !1;
1148 ####
1149 # TODO constant deparsing has been backed out for 5.12
1150 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
1151 # tests that shouldn't be constant folded
1152 # It might be fundamentally impossible to make this work on ithreads, in which
1153 # case the TODO should become a SKIP
1154 x() if $a;
1155 if ($a == 1) { x() } elsif ($b == 2) { z() }
1156 if (do { foo(); GLIPP }) { x() }
1157 if (do { $a++; GLIPP }) { x() }
1158 >>>>
1159 x() if $a;
1160 if ($a == 1) { x(); } elsif ($b == 2) { z(); }
1161 if (do { foo(); GLIPP }) { x(); }
1162 if (do { ++$a; GLIPP }) { x(); }
1163 ####
1164 # TODO constant deparsing has been backed out for 5.12
1165 # tests for deparsing constants
1166 warn PI;
1167 ####
1168 # TODO constant deparsing has been backed out for 5.12
1169 # tests for deparsing imported constants
1170 warn O_TRUNC;
1171 ####
1172 # TODO constant deparsing has been backed out for 5.12
1173 # tests for deparsing re-exported constants
1174 warn O_CREAT;
1175 ####
1176 # TODO constant deparsing has been backed out for 5.12
1177 # tests for deparsing imported constants that got deleted from the original namespace
1178 warn O_APPEND;
1179 ####
1180 # TODO constant deparsing has been backed out for 5.12
1181 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
1182 # tests for deparsing constants which got turned into full typeglobs
1183 # It might be fundamentally impossible to make this work on ithreads, in which
1184 # case the TODO should become a SKIP
1185 warn O_EXCL;
1186 eval '@Fcntl::O_EXCL = qw/affe tiger/;';
1187 warn O_EXCL;
1188 ####
1189 # TODO constant deparsing has been backed out for 5.12
1190 # tests for deparsing of blessed constant with overloaded numification
1191 warn OVERLOADED_NUMIFICATION;
1192 ####
1193 # strict
1194 no strict;
1195 print $x;
1196 use strict 'vars';
1197 print $main::x;
1198 use strict 'subs';
1199 print $main::x;
1200 use strict 'refs';
1201 print $main::x;
1202 no strict 'vars';
1203 $x;
1204 ####
1205 # TODO Subsets of warnings could be encoded textually, rather than as bitflips.
1206 # subsets of warnings
1207 no warnings 'deprecated';
1208 my $x;
1209 ####
1210 # TODO Better test for CPAN #33708 - the deparsed code has different behaviour
1211 # CPAN #33708
1212 use strict;
1213 no warnings;
1214
1215 foreach (0..3) {
1216     my $x = 2;
1217     {
1218         my $x if 0;
1219         print ++$x, "\n";
1220     }
1221 }
1222 ####
1223 # no attribute list
1224 my $pi = 4;
1225 ####
1226 # SKIP ?$] > 5.013006 && ":= is now a syntax error"
1227 # := treated as an empty attribute list
1228 no warnings;
1229 my $pi := 4;
1230 >>>>
1231 no warnings;
1232 my $pi = 4;
1233 ####
1234 # : = empty attribute list
1235 my $pi : = 4;
1236 >>>>
1237 my $pi = 4;
1238 ####
1239 # in place sort
1240 our @a;
1241 my @b;
1242 @a = sort @a;
1243 @b = sort @b;
1244 ();
1245 ####
1246 # in place reverse
1247 our @a;
1248 my @b;
1249 @a = reverse @a;
1250 @b = reverse @b;
1251 ();
1252 ####
1253 # #71870 Use of uninitialized value in bitwise and B::Deparse
1254 my($r, $s, @a);
1255 @a = split(/foo/, $s, 0);
1256 $r = qr/foo/;
1257 @a = split(/$r/, $s, 0);
1258 ();
1259 ####
1260 # package declaration before label
1261 {
1262     package Foo;
1263     label: print 123;
1264 }
1265 ####
1266 # shift optimisation
1267 shift;
1268 >>>>
1269 shift();
1270 ####
1271 # shift optimisation
1272 shift @_;
1273 ####
1274 # shift optimisation
1275 pop;
1276 >>>>
1277 pop();
1278 ####
1279 # shift optimisation
1280 pop @_;
1281 ####
1282 #[perl #20444]
1283 "foo" =~ (1 ? /foo/ : /bar/);
1284 "foo" =~ (1 ? y/foo// : /bar/);
1285 "foo" =~ (1 ? y/foo//r : /bar/);
1286 "foo" =~ (1 ? s/foo// : /bar/);
1287 >>>>
1288 'foo' =~ ($_ =~ /foo/);
1289 'foo' =~ ($_ =~ tr/fo//);
1290 'foo' =~ ($_ =~ tr/fo//r);
1291 'foo' =~ ($_ =~ s/foo//);
1292 ####
1293 # The fix for [perl #20444] broke this.
1294 'foo' =~ do { () };
1295 ####
1296 # [perl #81424] match against aelemfast_lex
1297 my @s;
1298 print /$s[1]/;
1299 ####
1300 # /$#a/
1301 print /$#main::a/;
1302 ####
1303 # /@array/
1304 our @a;
1305 my @b;
1306 print /@a/;
1307 print /@b/;
1308 print qr/@a/;
1309 print qr/@b/;
1310 ####
1311 # =~ QR_CONSTANT
1312 use constant QR_CONSTANT => qr/a/soupmix;
1313 '' =~ QR_CONSTANT;
1314 >>>>
1315 '' =~ /a/impsux;
1316 ####
1317 # $lexical =~ //
1318 my $x;
1319 $x =~ //;
1320 ####
1321 # [perl #91318] /regexp/applaud
1322 print /a/a, s/b/c/a;
1323 print /a/aa, s/b/c/aa;
1324 print /a/p, s/b/c/p;
1325 print /a/l, s/b/c/l;
1326 print /a/u, s/b/c/u;
1327 {
1328     use feature "unicode_strings";
1329     print /a/d, s/b/c/d;
1330 }
1331 {
1332     use re "/u";
1333     print /a/d, s/b/c/d;
1334 }
1335 {
1336     use 5.012;
1337     print /a/d, s/b/c/d;
1338 }
1339 >>>>
1340 print /a/a, s/b/c/a;
1341 print /a/aa, s/b/c/aa;
1342 print /a/p, s/b/c/p;
1343 print /a/l, s/b/c/l;
1344 print /a/u, s/b/c/u;
1345 {
1346     use feature 'unicode_strings';
1347     print /a/d, s/b/c/d;
1348 }
1349 {
1350     BEGIN { $^H{'reflags'}         = '0';
1351             $^H{'reflags_charset'} = '2'; }
1352     print /a/d, s/b/c/d;
1353 }
1354 {
1355     no feature ':all';
1356     use feature ':5.12';
1357     print /a/d, s/b/c/d;
1358 }
1359 ####
1360 # all the flags (qr//)
1361 $_ = qr/X/m;
1362 $_ = qr/X/s;
1363 $_ = qr/X/i;
1364 $_ = qr/X/x;
1365 $_ = qr/X/p;
1366 $_ = qr/X/o;
1367 $_ = qr/X/u;
1368 $_ = qr/X/a;
1369 $_ = qr/X/l;
1370 $_ = qr/X/n;
1371 ####
1372 use feature 'unicode_strings';
1373 $_ = qr/X/d;
1374 ####
1375 # all the flags (m//)
1376 /X/m;
1377 /X/s;
1378 /X/i;
1379 /X/x;
1380 /X/p;
1381 /X/o;
1382 /X/u;
1383 /X/a;
1384 /X/l;
1385 /X/n;
1386 /X/g;
1387 /X/cg;
1388 ####
1389 use feature 'unicode_strings';
1390 /X/d;
1391 ####
1392 # all the flags (s///)
1393 s/X//m;
1394 s/X//s;
1395 s/X//i;
1396 s/X//x;
1397 s/X//p;
1398 s/X//o;
1399 s/X//u;
1400 s/X//a;
1401 s/X//l;
1402 s/X//n;
1403 s/X//g;
1404 s/X/'';/e;
1405 s/X//r;
1406 ####
1407 use feature 'unicode_strings';
1408 s/X//d;
1409 ####
1410 # all the flags (tr///)
1411 tr/X/Y/c;
1412 tr/X//d;
1413 tr/X//s;
1414 tr/X//r;
1415 ####
1416 # [perl #119807] s//\(3)/ge should not warn when deparsed (\3 warns)
1417 s/foo/\(3);/eg;
1418 ####
1419 # [perl #115256]
1420 "" =~ /a(?{ print q|
1421 |})/;
1422 >>>>
1423 '' =~ /a(?{ print "\n"; })/;
1424 ####
1425 # [perl #123217]
1426 $_ = qr/(??{<<END})/
1427 f.o
1428 b.r
1429 END
1430 >>>>
1431 $_ = qr/(??{ "f.o\nb.r\n"; })/;
1432 ####
1433 # More regexp code block madness
1434 my($b, @a);
1435 /(?{ die $b; })/;
1436 /a(?{ die $b; })a/;
1437 /$a(?{ die $b; })/;
1438 /@a(?{ die $b; })/;
1439 /(??{ die $b; })/;
1440 /a(??{ die $b; })a/;
1441 /$a(??{ die $b; })/;
1442 /@a(??{ die $b; })/;
1443 qr/(?{ die $b; })/;
1444 qr/a(?{ die $b; })a/;
1445 qr/$a(?{ die $b; })/;
1446 qr/@a(?{ die $b; })/;
1447 qr/(??{ die $b; })/;
1448 qr/a(??{ die $b; })a/;
1449 qr/$a(??{ die $b; })/;
1450 qr/@a(??{ die $b; })/;
1451 s/(?{ die $b; })//;
1452 s/a(?{ die $b; })a//;
1453 s/$a(?{ die $b; })//;
1454 s/@a(?{ die $b; })//;
1455 s/(??{ die $b; })//;
1456 s/a(??{ die $b; })a//;
1457 s/$a(??{ die $b; })//;
1458 s/@a(??{ die $b; })//;
1459 ####
1460 # /(?x)<newline><tab>/
1461 /(?x)
1462         /;
1463 ####
1464 # y///r
1465 tr/a/b/r + $a =~ tr/p/q/r;
1466 ####
1467 # y///d in list [perl #119815]
1468 () = tr/a//d;
1469 ####
1470 # [perl #90898]
1471 <a,>;
1472 glob 'a,';
1473 >>>>
1474 glob 'a,';
1475 glob 'a,';
1476 ####
1477 # [perl #91008]
1478 # SKIP ?$] >= 5.023 && "autoderef deleted in this Perl version"
1479 # CONTEXT no warnings 'experimental::autoderef';
1480 each $@;
1481 keys $~;
1482 values $!;
1483 ####
1484 # readpipe with complex expression
1485 readpipe $a + $b;
1486 ####
1487 # aelemfast
1488 $b::a[0] = 1;
1489 ####
1490 # aelemfast for a lexical
1491 my @a;
1492 $a[0] = 1;
1493 ####
1494 # feature features without feature
1495 # CONTEXT no warnings 'experimental::smartmatch';
1496 CORE::state $x;
1497 CORE::say $x;
1498 CORE::given ($x) {
1499     CORE::when (3) {
1500         continue;
1501     }
1502     CORE::default {
1503         CORE::break;
1504     }
1505 }
1506 CORE::evalbytes '';
1507 () = CORE::__SUB__;
1508 () = CORE::fc $x;
1509 ####
1510 # feature features when feature has been disabled by use VERSION
1511 # CONTEXT no warnings 'experimental::smartmatch';
1512 use feature (sprintf(":%vd", $^V));
1513 use 1;
1514 CORE::say $_;
1515 CORE::state $x;
1516 CORE::given ($x) {
1517     CORE::when (3) {
1518         continue;
1519     }
1520     CORE::default {
1521         CORE::break;
1522     }
1523 }
1524 CORE::evalbytes '';
1525 () = CORE::__SUB__;
1526 >>>>
1527 CORE::say $_;
1528 CORE::state $x;
1529 CORE::given ($x) {
1530     CORE::when (3) {
1531         continue;
1532     }
1533     CORE::default {
1534         CORE::break;
1535     }
1536 }
1537 CORE::evalbytes '';
1538 () = CORE::__SUB__;
1539 ####
1540 # (the above test with CONTEXT, and the output is equivalent but different)
1541 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
1542 # feature features when feature has been disabled by use VERSION
1543 use feature (sprintf(":%vd", $^V));
1544 use 1;
1545 CORE::say $_;
1546 CORE::state $x;
1547 CORE::given ($x) {
1548     CORE::when (3) {
1549         continue;
1550     }
1551     CORE::default {
1552         CORE::break;
1553     }
1554 }
1555 CORE::evalbytes '';
1556 () = CORE::__SUB__;
1557 >>>>
1558 no feature ':all';
1559 use feature ':default';
1560 CORE::say $_;
1561 CORE::state $x;
1562 CORE::given ($x) {
1563     CORE::when (3) {
1564         continue;
1565     }
1566     CORE::default {
1567         CORE::break;
1568     }
1569 }
1570 CORE::evalbytes '';
1571 () = CORE::__SUB__;
1572 ####
1573 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1574 # lexical subroutines and keywords of the same name
1575 # CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental';
1576 my sub default;
1577 my sub else;
1578 my sub elsif;
1579 my sub for;
1580 my sub foreach;
1581 my sub given;
1582 my sub if;
1583 my sub m;
1584 my sub no;
1585 my sub package;
1586 my sub q;
1587 my sub qq;
1588 my sub qr;
1589 my sub qx;
1590 my sub require;
1591 my sub s;
1592 my sub sub;
1593 my sub tr;
1594 my sub unless;
1595 my sub until;
1596 my sub use;
1597 my sub when;
1598 my sub while;
1599 CORE::default { die; }
1600 CORE::if ($1) { die; }
1601 CORE::if ($1) { die; }
1602 CORE::elsif ($1) { die; }
1603 CORE::else { die; }
1604 CORE::for (die; $1; die) { die; }
1605 CORE::foreach $_ (1 .. 10) { die; }
1606 die CORE::foreach (1);
1607 CORE::given ($1) { die; }
1608 CORE::m[/];
1609 CORE::m?/?;
1610 CORE::package foo;
1611 CORE::no strict;
1612 () = (CORE::q['], CORE::qq["$_], CORE::qr//, CORE::qx[`]);
1613 CORE::require 1;
1614 CORE::s///;
1615 () = CORE::sub { die; } ;
1616 CORE::tr///;
1617 CORE::unless ($1) { die; }
1618 CORE::until ($1) { die; }
1619 die CORE::until $1;
1620 CORE::use strict;
1621 CORE::when ($1 ~~ $2) { die; }
1622 CORE::while ($1) { die; }
1623 die CORE::while $1;
1624 ####
1625 # Feature hints
1626 use feature 'current_sub', 'evalbytes';
1627 print;
1628 use 1;
1629 print;
1630 use 5.014;
1631 print;
1632 no feature 'unicode_strings';
1633 print;
1634 >>>>
1635 use feature 'current_sub', 'evalbytes';
1636 print $_;
1637 no feature ':all';
1638 use feature ':default';
1639 print $_;
1640 no feature ':all';
1641 use feature ':5.12';
1642 print $_;
1643 no feature 'unicode_strings';
1644 print $_;
1645 ####
1646 # $#- $#+ $#{%} etc.
1647 my @x;
1648 @x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
1649 @x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
1650 @x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
1651 @x = ($#{;}, $#{:}, $#{1}), $#_;
1652 ####
1653 # ${#} interpolated
1654 # It's a known TODO that warnings are deparsed as bits, not textually.
1655 no warnings;
1656 () = "${#}a";
1657 ####
1658 # [perl #86060] $( $| $) in regexps need braces
1659 /${(}/;
1660 /${|}/;
1661 /${)}/;
1662 /${(}${|}${)}/;
1663 /@{+}@{-}/;
1664 ####
1665 # ()[...]
1666 my(@a) = ()[()];
1667 ####
1668 # sort(foo(bar))
1669 # sort(foo(bar)) is interpreted as sort &foo(bar)
1670 # sort foo(bar) is interpreted as sort foo bar
1671 # parentheses are not optional in this case
1672 print sort(foo('bar'));
1673 >>>>
1674 print sort(foo('bar'));
1675 ####
1676 # substr assignment
1677 substr(my $a, 0, 0) = (foo(), bar());
1678 $a++;
1679 ####
1680 # This following line works around an unfixed bug that we are not trying to 
1681 # test for here:
1682 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1683 # hint hash
1684 BEGIN { $^H{'foo'} = undef; }
1685 {
1686  BEGIN { $^H{'bar'} = undef; }
1687  {
1688   BEGIN { $^H{'baz'} = undef; }
1689   {
1690    print $_;
1691   }
1692   print $_;
1693  }
1694  print $_;
1695 }
1696 BEGIN { $^H{q[']} = '('; }
1697 print $_;
1698 ####
1699 # This following line works around an unfixed bug that we are not trying to 
1700 # test for here:
1701 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1702 # hint hash changes that serialise the same way with sort %hh
1703 BEGIN { $^H{'a'} = 'b'; }
1704 {
1705  BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
1706  print $_;
1707 }
1708 print $_;
1709 ####
1710 # [perl #47361] do({}) and do +{} (variants of do-file)
1711 do({});
1712 do +{};
1713 sub foo::do {}
1714 package foo;
1715 CORE::do({});
1716 CORE::do +{};
1717 >>>>
1718 do({});
1719 do({});
1720 package foo;
1721 CORE::do({});
1722 CORE::do({});
1723 ####
1724 # [perl #77096] functions that do not follow the llafr
1725 () = (return 1) + time;
1726 () = (return ($1 + $2) * $3) + time;
1727 () = (return ($a xor $b)) + time;
1728 () = (do 'file') + time;
1729 () = (do ($1 + $2) * $3) + time;
1730 () = (do ($1 xor $2)) + time;
1731 () = (goto 1) + 3;
1732 () = (require 'foo') + 3;
1733 () = (require foo) + 3;
1734 () = (CORE::dump 1) + 3;
1735 () = (last 1) + 3;
1736 () = (next 1) + 3;
1737 () = (redo 1) + 3;
1738 () = (-R $_) + 3;
1739 () = (-W $_) + 3;
1740 () = (-X $_) + 3;
1741 () = (-r $_) + 3;
1742 () = (-w $_) + 3;
1743 () = (-x $_) + 3;
1744 ####
1745 # require(foo()) and do(foo())
1746 require (foo());
1747 do (foo());
1748 goto (foo());
1749 CORE::dump (foo());
1750 last (foo());
1751 next (foo());
1752 redo (foo());
1753 ####
1754 # require vstring
1755 require v5.16;
1756 ####
1757 # [perl #97476] not() *does* follow the llafr
1758 $_ = ($a xor not +($1 || 2) ** 2);
1759 ####
1760 # Precedence conundrums with argument-less function calls
1761 () = (eof) + 1;
1762 () = (return) + 1;
1763 () = (return, 1);
1764 () = warn;
1765 () = warn() + 1;
1766 () = setpgrp() + 1;
1767 ####
1768 # loopexes have assignment prec
1769 () = (CORE::dump a) | 'b';
1770 () = (goto a) | 'b';
1771 () = (last a) | 'b';
1772 () = (next a) | 'b';
1773 () = (redo a) | 'b';
1774 ####
1775 # [perl #63558] open local(*FH)
1776 open local *FH;
1777 pipe local *FH, local *FH;
1778 ####
1779 # [perl #91416] open "string"
1780 open 'open';
1781 open '####';
1782 open '^A';
1783 open "\ca";
1784 >>>>
1785 open *open;
1786 open '####';
1787 open '^A';
1788 open *^A;
1789 ####
1790 # "string"->[] ->{}
1791 no strict 'vars';
1792 () = 'open'->[0]; #aelemfast
1793 () = '####'->[0];
1794 () = '^A'->[0];
1795 () = "\ca"->[0];
1796 () = 'a::]b'->[0];
1797 () = 'open'->[$_]; #aelem
1798 () = '####'->[$_];
1799 () = '^A'->[$_];
1800 () = "\ca"->[$_];
1801 () = 'a::]b'->[$_];
1802 () = 'open'->{0}; #helem
1803 () = '####'->{0};
1804 () = '^A'->{0};
1805 () = "\ca"->{0};
1806 () = 'a::]b'->{0};
1807 >>>>
1808 no strict 'vars';
1809 () = $open[0];
1810 () = '####'->[0];
1811 () = '^A'->[0];
1812 () = $^A[0];
1813 () = 'a::]b'->[0];
1814 () = $open[$_];
1815 () = '####'->[$_];
1816 () = '^A'->[$_];
1817 () = $^A[$_];
1818 () = 'a::]b'->[$_];
1819 () = $open{'0'};
1820 () = '####'->{'0'};
1821 () = '^A'->{'0'};
1822 () = $^A{'0'};
1823 () = 'a::]b'->{'0'};
1824 ####
1825 # [perl #74740] -(f()) vs -f()
1826 $_ = -(f());
1827 ####
1828 # require <binop>
1829 require 'a' . $1;
1830 ####
1831 #[perl #30504] foreach-my postfix/prefix difference
1832 $_ = 'foo' foreach my ($foo1, $bar1, $baz1);
1833 foreach (my ($foo2, $bar2, $baz2)) { $_ = 'foo' }
1834 foreach my $i (my ($foo3, $bar3, $baz3)) { $i = 'foo' }
1835 >>>>
1836 $_ = 'foo' foreach (my($foo1, $bar1, $baz1));
1837 foreach $_ (my($foo2, $bar2, $baz2)) {
1838     $_ = 'foo';
1839 }
1840 foreach my $i (my($foo3, $bar3, $baz3)) {
1841     $i = 'foo';
1842 }
1843 ####
1844 #[perl #108224] foreach with continue block
1845 foreach (1 .. 3) { print } continue { print "\n" }
1846 foreach (1 .. 3) { } continue { }
1847 foreach my $i (1 .. 3) { print $i } continue { print "\n" }
1848 foreach my $i (1 .. 3) { } continue { }
1849 >>>>
1850 foreach $_ (1 .. 3) {
1851     print $_;
1852 }
1853 continue {
1854     print "\n";
1855 }
1856 foreach $_ (1 .. 3) {
1857     ();
1858 }
1859 continue {
1860     ();
1861 }
1862 foreach my $i (1 .. 3) {
1863     print $i;
1864 }
1865 continue {
1866     print "\n";
1867 }
1868 foreach my $i (1 .. 3) {
1869     ();
1870 }
1871 continue {
1872     ();
1873 }
1874 ####
1875 # file handles
1876 no strict;
1877 my $mfh;
1878 open F;
1879 open *F;
1880 open $fh;
1881 open $mfh;
1882 open 'a+b';
1883 select *F;
1884 select F;
1885 select $f;
1886 select $mfh;
1887 select 'a+b';
1888 ####
1889 # 'my' works with padrange op
1890 my($z, @z);
1891 my $m1;
1892 $m1 = 1;
1893 $z = $m1;
1894 my $m2 = 2;
1895 my($m3, $m4);
1896 ($m3, $m4) = (1, 2);
1897 @z = ($m3, $m4);
1898 my($m5, $m6) = (1, 2);
1899 my($m7, undef, $m8) = (1, 2, 3);
1900 @z = ($m7, undef, $m8);
1901 ($m7, undef, $m8) = (1, 2, 3);
1902 ####
1903 # 'our/local' works with padrange op
1904 our($z, @z);
1905 our $o1;
1906 no strict;
1907 local $o11;
1908 $o1 = 1;
1909 local $o1 = 1;
1910 $z = $o1;
1911 $z = local $o1;
1912 our $o2 = 2;
1913 our($o3, $o4);
1914 ($o3, $o4) = (1, 2);
1915 local($o3, $o4) = (1, 2);
1916 @z = ($o3, $o4);
1917 @z = local($o3, $o4);
1918 our($o5, $o6) = (1, 2);
1919 our($o7, undef, $o8) = (1, 2, 3);
1920 @z = ($o7, undef, $o8);
1921 @z = local($o7, undef, $o8);
1922 ($o7, undef, $o8) = (1, 2, 3);
1923 local($o7, undef, $o8) = (1, 2, 3);
1924 ####
1925 # 'state' works with padrange op
1926 # CONTEXT no strict; use feature 'state';
1927 state($z, @z);
1928 state $s1;
1929 $s1 = 1;
1930 $z = $s1;
1931 state $s2 = 2;
1932 state($s3, $s4);
1933 ($s3, $s4) = (1, 2);
1934 @z = ($s3, $s4);
1935 # assignment of state lists isn't implemented yet
1936 #state($s5, $s6) = (1, 2);
1937 #state($s7, undef, $s8) = (1, 2, 3);
1938 #@z = ($s7, undef, $s8);
1939 ($s7, undef, $s8) = (1, 2, 3);
1940 ####
1941 # anon arrays with padrange
1942 my($a, $b);
1943 my $c = [$a, $b];
1944 my $d = {$a, $b};
1945 ####
1946 # slices with padrange
1947 my($a, $b);
1948 my(@x, %y);
1949 @x = @x[$a, $b];
1950 @x = @y{$a, $b};
1951 ####
1952 # binops with padrange
1953 my($a, $b, $c);
1954 $c = $a cmp $b;
1955 $c = $a + $b;
1956 $a += $b;
1957 $c = $a - $b;
1958 $a -= $b;
1959 $c = my $a1 cmp $b;
1960 $c = my $a2 + $b;
1961 $a += my $b1;
1962 $c = my $a3 - $b;
1963 $a -= my $b2;
1964 ####
1965 # 'x' with padrange
1966 my($a, $b, $c, $d, @e);
1967 $c = $a x $b;
1968 $a x= $b;
1969 @e = ($a) x $d;
1970 @e = ($a, $b) x $d;
1971 @e = ($a, $b, $c) x $d;
1972 @e = ($a, 1) x $d;
1973 ####
1974 # @_ with padrange
1975 my($a, $b, $c) = @_;
1976 ####
1977 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1978 # lexical subroutine
1979 # CONTEXT use feature 'lexical_subs';
1980 no warnings "experimental::lexical_subs";
1981 my sub f {}
1982 print f();
1983 >>>>
1984 BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55"}
1985 my sub f {
1986     
1987 }
1988 print f();
1989 ####
1990 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1991 # lexical "state" subroutine
1992 # CONTEXT use feature 'state', 'lexical_subs';
1993 no warnings 'experimental::lexical_subs';
1994 state sub f {}
1995 print f();
1996 >>>>
1997 BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55"}
1998 state sub f {
1999     
2000 }
2001 print f();
2002 ####
2003 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
2004 # lexical subroutine scoping
2005 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
2006 {
2007   {
2008     my sub a { die; }
2009     {
2010       foo();
2011       my sub b;
2012       b ;
2013       main::b();
2014       &main::b;
2015       &main::b();
2016       my $b = \&main::b;
2017       sub b { $b; }
2018     }
2019   }
2020   b();
2021 }
2022 ####
2023 # self-referential lexical subroutine
2024 # CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
2025 ();
2026 state sub sb2;
2027 sub sb2 {
2028     sb2 ;
2029 }
2030 ####
2031 # lexical subroutine with outer declaration and inner definition
2032 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
2033 ();
2034 my sub f;
2035 my sub g {
2036     ();
2037     sub f { }
2038 }
2039 ####
2040 # TODO only partially fixed
2041 # lexical state subroutine with outer declaration and inner definition
2042 # CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
2043 ();
2044 state sub sb4;
2045 state sub a {
2046     ();
2047     sub sb4 { }
2048 }
2049 state sub sb5;
2050 sub {
2051     ();
2052     sub sb5 { }
2053 } ;
2054 ####
2055 # Elements of %# should not be confused with $#{ array }
2056 () = ${#}{'foo'};
2057 ####
2058 # $; [perl #123357]
2059 $_ = $;;
2060 do {
2061     $;
2062 };
2063 ####
2064 # Ampersand calls and scalar context
2065 # OPTIONS -P
2066 package prototest;
2067 sub foo($$);
2068 foo(bar(),baz());
2069 >>>>
2070 package prototest;
2071 &foo(scalar bar(), scalar baz());
2072 ####
2073 # coderef2text and prototyped sub calls [perl #123435]
2074 is 'foo', 'oo';
2075 ####
2076 # prototypes with unary precedence
2077 package prototest;
2078 sub dollar($) {}
2079 sub optdollar(;$) {}
2080 sub optoptdollar(;;$) {}
2081 sub splat(*) {}
2082 sub optsplat(;*) {}
2083 sub optoptsplat(;;*) {}
2084 sub bar(_) {}
2085 sub optbar(;_) {}
2086 sub optoptbar(;;_) {}
2087 sub plus(+) {}
2088 sub optplus(;+) {}
2089 sub optoptplus(;;+) {}
2090 sub wack(\$) {}
2091 sub optwack(;\$) {}
2092 sub optoptwack(;;\$) {}
2093 sub wackbrack(\[$]) {}
2094 sub optwackbrack(;\[$]) {}
2095 sub optoptwackbrack(;;\[$]) {}
2096 dollar($a < $b);
2097 optdollar($a < $b);
2098 optoptdollar($a < $b);
2099 splat($a < $b);     # Some of these deparse with â€˜&’; if that changes, just
2100 optsplat($a < $b);  # change the tests.
2101 optoptsplat($a < $b);
2102 bar($a < $b);
2103 optbar($a < $b);
2104 optoptbar($a < $b);
2105 plus($a < $b);
2106 optplus($a < $b);
2107 optoptplus($a < $b);
2108 wack($a = $b);
2109 optwack($a = $b);
2110 optoptwack($a = $b);
2111 wackbrack($a = $b);
2112 optwackbrack($a = $b);
2113 optoptwackbrack($a = $b);
2114 >>>>
2115 package prototest;
2116 dollar($a < $b);
2117 optdollar($a < $b);
2118 optoptdollar($a < $b);
2119 &splat($a < $b);
2120 &optsplat($a < $b);
2121 &optoptsplat($a < $b);
2122 bar($a < $b);
2123 optbar($a < $b);
2124 optoptbar($a < $b);
2125 &plus($a < $b);
2126 &optplus($a < $b);
2127 &optoptplus($a < $b);
2128 &wack(\($a = $b));
2129 &optwack(\($a = $b));
2130 &optoptwack(\($a = $b));
2131 &wackbrack(\($a = $b));
2132 &optwackbrack(\($a = $b));
2133 &optoptwackbrack(\($a = $b));
2134 ####
2135 # ensure aelemfast works in the range -128..127 and that there's no
2136 # funky edge cases
2137 my $x;
2138 no strict 'vars';
2139 $x = $a[-256] + $a[-255] + $a[-129] + $a[-128] + $a[-127] + $a[-1] + $a[0];
2140 $x = $a[1] + $a[126] + $a[127] + $a[128] + $a[255] + $a[256];
2141 my @b;
2142 $x = $b[-256] + $b[-255] + $b[-129] + $b[-128] + $b[-127] + $b[-1] + $b[0];
2143 $x = $b[1] + $b[126] + $b[127] + $b[128] + $b[255] + $b[256];
2144 ####
2145 # 'm' must be preserved in m??
2146 m??;
2147 ####
2148 # \(@array) and \(..., (@array), ...)
2149 my(@array, %hash, @a, @b, %c, %d);
2150 () = \(@array);
2151 () = \(%hash);
2152 () = \(@a, (@b), (%c), %d);
2153 () = \(@Foo::array);
2154 () = \(%Foo::hash);
2155 () = \(@Foo::a, (@Foo::b), (%Foo::c), %Foo::d);
2156 ####
2157 # subs synonymous with keywords
2158 main::our();
2159 main::pop();
2160 state();
2161 use feature 'state';
2162 main::state();
2163 ####
2164 # lvalue references
2165 # CONTEXT use feature "state", 'refaliasing', 'lexical_subs'; no warnings 'experimental';
2166 our $x;
2167 \$x = \$x;
2168 my $m;
2169 \$m = \$x;
2170 \my $n = \$x;
2171 (\$x) = @_;
2172 \($x) = @_;
2173 \($m) = @_;
2174 (\$m) = @_;
2175 \my($p) = @_;
2176 (\my $r) = @_;
2177 \($x, my $a) = @{[\$x, \$x]};
2178 (\$x, \my $b) = @{[\$x, \$x]};
2179 \local $x = \3;
2180 \local($x) = \3;
2181 \state $c = \3;
2182 \state($d) = \3;
2183 \our $e = \3;
2184 \our($f) = \3;
2185 \$_[0] = foo();
2186 \($_[1]) = foo();
2187 my @a;
2188 \$a[0] = foo();
2189 \($a[1]) = foo();
2190 \local($a[1]) = foo();
2191 \@a[0,1] = foo();
2192 \(@a[2,3]) = foo();
2193 \local @a[0,1] = (\$a)x2;
2194 \$_{a} = foo();
2195 \($_{b}) = foo();
2196 my %h;
2197 \$h{a} = foo();
2198 \($h{b}) = foo();
2199 \local $h{a} = \$x;
2200 \local($h{b}) = \$x;
2201 \@h{'a','b'} = foo();
2202 \(@h{2,3}) = foo();
2203 \local @h{'a','b'} = (\$x)x2;
2204 \@_ = foo();
2205 \@a = foo();
2206 (\@_) = foo();
2207 (\@a) = foo();
2208 \my @c = foo();
2209 (\my @d) = foo();
2210 \(@_) = foo();
2211 \(@a) = foo();
2212 \my(@g) = foo();
2213 \local @_ = \@_;
2214 (\local @_) = \@_;
2215 \state @e = [1..3];
2216 \state(@f) = \3;
2217 \our @i = [1..3];
2218 \our(@h) = \3;
2219 \%_ = foo();
2220 \%h = foo();
2221 (\%_) = foo();
2222 (\%h) = foo();
2223 \my %c = foo();
2224 (\my %d) = foo();
2225 \local %_ = \%h;
2226 (\local %_) = \%h;
2227 \state %y = {1,2};
2228 \our %z = {1,2};
2229 (\our %zz) = {1,2};
2230 \&a = foo();
2231 (\&a) = foo();
2232 \(&a) = foo();
2233 {
2234   my sub a;
2235   \&a = foo();
2236   (\&a) = foo();
2237   \(&a) = foo();
2238 }
2239 (\$_, $_) = \(1, 2);
2240 $_ == 3 ? \$_ : $_ = \3;
2241 $_ == 3 ? \$_ : \$x = \3;
2242 \($_ == 3 ? $_ : $x) = \3;
2243 for \my $topic (\$1, \$2) {
2244     die;
2245 }
2246 for \state $topic (\$1, \$2) {
2247     die;
2248 }
2249 for \our $topic (\$1, \$2) {
2250     die;
2251 }
2252 for \$_ (\$1, \$2) {
2253     die;
2254 }
2255 for \my @a ([1,2], [3,4]) {
2256     die;
2257 }
2258 for \state @a ([1,2], [3,4]) {
2259     die;
2260 }
2261 for \our @a ([1,2], [3,4]) {
2262     die;
2263 }
2264 for \@_ ([1,2], [3,4]) {
2265     die;
2266 }
2267 for \my %a ({5,6}, {7,8}) {
2268     die;
2269 }
2270 for \our %a ({5,6}, {7,8}) {
2271     die;
2272 }
2273 for \state %a ({5,6}, {7,8}) {
2274     die;
2275 }
2276 for \%_ ({5,6}, {7,8}) {
2277     die;
2278 }
2279 {
2280     my sub a;
2281     for \&a (sub { 9; }, sub { 10; }) {
2282         die;
2283     }
2284 }
2285 for \&a (sub { 9; }, sub { 10; }) {
2286     die;
2287 }
2288 >>>>
2289 our $x;
2290 \$x = \$x;
2291 my $m;
2292 \$m = \$x;
2293 \my $n = \$x;
2294 (\$x) = @_;
2295 (\$x) = @_;
2296 (\$m) = @_;
2297 (\$m) = @_;
2298 (\my $p) = @_;
2299 (\my $r) = @_;
2300 (\$x, \my $a) = @{[\$x, \$x];};
2301 (\$x, \my $b) = @{[\$x, \$x];};
2302 \local $x = \3;
2303 (\local $x) = \3;
2304 \state $c = \3;
2305 (\state $d) = \3;
2306 \our $e = \3;
2307 (\our $f) = \3;
2308 \$_[0] = foo();
2309 (\$_[1]) = foo();
2310 my @a;
2311 \$a[0] = foo();
2312 (\$a[1]) = foo();
2313 (\local $a[1]) = foo();
2314 (\@a[0, 1]) = foo();
2315 (\@a[2, 3]) = foo();
2316 (\local @a[0, 1]) = (\$a) x 2;
2317 \$_{'a'} = foo();
2318 (\$_{'b'}) = foo();
2319 my %h;
2320 \$h{'a'} = foo();
2321 (\$h{'b'}) = foo();
2322 \local $h{'a'} = \$x;
2323 (\local $h{'b'}) = \$x;
2324 (\@h{'a', 'b'}) = foo();
2325 (\@h{2, 3}) = foo();
2326 (\local @h{'a', 'b'}) = (\$x) x 2;
2327 \@_ = foo();
2328 \@a = foo();
2329 (\@_) = foo();
2330 (\@a) = foo();
2331 \my @c = foo();
2332 (\my @d) = foo();
2333 (\(@_)) = foo();
2334 (\(@a)) = foo();
2335 (\(my @g)) = foo();
2336 \local @_ = \@_;
2337 (\local @_) = \@_;
2338 \state @e = [1..3];
2339 (\(state @f)) = \3;
2340 \our @i = [1..3];
2341 (\(our @h)) = \3;
2342 \%_ = foo();
2343 \%h = foo();
2344 (\%_) = foo();
2345 (\%h) = foo();
2346 \my %c = foo();
2347 (\my %d) = foo();
2348 \local %_ = \%h;
2349 (\local %_) = \%h;
2350 \state %y = {1, 2};
2351 \our %z = {1, 2};
2352 (\our %zz) = {1, 2};
2353 \&a = foo();
2354 (\&a) = foo();
2355 (\&a) = foo();
2356 {
2357   my sub a;
2358   \&a = foo();
2359   (\&a) = foo();
2360   (\&a) = foo();
2361 }
2362 (\$_, $_) = \(1, 2);
2363 $_ == 3 ? \$_ : $_ = \3;
2364 $_ == 3 ? \$_ : \$x = \3;
2365 ($_ == 3 ? \$_ : \$x) = \3;
2366 foreach \my $topic (\$1, \$2) {
2367     die;
2368 }
2369 foreach \state $topic (\$1, \$2) {
2370     die;
2371 }
2372 foreach \our $topic (\$1, \$2) {
2373     die;
2374 }
2375 foreach \$_ (\$1, \$2) {
2376     die;
2377 }
2378 foreach \my @a ([1, 2], [3, 4]) {
2379     die;
2380 }
2381 foreach \state @a ([1, 2], [3, 4]) {
2382     die;
2383 }
2384 foreach \our @a ([1, 2], [3, 4]) {
2385     die;
2386 }
2387 foreach \@_ ([1, 2], [3, 4]) {
2388     die;
2389 }
2390 foreach \my %a ({5, 6}, {7, 8}) {
2391     die;
2392 }
2393 foreach \our %a ({5, 6}, {7, 8}) {
2394     die;
2395 }
2396 foreach \state %a ({5, 6}, {7, 8}) {
2397     die;
2398 }
2399 foreach \%_ ({5, 6}, {7, 8}) {
2400     die;
2401 }
2402 {
2403     my sub a;
2404     foreach \&a (sub { 9; } , sub { 10; } ) {
2405         die;
2406     }
2407 }
2408 foreach \&a (sub { 9; } , sub { 10; } ) {
2409     die;
2410 }
2411 ####
2412 # join $foo, pos
2413 my $foo;
2414 $_ = join $foo, pos
2415 >>>>
2416 my $foo;
2417 $_ = join('???', pos $_);
2418 ####
2419 # exists $a[0]
2420 our @a;
2421 exists $a[0];
2422 ####
2423 # my @a; exists $a[0]
2424 my @a;
2425 exists $a[0];
2426 ####
2427 # delete $a[0]
2428 our @a;
2429 delete $a[0];
2430 ####
2431 # my @a; delete $a[0]
2432 my @a;
2433 delete $a[0];
2434 ####
2435 # $_[0][$_[1]]
2436 $_[0][$_[1]];
2437 ####
2438 # f($a[0]);
2439 my @a;
2440 f($a[0]);
2441 ####
2442 #qr/\Q$h{'key'}\E/;
2443 my %h;
2444 qr/\Q$h{'key'}\E/;
2445 ####
2446 # my $x = "$h{foo}";
2447 my %h;
2448 my $x = "$h{'foo'}";
2449 ####
2450 # weird constant hash key
2451 my %h;
2452 my $x = $h{"\000\t\x{100}"};
2453 ####
2454 # multideref and packages
2455 package foo;
2456 my(%bar) = ('a', 'b');
2457 our(@bar) = (1, 2);
2458 $bar{'k'} = $bar[200];
2459 $main::bar{'k'} = $main::bar[200];
2460 $foo::bar{'k'} = $foo::bar[200];
2461 package foo2;
2462 $bar{'k'} = $bar[200];
2463 $main::bar{'k'} = $main::bar[200];
2464 $foo::bar{'k'} = $foo::bar[200];
2465 >>>>
2466 package foo;
2467 my(%bar) = ('a', 'b');
2468 our(@bar) = (1, 2);
2469 $bar{'k'} = $bar[200];
2470 $main::bar{'k'} = $main::bar[200];
2471 $foo::bar{'k'} = $bar[200];
2472 package foo2;
2473 $bar{'k'} = $foo::bar[200];
2474 $main::bar{'k'} = $main::bar[200];
2475 $foo::bar{'k'} = $foo::bar[200];
2476 ####
2477 # multideref and local
2478 my %h;
2479 local $h{'foo'}[0] = 1;
2480 ####
2481 # multideref and exists
2482 my(%h, $i);
2483 my $e = exists $h{'foo'}[$i];
2484 ####
2485 # multideref and delete
2486 my(%h, $i);
2487 my $e = delete $h{'foo'}[$i];
2488 ####
2489 # multideref with leading expression
2490 my $r;
2491 my $x = +($r // [])->{'foo'}[0];
2492 ####
2493 # multideref with complex middle index
2494 my(%h, $i, $j, $k);
2495 my $x = $h{'foo'}[$i + $j]{$k};
2496 ####
2497 # multideref with trailing non-simple index that initially looks simple
2498 # (i.e. the constant "3")
2499 my($r, $i, $j, $k);
2500 my $x = +($r || {})->{'foo'}[$i + $j]{3 + $k};
2501 ####
2502 # chdir
2503 chdir 'file';
2504 chdir FH;
2505 chdir;
2506 ####
2507 # 5.22 bitops
2508 # CONTEXT use feature "bitwise"; no warnings "experimental::bitwise";
2509 $_ = $_ | $_;
2510 $_ = $_ & $_;
2511 $_ = $_ ^ $_;
2512 $_ = ~$_;
2513 $_ = $_ |. $_;
2514 $_ = $_ &. $_;
2515 $_ = $_ ^. $_;
2516 $_ = ~.$_;
2517 $_ |= $_;
2518 $_ &= $_;
2519 $_ ^= $_;
2520 $_ |.= $_;
2521 $_ &.= $_;
2522 $_ ^.= $_;
2523 ####
2524 ####
2525 # Should really use 'no warnings "experimental::signatures"',
2526 # but it doesn't yet deparse correctly.
2527 # anon subs used because this test framework doesn't deparse named subs
2528 # in the DATA code snippets.
2529 #
2530 # general signature
2531 no warnings;
2532 use feature 'signatures';
2533 my $x;
2534 sub ($a, $, $b = $glo::bal, $c = $a, $d = 'foo', $e = -37, $f = 0, $g = 1, $h = undef, $i = $a + 1, $j = /foo/, @) {
2535     $x++;
2536 }
2537 ;
2538 $x++;
2539 ####
2540 # Signature and prototype
2541 no warnings;
2542 use feature 'signatures';
2543 my $x;
2544 sub ($a, $b) : prototype($$) {
2545     $x++;
2546 }
2547 ;
2548 $x++;
2549 ####
2550 # Signature and prototype and attrs
2551 no warnings;
2552 use feature 'signatures';
2553 my $x;
2554 sub ($a, $b) : prototype($$) lvalue {
2555     $x++;
2556 }
2557 ;
2558 $x++;
2559 ####
2560 # Signature and attrs
2561 no warnings;
2562 use feature 'signatures';
2563 my $x;
2564 sub ($a, $b) : lvalue method {
2565     $x++;
2566 }
2567 ;
2568 $x++;
2569 ####
2570 # named array slurp, null body
2571 no warnings;
2572 use feature 'signatures';
2573 sub (@a) {
2574     ;
2575 }
2576 ;
2577 ####
2578 # named hash slurp
2579 no warnings;
2580 use feature 'signatures';
2581 sub ($key, %h) {
2582     $h{$key};
2583 }
2584 ;
2585 ####
2586 # anon hash slurp
2587 no warnings;
2588 use feature 'signatures';
2589 sub ($a, %) {
2590     $a;
2591 }
2592 ;
2593 ####
2594 # parenthesised default arg
2595 no warnings;
2596 use feature 'signatures';
2597 sub ($a, $b = (/foo/), $c = 1) {
2598     $a + $b + $c;
2599 }
2600 ;
2601 ####
2602 # parenthesised default arg with TARGMY
2603 no warnings;
2604 use feature 'signatures';
2605 sub ($a, $b = ($a + 1), $c = 1) {
2606     $a + $b + $c;
2607 }
2608 ;
2609 ####
2610 # empty default
2611 no warnings;
2612 use feature 'signatures';
2613 sub ($a, $=) {
2614     $a;
2615 }
2616 ;
2617 ####
2618 # padrange op within pattern code blocks
2619 /(?{ my($x, $y) = (); })/;
2620 my $a;
2621 /$a(?{ my($x, $y) = (); })/;
2622 my $r1 = qr/(?{ my($x, $y) = (); })/;
2623 my $r2 = qr/$a(?{ my($x, $y) = (); })/;
2624 ####
2625 # don't remove pattern whitespace escapes
2626 /a\ b/;
2627 /a\ b/x;
2628 /a\     b/;
2629 /a\     b/x;
2630 ####
2631 # my attributes
2632 my $s1 :foo(f1, f2) bar(b1, b2);
2633 my @a1 :foo(f1, f2) bar(b1, b2);
2634 my %h1 :foo(f1, f2) bar(b1, b2);
2635 my($s2, @a2, %h2) :foo(f1, f2) bar(b1, b2);
2636 ####
2637 # my class attributes
2638 package Foo::Bar;
2639 my Foo::Bar $s1 :foo(f1, f2) bar(b1, b2);
2640 my Foo::Bar @a1 :foo(f1, f2) bar(b1, b2);
2641 my Foo::Bar %h1 :foo(f1, f2) bar(b1, b2);
2642 my Foo::Bar ($s2, @a2, %h2) :foo(f1, f2) bar(b1, b2);
2643 package main;
2644 my Foo::Bar $s3 :foo(f1, f2) bar(b1, b2);
2645 my Foo::Bar @a3 :foo(f1, f2) bar(b1, b2);
2646 my Foo::Bar %h3 :foo(f1, f2) bar(b1, b2);
2647 my Foo::Bar ($s4, @a4, %h4) :foo(f1, f2) bar(b1, b2);
2648 ####
2649 # avoid false positives in my $x :attribute
2650 'attributes'->import('main', \my $x1, 'foo(bar)'), my $y1;
2651 'attributes'->import('Fooo', \my $x2, 'foo(bar)'), my $y2;
2652 ####
2653 # hash slices and hash key/value slices
2654 my(@a, %h);
2655 our(@oa, %oh);
2656 @a = @h{'foo', 'bar'};
2657 @a = %h{'foo', 'bar'};
2658 @a = delete @h{'foo', 'bar'};
2659 @a = delete %h{'foo', 'bar'};
2660 @oa = @oh{'foo', 'bar'};
2661 @oa = %oh{'foo', 'bar'};
2662 @oa = delete @oh{'foo', 'bar'};
2663 @oa = delete %oh{'foo', 'bar'};
2664 ####
2665 # keys optimised away in void and scalar context
2666 no warnings;
2667 ;
2668 our %h1;
2669 my($x, %h2);
2670 %h1;
2671 keys %h1;
2672 $x = %h1;
2673 $x = keys %h1;
2674 %h2;
2675 keys %h2;
2676 $x = %h2;
2677 $x = keys %h2;
2678 ####
2679 # eq,const optimised away for (index() == -1)
2680 my($a, $b);
2681 our $c;
2682 $c = index($a, $b) == 2;
2683 $c = rindex($a, $b) == 2;
2684 $c = index($a, $b) == -1;
2685 $c = rindex($a, $b) == -1;
2686 $c = index($a, $b) != -1;
2687 $c = rindex($a, $b) != -1;
2688 $c = (index($a, $b) == -1);
2689 $c = (rindex($a, $b) == -1);
2690 $c = (index($a, $b) != -1);
2691 $c = (rindex($a, $b) != -1);
2692 ####
2693 # eq,const,sassign,madmy optimised away for (index() == -1)
2694 my($a, $b);
2695 my $c;
2696 $c = index($a, $b) == 2;
2697 $c = rindex($a, $b) == 2;
2698 $c = index($a, $b) == -1;
2699 $c = rindex($a, $b) == -1;
2700 $c = index($a, $b) != -1;
2701 $c = rindex($a, $b) != -1;
2702 $c = (index($a, $b) == -1);
2703 $c = (rindex($a, $b) == -1);
2704 $c = (index($a, $b) != -1);
2705 $c = (rindex($a, $b) != -1);