This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
lib/B/Deparse.pm: Output WARNING_BITS in binary
[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 = 44; # 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 # Sub calls compiled before importation
335 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
336              prog => 'BEGIN {
337                        require Test::More;
338                        Test::More::->import;
339                        is(*foo, *foo)
340                      }'),
341      qr/&is\(/,
342     'sub calls compiled before importation of prototype subs';
343
344 # [perl #121050] Prototypes with whitespace
345 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
346            prog => <<'EOCODO'),
347 sub _121050(\$ \$) { }
348 _121050($a,$b);
349 sub _121050empty( ) {}
350 () = _121050empty() + 1;
351 EOCODO
352    <<'EOCODP', '[perl #121050] prototypes with whitespace';
353 sub _121050 (\$ \$) {
354     
355 }
356 _121050 $a, $b;
357 sub _121050empty ( ) {
358     
359 }
360 () = _121050empty + 1;
361 EOCODP
362
363 # CORE::no
364 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
365              .qq`"use feature q|:all|; my sub no; CORE::no less" 2>&1`;
366 like($a, qr/my sub no;\nCORE::no less;/,
367     'CORE::no after my sub no');
368
369 # CORE::use
370 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
371              .qq`"use feature q|:all|; my sub use; CORE::use less" 2>&1`;
372 like($a, qr/my sub use;\nCORE::use less;/,
373     'CORE::use after my sub use');
374
375 # CORE::__DATA__
376 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
377              .qq`"use feature q|:all|; my sub __DATA__; `
378              .qq`CORE::__DATA__" 2>&1`;
379 like($a, qr/my sub __DATA__;\n.*\nCORE::__DATA__/s,
380     'CORE::__DATA__ after my sub __DATA__');
381
382 # sub declarations
383 $a = readpipe qq`$^X $path "-MO=Deparse" -e "sub foo{}" 2>&1`;
384 like($a, qr/sub foo\s*\{\s+\}/, 'sub declarations');
385 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
386            prog => 'sub f($); sub f($){}'),
387      qr/sub f\s*\(\$\)\s*\{\s*\}/,
388     'predeclared prototyped subs';
389 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
390            prog => 'use Scalar::Util q-weaken-;
391                     sub f($);
392                     BEGIN { weaken($_=\$::{f}) }'),
393      qr/sub f\s*\(\$\)\s*;/,
394     'prototyped stub with weak reference to the stash entry';
395 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
396            prog => 'sub f () { 42 }'),
397      qr/sub f\s*\(\)\s*\{\s*42;\s*\}/,
398     'constant perl sub declaration';
399
400 # BEGIN blocks
401 SKIP : {
402     skip "BEGIN output is wrong on old perls", 1 if $] < 5.021006;
403     my $prog = '
404       BEGIN { pop }
405       {
406         BEGIN { pop }
407         {
408           no overloading;
409           {
410             BEGIN { pop }
411             die
412           }
413         }
414       }';
415     $prog =~ s/\n//g;
416     $a = readpipe qq`$^X $path "-MO=Deparse" -e "$prog" 2>&1`;
417     $a =~ s/-e syntax OK\n//g;
418     is($a, <<'EOCODJ', 'BEGIN blocks');
419 sub BEGIN {
420     pop @ARGV;
421 }
422 {
423     sub BEGIN {
424         pop @ARGV;
425     }
426     {
427         no overloading;
428         {
429             sub BEGIN {
430                 pop @ARGV;
431             }
432             die;
433         }
434     }
435 }
436 EOCODJ
437 }
438 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ], prog => '
439       {
440         {
441           die;
442           BEGIN { pop }
443         }
444         BEGIN { pop }
445       }
446       BEGIN { pop }
447   '), <<'EOCODL', 'BEGIN blocks at the end of their enclosing blocks';
448 {
449     {
450         die;
451         sub BEGIN {
452             pop @ARGV;
453         }
454     }
455     sub BEGIN {
456         pop @ARGV;
457     }
458 }
459 sub BEGIN {
460     pop @ARGV;
461 }
462 EOCODL
463
464 # BEGIN blocks should not be called __ANON__
465 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
466              prog => 'sub BEGIN { } CHECK { delete $::{BEGIN} }'),
467      qr/sub BEGIN/, 'anonymised BEGIN';
468
469 # [perl #115066]
470 my $prog = 'use constant FOO => do { 1 }; no overloading; die';
471 $a = readpipe qq`$^X $path "-MO=-qq,Deparse" -e "$prog" 2>&1`;
472 is($a, <<'EOCODK', '[perl #115066] use statements accidentally nested');
473 use constant ('FOO', do {
474     1
475 });
476 no overloading;
477 die;
478 EOCODK
479
480 # BEGIN blocks inside predeclared subs
481 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
482              prog => '
483                  sub run_tests;
484                  run_tests();
485                  sub run_tests { BEGIN { } die }'),
486      qr/sub run_tests \{\s*sub BEGIN/,
487     'BEGIN block inside predeclared sub';
488
489 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
490              prog => 'package foo; use overload qr=>sub{}'),
491      qr/package foo;\s*use overload/,
492     'package, then use';
493
494 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
495              prog => 'use feature lexical_subs=>; my sub f;sub main::f{}'),
496      qr/^sub main::f \{/m,
497     'sub decl when lex sub is in scope';
498
499 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
500              prog => 'sub foo{foo()}'),
501      qr/^sub foo \{\s+foo\(\)/m,
502     'recursive sub';
503
504 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
505            prog => '$x =~ (1?/$a/:0)'),
506   '$x =~ ($_ =~ /$a/);'."\n",
507   '$foo =~ <branch-folded match> under taint mode';
508
509 unlike runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-w' ],
510                prog => 'BEGIN { undef &foo }'),
511        qr'Use of uninitialized value',
512       'no warnings for undefined sub';
513
514 done_testing($tests);
515
516 __DATA__
517 # TODO [perl #120950] This succeeds when run a 2nd time
518 # y/uni/code/
519 tr/\x{345}/\x{370}/;
520 ####
521 # y/uni/code/  [perl #120950] This 2nd instance succeeds
522 tr/\x{345}/\x{370}/;
523 ####
524 # A constant
525 1;
526 ####
527 # Constants in a block
528 # CONTEXT no warnings;
529 {
530     '???';
531     2;
532 }
533 ####
534 # List of constants in void context
535 # CONTEXT no warnings;
536 (1,2,3);
537 0;
538 >>>>
539 '???', '???', '???';
540 0;
541 ####
542 # Lexical and simple arithmetic
543 my $test;
544 ++$test and $test /= 2;
545 >>>>
546 my $test;
547 $test /= 2 if ++$test;
548 ####
549 # list x
550 -((1, 2) x 2);
551 ####
552 # Assignment to list x
553 ((undef) x 3) = undef;
554 ####
555 # lvalue sub
556 {
557     my $test = sub : lvalue {
558         my $x;
559     }
560     ;
561 }
562 ####
563 # method
564 {
565     my $test = sub : method {
566         my $x;
567     }
568     ;
569 }
570 ####
571 # anonsub attrs at statement start
572 my $x = do { +sub : lvalue { my $y; } };
573 my $z = do { foo: +sub : method { my $a; } };
574 ####
575 # block with continue
576 {
577     234;
578 }
579 continue {
580     123;
581 }
582 ####
583 # lexical and package scalars
584 my $x;
585 print $main::x;
586 ####
587 # lexical and package arrays
588 my @x;
589 print $main::x[1];
590 print \my @a;
591 ####
592 # lexical and package hashes
593 my %x;
594 $x{warn()};
595 ####
596 # our (LIST)
597 our($foo, $bar, $baz);
598 ####
599 # CONTEXT { package Dog } use feature "state";
600 # variables with declared classes
601 my Dog $spot;
602 our Dog $spotty;
603 state Dog $spotted;
604 my Dog @spot;
605 our Dog @spotty;
606 state Dog @spotted;
607 my Dog %spot;
608 our Dog %spotty;
609 state Dog %spotted;
610 my Dog ($foo, @bar, %baz);
611 our Dog ($phoo, @barr, %bazz);
612 state Dog ($fough, @barre, %bazze);
613 ####
614 # local our
615 local our $rhubarb;
616 local our($rhu, $barb);
617 ####
618 # <>
619 my $foo;
620 $_ .= <ARGV> . <$foo>;
621 ####
622 # readline
623 readline 'FH';
624 readline *$_;
625 readline *{$_;};
626 ####
627 # \x{}
628 my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
629 my $bar = "\x{100}";
630 ####
631 # Latin-1 chars
632 # TODO ? ord("A") != 65 && "EBCDIC"
633 my $baz = "B\366\x{100}";
634 my $bba = qr/B\366\x{100}/;
635 ####
636 # s///e
637 s/x/'y';/e;
638 s/x/$a;/e;
639 s/x/complex_expression();/e;
640 ####
641 # block
642 { my $x; }
643 ####
644 # while 1
645 while (1) { my $k; }
646 ####
647 # trailing for
648 my ($x,@a);
649 $x=1 for @a;
650 >>>>
651 my($x, @a);
652 $x = 1 foreach (@a);
653 ####
654 # 2 arguments in a 3 argument for
655 for (my $i = 0; $i < 2;) {
656     my $z = 1;
657 }
658 ####
659 # 3 argument for
660 for (my $i = 0; $i < 2; ++$i) {
661     my $z = 1;
662 }
663 ####
664 # 3 argument for again
665 for (my $i = 0; $i < 2; ++$i) {
666     my $z = 1;
667 }
668 ####
669 # 3-argument for with inverted condition
670 for (my $i; not $i;) {
671     die;
672 }
673 for (my $i; not $i; ++$i) {
674     die;
675 }
676 for (my $a; not +($1 || 2) ** 2;) {
677     die;
678 }
679 Something_to_put_the_loop_in_void_context();
680 ####
681 # while/continue
682 my $i;
683 while ($i) { my $z = 1; } continue { $i = 99; }
684 ####
685 # foreach with my
686 foreach my $i (1, 2) {
687     my $z = 1;
688 }
689 ####
690 # OPTIONS -p
691 # foreach with my under -p
692 foreach my $i (1) {
693     die;
694 }
695 ####
696 # foreach
697 my $i;
698 foreach $i (1, 2) {
699     my $z = 1;
700 }
701 ####
702 # foreach, 2 mys
703 my $i;
704 foreach my $i (1, 2) {
705     my $z = 1;
706 }
707 ####
708 # foreach with our
709 foreach our $i (1, 2) {
710     my $z = 1;
711 }
712 ####
713 # foreach with my and our
714 my $i;
715 foreach our $i (1, 2) {
716     my $z = 1;
717 }
718 ####
719 # foreach with state
720 # CONTEXT use feature "state";
721 foreach state $i (1, 2) {
722     state $z = 1;
723 }
724 ####
725 # foreach with sub call
726 foreach $_ (hcaerof()) {
727     ();
728 }
729 ####
730 # reverse sort
731 my @x;
732 print reverse sort(@x);
733 ####
734 # sort with cmp
735 my @x;
736 print((sort {$b cmp $a} @x));
737 ####
738 # reverse sort with block
739 my @x;
740 print((reverse sort {$b <=> $a} @x));
741 ####
742 # foreach reverse
743 our @a;
744 print $_ foreach (reverse @a);
745 ####
746 # foreach reverse (not inplace)
747 our @a;
748 print $_ foreach (reverse 1, 2..5);
749 ####
750 # bug #38684
751 our @ary;
752 @ary = split(' ', 'foo', 0);
753 ####
754 # Split to our array
755 our @array = split(//, 'foo', 0);
756 ####
757 # Split to my array
758 my @array  = split(//, 'foo', 0);
759 ####
760 # bug #40055
761 do { () }; 
762 ####
763 # bug #40055
764 do { my $x = 1; $x }; 
765 ####
766 # <20061012113037.GJ25805@c4.convolution.nl>
767 my $f = sub {
768     +{[]};
769 } ;
770 ####
771 # bug #43010
772 '!@$%'->();
773 ####
774 # bug #43010
775 ::();
776 ####
777 # bug #43010
778 '::::'->();
779 ####
780 # bug #43010
781 &::::;
782 ####
783 # [perl #77172]
784 package rt77172;
785 sub foo {} foo & & & foo;
786 >>>>
787 package rt77172;
788 foo(&{&} & foo());
789 ####
790 # variables as method names
791 my $bar;
792 'Foo'->$bar('orz');
793 'Foo'->$bar('orz') = 'a stranger stranger than before';
794 ####
795 # constants as method names
796 'Foo'->bar('orz');
797 ####
798 # constants as method names without ()
799 'Foo'->bar;
800 ####
801 # [perl #47359] "indirect" method call notation
802 our @bar;
803 foo{@bar}+1,->foo;
804 (foo{@bar}+1),foo();
805 foo{@bar}1 xor foo();
806 >>>>
807 our @bar;
808 (foo { @bar } 1)->foo;
809 (foo { @bar } 1), foo();
810 foo { @bar } 1 xor foo();
811 ####
812 # indirops with blocks
813 # CONTEXT use 5.01;
814 print {*STDOUT;} 'foo';
815 printf {*STDOUT;} 'foo';
816 say {*STDOUT;} 'foo';
817 system {'foo';} '-foo';
818 exec {'foo';} '-foo';
819 ####
820 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
821 # CONTEXT use feature ':5.10';
822 # say
823 say 'foo';
824 ####
825 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
826 # CONTEXT use 5.10.0;
827 # say in the context of use 5.10.0
828 say 'foo';
829 ####
830 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
831 # say with use 5.10.0
832 use 5.10.0;
833 say 'foo';
834 >>>>
835 no feature ':all';
836 use feature ':5.10';
837 say 'foo';
838 ####
839 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
840 # say with use feature ':5.10';
841 use feature ':5.10';
842 say 'foo';
843 >>>>
844 use feature 'say', 'state', 'switch';
845 say 'foo';
846 ####
847 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
848 # CONTEXT use feature ':5.10';
849 # say with use 5.10.0 in the context of use feature
850 use 5.10.0;
851 say 'foo';
852 >>>>
853 no feature ':all';
854 use feature ':5.10';
855 say 'foo';
856 ####
857 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
858 # CONTEXT use 5.10.0;
859 # say with use feature ':5.10' in the context of use 5.10.0
860 use feature ':5.10';
861 say 'foo';
862 >>>>
863 say 'foo';
864 ####
865 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
866 # CONTEXT use feature ':5.15';
867 # __SUB__
868 __SUB__;
869 ####
870 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
871 # CONTEXT use 5.15.0;
872 # __SUB__ in the context of use 5.15.0
873 __SUB__;
874 ####
875 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
876 # __SUB__ with use 5.15.0
877 use 5.15.0;
878 __SUB__;
879 >>>>
880 no feature ':all';
881 use feature ':5.16';
882 __SUB__;
883 ####
884 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
885 # __SUB__ with use feature ':5.15';
886 use feature ':5.15';
887 __SUB__;
888 >>>>
889 use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
890 __SUB__;
891 ####
892 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
893 # CONTEXT use feature ':5.15';
894 # __SUB__ with use 5.15.0 in the context of use feature
895 use 5.15.0;
896 __SUB__;
897 >>>>
898 no feature ':all';
899 use feature ':5.16';
900 __SUB__;
901 ####
902 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
903 # CONTEXT use 5.15.0;
904 # __SUB__ with use feature ':5.15' in the context of use 5.15.0
905 use feature ':5.15';
906 __SUB__;
907 >>>>
908 __SUB__;
909 ####
910 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
911 # CONTEXT use feature ':5.10';
912 # state vars
913 state $x = 42;
914 ####
915 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
916 # CONTEXT use feature ':5.10';
917 # state var assignment
918 {
919     my $y = (state $x = 42);
920 }
921 ####
922 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
923 # CONTEXT use feature ':5.10';
924 # state vars in anonymous subroutines
925 $a = sub {
926     state $x;
927     return $x++;
928 }
929 ;
930 ####
931 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
932 # each @array;
933 each @ARGV;
934 each @$a;
935 ####
936 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
937 # keys @array; values @array
938 keys @$a if keys @ARGV;
939 values @ARGV if values @$a;
940 ####
941 # Anonymous arrays and hashes, and references to them
942 my $a = {};
943 my $b = \{};
944 my $c = [];
945 my $d = \[];
946 ####
947 # SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
948 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
949 # implicit smartmatch in given/when
950 given ('foo') {
951     when ('bar') { continue; }
952     when ($_ ~~ 'quux') { continue; }
953     default { 0; }
954 }
955 ####
956 # conditions in elsifs (regression in change #33710 which fixed bug #37302)
957 if ($a) { x(); }
958 elsif ($b) { x(); }
959 elsif ($a and $b) { x(); }
960 elsif ($a or $b) { x(); }
961 else { x(); }
962 ####
963 # interpolation in regexps
964 my($y, $t);
965 /x${y}z$t/;
966 ####
967 # TODO new undocumented cpan-bug #33708
968 # cpan-bug #33708
969 %{$_ || {}}
970 ####
971 # TODO hash constants not yet fixed
972 # cpan-bug #33708
973 use constant H => { "#" => 1 }; H->{"#"}
974 ####
975 # TODO optimized away 0 not yet fixed
976 # cpan-bug #33708
977 foreach my $i (@_) { 0 }
978 ####
979 # tests with not, not optimized
980 my $c;
981 x() unless $a;
982 x() if not $a and $b;
983 x() if $a and not $b;
984 x() unless not $a and $b;
985 x() unless $a and not $b;
986 x() if not $a or $b;
987 x() if $a or not $b;
988 x() unless not $a or $b;
989 x() unless $a or not $b;
990 x() if $a and not $b and $c;
991 x() if not $a and $b and not $c;
992 x() unless $a and not $b and $c;
993 x() unless not $a and $b and not $c;
994 x() if $a or not $b or $c;
995 x() if not $a or $b or not $c;
996 x() unless $a or not $b or $c;
997 x() unless not $a or $b or not $c;
998 ####
999 # tests with not, optimized
1000 my $c;
1001 x() if not $a;
1002 x() unless not $a;
1003 x() if not $a and not $b;
1004 x() unless not $a and not $b;
1005 x() if not $a or not $b;
1006 x() unless not $a or not $b;
1007 x() if not $a and not $b and $c;
1008 x() unless not $a and not $b and $c;
1009 x() if not $a or not $b or $c;
1010 x() unless not $a or not $b or $c;
1011 x() if not $a and not $b and not $c;
1012 x() unless not $a and not $b and not $c;
1013 x() if not $a or not $b or not $c;
1014 x() unless not $a or not $b or not $c;
1015 x() unless not $a or not $b or not $c;
1016 >>>>
1017 my $c;
1018 x() unless $a;
1019 x() if $a;
1020 x() unless $a or $b;
1021 x() if $a or $b;
1022 x() unless $a and $b;
1023 x() if $a and $b;
1024 x() if not $a || $b and $c;
1025 x() unless not $a || $b and $c;
1026 x() if not $a && $b or $c;
1027 x() unless not $a && $b or $c;
1028 x() unless $a or $b or $c;
1029 x() if $a or $b or $c;
1030 x() unless $a and $b and $c;
1031 x() if $a and $b and $c;
1032 x() unless not $a && $b && $c;
1033 ####
1034 # tests that should be constant folded
1035 x() if 1;
1036 x() if GLIPP;
1037 x() if !GLIPP;
1038 x() if GLIPP && GLIPP;
1039 x() if !GLIPP || GLIPP;
1040 x() if do { GLIPP };
1041 x() if do { no warnings 'void'; 5; GLIPP };
1042 x() if do { !GLIPP };
1043 if (GLIPP) { x() } else { z() }
1044 if (!GLIPP) { x() } else { z() }
1045 if (GLIPP) { x() } elsif (GLIPP) { z() }
1046 if (!GLIPP) { x() } elsif (GLIPP) { z() }
1047 if (GLIPP) { x() } elsif (!GLIPP) { z() }
1048 if (!GLIPP) { x() } elsif (!GLIPP) { z() }
1049 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
1050 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
1051 if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
1052 >>>>
1053 x();
1054 x();
1055 '???';
1056 x();
1057 x();
1058 x();
1059 x();
1060 do {
1061     '???'
1062 };
1063 do {
1064     x()
1065 };
1066 do {
1067     z()
1068 };
1069 do {
1070     x()
1071 };
1072 do {
1073     z()
1074 };
1075 do {
1076     x()
1077 };
1078 '???';
1079 do {
1080     t()
1081 };
1082 '???';
1083 !1;
1084 ####
1085 # TODO constant deparsing has been backed out for 5.12
1086 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
1087 # tests that shouldn't be constant folded
1088 # It might be fundamentally impossible to make this work on ithreads, in which
1089 # case the TODO should become a SKIP
1090 x() if $a;
1091 if ($a == 1) { x() } elsif ($b == 2) { z() }
1092 if (do { foo(); GLIPP }) { x() }
1093 if (do { $a++; GLIPP }) { x() }
1094 >>>>
1095 x() if $a;
1096 if ($a == 1) { x(); } elsif ($b == 2) { z(); }
1097 if (do { foo(); GLIPP }) { x(); }
1098 if (do { ++$a; GLIPP }) { x(); }
1099 ####
1100 # TODO constant deparsing has been backed out for 5.12
1101 # tests for deparsing constants
1102 warn PI;
1103 ####
1104 # TODO constant deparsing has been backed out for 5.12
1105 # tests for deparsing imported constants
1106 warn O_TRUNC;
1107 ####
1108 # TODO constant deparsing has been backed out for 5.12
1109 # tests for deparsing re-exported constants
1110 warn O_CREAT;
1111 ####
1112 # TODO constant deparsing has been backed out for 5.12
1113 # tests for deparsing imported constants that got deleted from the original namespace
1114 warn O_APPEND;
1115 ####
1116 # TODO constant deparsing has been backed out for 5.12
1117 # XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
1118 # tests for deparsing constants which got turned into full typeglobs
1119 # It might be fundamentally impossible to make this work on ithreads, in which
1120 # case the TODO should become a SKIP
1121 warn O_EXCL;
1122 eval '@Fcntl::O_EXCL = qw/affe tiger/;';
1123 warn O_EXCL;
1124 ####
1125 # TODO constant deparsing has been backed out for 5.12
1126 # tests for deparsing of blessed constant with overloaded numification
1127 warn OVERLOADED_NUMIFICATION;
1128 ####
1129 # strict
1130 no strict;
1131 print $x;
1132 use strict 'vars';
1133 print $main::x;
1134 use strict 'subs';
1135 print $main::x;
1136 use strict 'refs';
1137 print $main::x;
1138 no strict 'vars';
1139 $x;
1140 ####
1141 # TODO Subsets of warnings could be encoded textually, rather than as bitflips.
1142 # subsets of warnings
1143 no warnings 'deprecated';
1144 my $x;
1145 ####
1146 # TODO Better test for CPAN #33708 - the deparsed code has different behaviour
1147 # CPAN #33708
1148 use strict;
1149 no warnings;
1150
1151 foreach (0..3) {
1152     my $x = 2;
1153     {
1154         my $x if 0;
1155         print ++$x, "\n";
1156     }
1157 }
1158 ####
1159 # no attribute list
1160 my $pi = 4;
1161 ####
1162 # SKIP ?$] > 5.013006 && ":= is now a syntax error"
1163 # := treated as an empty attribute list
1164 no warnings;
1165 my $pi := 4;
1166 >>>>
1167 no warnings;
1168 my $pi = 4;
1169 ####
1170 # : = empty attribute list
1171 my $pi : = 4;
1172 >>>>
1173 my $pi = 4;
1174 ####
1175 # in place sort
1176 our @a;
1177 my @b;
1178 @a = sort @a;
1179 @b = sort @b;
1180 ();
1181 ####
1182 # in place reverse
1183 our @a;
1184 my @b;
1185 @a = reverse @a;
1186 @b = reverse @b;
1187 ();
1188 ####
1189 # #71870 Use of uninitialized value in bitwise and B::Deparse
1190 my($r, $s, @a);
1191 @a = split(/foo/, $s, 0);
1192 $r = qr/foo/;
1193 @a = split(/$r/, $s, 0);
1194 ();
1195 ####
1196 # package declaration before label
1197 {
1198     package Foo;
1199     label: print 123;
1200 }
1201 ####
1202 # shift optimisation
1203 shift;
1204 >>>>
1205 shift();
1206 ####
1207 # shift optimisation
1208 shift @_;
1209 ####
1210 # shift optimisation
1211 pop;
1212 >>>>
1213 pop();
1214 ####
1215 # shift optimisation
1216 pop @_;
1217 ####
1218 #[perl #20444]
1219 "foo" =~ (1 ? /foo/ : /bar/);
1220 "foo" =~ (1 ? y/foo// : /bar/);
1221 "foo" =~ (1 ? y/foo//r : /bar/);
1222 "foo" =~ (1 ? s/foo// : /bar/);
1223 >>>>
1224 'foo' =~ ($_ =~ /foo/);
1225 'foo' =~ ($_ =~ tr/fo//);
1226 'foo' =~ ($_ =~ tr/fo//r);
1227 'foo' =~ ($_ =~ s/foo//);
1228 ####
1229 # The fix for [perl #20444] broke this.
1230 'foo' =~ do { () };
1231 ####
1232 # [perl #81424] match against aelemfast_lex
1233 my @s;
1234 print /$s[1]/;
1235 ####
1236 # /$#a/
1237 print /$#main::a/;
1238 ####
1239 # /@array/
1240 our @a;
1241 my @b;
1242 print /@a/;
1243 print /@b/;
1244 print qr/@a/;
1245 print qr/@b/;
1246 ####
1247 # =~ QR_CONSTANT
1248 use constant QR_CONSTANT => qr/a/soupmix;
1249 '' =~ QR_CONSTANT;
1250 >>>>
1251 '' =~ /a/impsux;
1252 ####
1253 # $lexical =~ //
1254 my $x;
1255 $x =~ //;
1256 ####
1257 # [perl #91318] /regexp/applaud
1258 print /a/a, s/b/c/a;
1259 print /a/aa, s/b/c/aa;
1260 print /a/p, s/b/c/p;
1261 print /a/l, s/b/c/l;
1262 print /a/u, s/b/c/u;
1263 {
1264     use feature "unicode_strings";
1265     print /a/d, s/b/c/d;
1266 }
1267 {
1268     use re "/u";
1269     print /a/d, s/b/c/d;
1270 }
1271 {
1272     use 5.012;
1273     print /a/d, s/b/c/d;
1274 }
1275 >>>>
1276 print /a/a, s/b/c/a;
1277 print /a/aa, s/b/c/aa;
1278 print /a/p, s/b/c/p;
1279 print /a/l, s/b/c/l;
1280 print /a/u, s/b/c/u;
1281 {
1282     use feature 'unicode_strings';
1283     print /a/d, s/b/c/d;
1284 }
1285 {
1286     BEGIN { $^H{'reflags'}         = '0';
1287             $^H{'reflags_charset'} = '2'; }
1288     print /a/d, s/b/c/d;
1289 }
1290 {
1291     no feature ':all';
1292     use feature ':5.12';
1293     print /a/d, s/b/c/d;
1294 }
1295 ####
1296 # [perl #119807] s//\(3)/ge should not warn when deparsed (\3 warns)
1297 s/foo/\(3);/eg;
1298 ####
1299 # [perl #115256]
1300 "" =~ /a(?{ print q|
1301 |})/;
1302 >>>>
1303 '' =~ /a(?{ print "\n"; })/;
1304 ####
1305 # [perl #123217]
1306 $_ = qr/(??{<<END})/
1307 f.o
1308 b.r
1309 END
1310 >>>>
1311 $_ = qr/(??{ "f.o\nb.r\n"; })/;
1312 ####
1313 # More regexp code block madness
1314 my($b, @a);
1315 /(?{ die $b; })/;
1316 /a(?{ die $b; })a/;
1317 /$a(?{ die $b; })/;
1318 /@a(?{ die $b; })/;
1319 /(??{ die $b; })/;
1320 /a(??{ die $b; })a/;
1321 /$a(??{ die $b; })/;
1322 /@a(??{ die $b; })/;
1323 qr/(?{ die $b; })/;
1324 qr/a(?{ die $b; })a/;
1325 qr/$a(?{ die $b; })/;
1326 qr/@a(?{ die $b; })/;
1327 qr/(??{ die $b; })/;
1328 qr/a(??{ die $b; })a/;
1329 qr/$a(??{ die $b; })/;
1330 qr/@a(??{ die $b; })/;
1331 s/(?{ die $b; })//;
1332 s/a(?{ die $b; })a//;
1333 s/$a(?{ die $b; })//;
1334 s/@a(?{ die $b; })//;
1335 s/(??{ die $b; })//;
1336 s/a(??{ die $b; })a//;
1337 s/$a(??{ die $b; })//;
1338 s/@a(??{ die $b; })//;
1339 ####
1340 # /(?x)<newline><tab>/
1341 /(?x)
1342         /;
1343 ####
1344 # y///r
1345 tr/a/b/r + $a =~ tr/p/q/r;
1346 ####
1347 # y///d in list [perl #119815]
1348 () = tr/a//d;
1349 ####
1350 # [perl #90898]
1351 <a,>;
1352 ####
1353 # [perl #91008]
1354 # CONTEXT no warnings 'experimental::autoderef';
1355 each $@;
1356 keys $~;
1357 values $!;
1358 ####
1359 # readpipe with complex expression
1360 readpipe $a + $b;
1361 ####
1362 # aelemfast
1363 $b::a[0] = 1;
1364 ####
1365 # aelemfast for a lexical
1366 my @a;
1367 $a[0] = 1;
1368 ####
1369 # feature features without feature
1370 # CONTEXT no warnings 'experimental::smartmatch';
1371 CORE::state $x;
1372 CORE::say $x;
1373 CORE::given ($x) {
1374     CORE::when (3) {
1375         continue;
1376     }
1377     CORE::default {
1378         CORE::break;
1379     }
1380 }
1381 CORE::evalbytes '';
1382 () = CORE::__SUB__;
1383 () = CORE::fc $x;
1384 ####
1385 # feature features when feature has been disabled by use VERSION
1386 # CONTEXT no warnings 'experimental::smartmatch';
1387 use feature (sprintf(":%vd", $^V));
1388 use 1;
1389 CORE::say $_;
1390 CORE::state $x;
1391 CORE::given ($x) {
1392     CORE::when (3) {
1393         continue;
1394     }
1395     CORE::default {
1396         CORE::break;
1397     }
1398 }
1399 CORE::evalbytes '';
1400 () = CORE::__SUB__;
1401 >>>>
1402 CORE::say $_;
1403 CORE::state $x;
1404 CORE::given ($x) {
1405     CORE::when (3) {
1406         continue;
1407     }
1408     CORE::default {
1409         CORE::break;
1410     }
1411 }
1412 CORE::evalbytes '';
1413 () = CORE::__SUB__;
1414 ####
1415 # (the above test with CONTEXT, and the output is equivalent but different)
1416 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
1417 # feature features when feature has been disabled by use VERSION
1418 use feature (sprintf(":%vd", $^V));
1419 use 1;
1420 CORE::say $_;
1421 CORE::state $x;
1422 CORE::given ($x) {
1423     CORE::when (3) {
1424         continue;
1425     }
1426     CORE::default {
1427         CORE::break;
1428     }
1429 }
1430 CORE::evalbytes '';
1431 () = CORE::__SUB__;
1432 >>>>
1433 no feature ':all';
1434 use feature ':default';
1435 CORE::say $_;
1436 CORE::state $x;
1437 CORE::given ($x) {
1438     CORE::when (3) {
1439         continue;
1440     }
1441     CORE::default {
1442         CORE::break;
1443     }
1444 }
1445 CORE::evalbytes '';
1446 () = CORE::__SUB__;
1447 ####
1448 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1449 # lexical subroutines and keywords of the same name
1450 # CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental';
1451 my sub default;
1452 my sub else;
1453 my sub elsif;
1454 my sub for;
1455 my sub foreach;
1456 my sub given;
1457 my sub if;
1458 my sub m;
1459 my sub no;
1460 my sub package;
1461 my sub q;
1462 my sub qq;
1463 my sub qr;
1464 my sub qx;
1465 my sub require;
1466 my sub s;
1467 my sub sub;
1468 my sub tr;
1469 my sub unless;
1470 my sub until;
1471 my sub use;
1472 my sub when;
1473 my sub while;
1474 CORE::default { die; }
1475 CORE::if ($1) { die; }
1476 CORE::if ($1) { die; }
1477 CORE::elsif ($1) { die; }
1478 CORE::else { die; }
1479 CORE::for (die; $1; die) { die; }
1480 CORE::foreach $_ (1 .. 10) { die; }
1481 die CORE::foreach (1);
1482 CORE::given ($1) { die; }
1483 CORE::m[/];
1484 CORE::m?/?;
1485 CORE::package foo;
1486 CORE::no strict;
1487 () = (CORE::q['], CORE::qq["$_], CORE::qr//, CORE::qx[`]);
1488 CORE::require 1;
1489 CORE::s///;
1490 () = CORE::sub { die; } ;
1491 CORE::tr///;
1492 CORE::unless ($1) { die; }
1493 CORE::until ($1) { die; }
1494 die CORE::until $1;
1495 CORE::use strict;
1496 CORE::when ($1 ~~ $2) { die; }
1497 CORE::while ($1) { die; }
1498 die CORE::while $1;
1499 ####
1500 # Feature hints
1501 use feature 'current_sub', 'evalbytes';
1502 print;
1503 use 1;
1504 print;
1505 use 5.014;
1506 print;
1507 no feature 'unicode_strings';
1508 print;
1509 >>>>
1510 use feature 'current_sub', 'evalbytes';
1511 print $_;
1512 no feature ':all';
1513 use feature ':default';
1514 print $_;
1515 no feature ':all';
1516 use feature ':5.12';
1517 print $_;
1518 no feature 'unicode_strings';
1519 print $_;
1520 ####
1521 # $#- $#+ $#{%} etc.
1522 my @x;
1523 @x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
1524 @x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
1525 @x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
1526 @x = ($#{;}, $#{:}, $#{1});
1527 ####
1528 # ${#} interpolated
1529 # It's a known TODO that warnings are deparsed as bits, not textually.
1530 no warnings;
1531 () = "${#}a";
1532 ####
1533 # [perl #86060] $( $| $) in regexps need braces
1534 /${(}/;
1535 /${|}/;
1536 /${)}/;
1537 /${(}${|}${)}/;
1538 /@{+}@{-}/;
1539 ####
1540 # ()[...]
1541 my(@a) = ()[()];
1542 ####
1543 # sort(foo(bar))
1544 # sort(foo(bar)) is interpreted as sort &foo(bar)
1545 # sort foo(bar) is interpreted as sort foo bar
1546 # parentheses are not optional in this case
1547 print sort(foo('bar'));
1548 >>>>
1549 print sort(foo('bar'));
1550 ####
1551 # substr assignment
1552 substr(my $a, 0, 0) = (foo(), bar());
1553 $a++;
1554 ####
1555 # This following line works around an unfixed bug that we are not trying to 
1556 # test for here:
1557 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1558 # hint hash
1559 BEGIN { $^H{'foo'} = undef; }
1560 {
1561  BEGIN { $^H{'bar'} = undef; }
1562  {
1563   BEGIN { $^H{'baz'} = undef; }
1564   {
1565    print $_;
1566   }
1567   print $_;
1568  }
1569  print $_;
1570 }
1571 BEGIN { $^H{q[']} = '('; }
1572 print $_;
1573 ####
1574 # This following line works around an unfixed bug that we are not trying to 
1575 # test for here:
1576 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1577 # hint hash changes that serialise the same way with sort %hh
1578 BEGIN { $^H{'a'} = 'b'; }
1579 {
1580  BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
1581  print $_;
1582 }
1583 print $_;
1584 ####
1585 # [perl #47361] do({}) and do +{} (variants of do-file)
1586 do({});
1587 do +{};
1588 sub foo::do {}
1589 package foo;
1590 CORE::do({});
1591 CORE::do +{};
1592 >>>>
1593 do({});
1594 do({});
1595 package foo;
1596 CORE::do({});
1597 CORE::do({});
1598 ####
1599 # [perl #77096] functions that do not follow the llafr
1600 () = (return 1) + time;
1601 () = (return ($1 + $2) * $3) + time;
1602 () = (return ($a xor $b)) + time;
1603 () = (do 'file') + time;
1604 () = (do ($1 + $2) * $3) + time;
1605 () = (do ($1 xor $2)) + time;
1606 () = (goto 1) + 3;
1607 () = (require 'foo') + 3;
1608 () = (require foo) + 3;
1609 () = (CORE::dump 1) + 3;
1610 () = (last 1) + 3;
1611 () = (next 1) + 3;
1612 () = (redo 1) + 3;
1613 () = (-R $_) + 3;
1614 () = (-W $_) + 3;
1615 () = (-X $_) + 3;
1616 () = (-r $_) + 3;
1617 () = (-w $_) + 3;
1618 () = (-x $_) + 3;
1619 ####
1620 # require(foo()) and do(foo())
1621 require (foo());
1622 do (foo());
1623 goto (foo());
1624 CORE::dump (foo());
1625 last (foo());
1626 next (foo());
1627 redo (foo());
1628 ####
1629 # require vstring
1630 require v5.16;
1631 ####
1632 # [perl #97476] not() *does* follow the llafr
1633 $_ = ($a xor not +($1 || 2) ** 2);
1634 ####
1635 # Precedence conundrums with argument-less function calls
1636 () = (eof) + 1;
1637 () = (return) + 1;
1638 () = (return, 1);
1639 () = warn;
1640 () = warn() + 1;
1641 () = setpgrp() + 1;
1642 ####
1643 # loopexes have assignment prec
1644 () = (CORE::dump a) | 'b';
1645 () = (goto a) | 'b';
1646 () = (last a) | 'b';
1647 () = (next a) | 'b';
1648 () = (redo a) | 'b';
1649 ####
1650 # [perl #63558] open local(*FH)
1651 open local *FH;
1652 pipe local *FH, local *FH;
1653 ####
1654 # [perl #91416] open "string"
1655 open 'open';
1656 open '####';
1657 open '^A';
1658 open "\ca";
1659 >>>>
1660 open *open;
1661 open '####';
1662 open '^A';
1663 open *^A;
1664 ####
1665 # "string"->[] ->{}
1666 no strict 'vars';
1667 () = 'open'->[0]; #aelemfast
1668 () = '####'->[0];
1669 () = '^A'->[0];
1670 () = "\ca"->[0];
1671 () = 'a::]b'->[0];
1672 () = 'open'->[$_]; #aelem
1673 () = '####'->[$_];
1674 () = '^A'->[$_];
1675 () = "\ca"->[$_];
1676 () = 'a::]b'->[$_];
1677 () = 'open'->{0}; #helem
1678 () = '####'->{0};
1679 () = '^A'->{0};
1680 () = "\ca"->{0};
1681 () = 'a::]b'->{0};
1682 >>>>
1683 no strict 'vars';
1684 () = $open[0];
1685 () = '####'->[0];
1686 () = '^A'->[0];
1687 () = $^A[0];
1688 () = 'a::]b'->[0];
1689 () = $open[$_];
1690 () = '####'->[$_];
1691 () = '^A'->[$_];
1692 () = $^A[$_];
1693 () = 'a::]b'->[$_];
1694 () = $open{'0'};
1695 () = '####'->{'0'};
1696 () = '^A'->{'0'};
1697 () = $^A{'0'};
1698 () = 'a::]b'->{'0'};
1699 ####
1700 # [perl #74740] -(f()) vs -f()
1701 $_ = -(f());
1702 ####
1703 # require <binop>
1704 require 'a' . $1;
1705 ####
1706 #[perl #30504] foreach-my postfix/prefix difference
1707 $_ = 'foo' foreach my ($foo1, $bar1, $baz1);
1708 foreach (my ($foo2, $bar2, $baz2)) { $_ = 'foo' }
1709 foreach my $i (my ($foo3, $bar3, $baz3)) { $i = 'foo' }
1710 >>>>
1711 $_ = 'foo' foreach (my($foo1, $bar1, $baz1));
1712 foreach $_ (my($foo2, $bar2, $baz2)) {
1713     $_ = 'foo';
1714 }
1715 foreach my $i (my($foo3, $bar3, $baz3)) {
1716     $i = 'foo';
1717 }
1718 ####
1719 #[perl #108224] foreach with continue block
1720 foreach (1 .. 3) { print } continue { print "\n" }
1721 foreach (1 .. 3) { } continue { }
1722 foreach my $i (1 .. 3) { print $i } continue { print "\n" }
1723 foreach my $i (1 .. 3) { } continue { }
1724 >>>>
1725 foreach $_ (1 .. 3) {
1726     print $_;
1727 }
1728 continue {
1729     print "\n";
1730 }
1731 foreach $_ (1 .. 3) {
1732     ();
1733 }
1734 continue {
1735     ();
1736 }
1737 foreach my $i (1 .. 3) {
1738     print $i;
1739 }
1740 continue {
1741     print "\n";
1742 }
1743 foreach my $i (1 .. 3) {
1744     ();
1745 }
1746 continue {
1747     ();
1748 }
1749 ####
1750 # file handles
1751 no strict;
1752 my $mfh;
1753 open F;
1754 open *F;
1755 open $fh;
1756 open $mfh;
1757 open 'a+b';
1758 select *F;
1759 select F;
1760 select $f;
1761 select $mfh;
1762 select 'a+b';
1763 ####
1764 # 'my' works with padrange op
1765 my($z, @z);
1766 my $m1;
1767 $m1 = 1;
1768 $z = $m1;
1769 my $m2 = 2;
1770 my($m3, $m4);
1771 ($m3, $m4) = (1, 2);
1772 @z = ($m3, $m4);
1773 my($m5, $m6) = (1, 2);
1774 my($m7, undef, $m8) = (1, 2, 3);
1775 @z = ($m7, undef, $m8);
1776 ($m7, undef, $m8) = (1, 2, 3);
1777 ####
1778 # 'our/local' works with padrange op
1779 our($z, @z);
1780 our $o1;
1781 no strict;
1782 local $o11;
1783 $o1 = 1;
1784 local $o1 = 1;
1785 $z = $o1;
1786 $z = local $o1;
1787 our $o2 = 2;
1788 our($o3, $o4);
1789 ($o3, $o4) = (1, 2);
1790 local($o3, $o4) = (1, 2);
1791 @z = ($o3, $o4);
1792 @z = local($o3, $o4);
1793 our($o5, $o6) = (1, 2);
1794 our($o7, undef, $o8) = (1, 2, 3);
1795 @z = ($o7, undef, $o8);
1796 @z = local($o7, undef, $o8);
1797 ($o7, undef, $o8) = (1, 2, 3);
1798 local($o7, undef, $o8) = (1, 2, 3);
1799 ####
1800 # 'state' works with padrange op
1801 # CONTEXT no strict; use feature 'state';
1802 state($z, @z);
1803 state $s1;
1804 $s1 = 1;
1805 $z = $s1;
1806 state $s2 = 2;
1807 state($s3, $s4);
1808 ($s3, $s4) = (1, 2);
1809 @z = ($s3, $s4);
1810 # assignment of state lists isn't implemented yet
1811 #state($s5, $s6) = (1, 2);
1812 #state($s7, undef, $s8) = (1, 2, 3);
1813 #@z = ($s7, undef, $s8);
1814 ($s7, undef, $s8) = (1, 2, 3);
1815 ####
1816 # anon arrays with padrange
1817 my($a, $b);
1818 my $c = [$a, $b];
1819 my $d = {$a, $b};
1820 ####
1821 # slices with padrange
1822 my($a, $b);
1823 my(@x, %y);
1824 @x = @x[$a, $b];
1825 @x = @y{$a, $b};
1826 ####
1827 # binops with padrange
1828 my($a, $b, $c);
1829 $c = $a cmp $b;
1830 $c = $a + $b;
1831 $a += $b;
1832 $c = $a - $b;
1833 $a -= $b;
1834 $c = my $a1 cmp $b;
1835 $c = my $a2 + $b;
1836 $a += my $b1;
1837 $c = my $a3 - $b;
1838 $a -= my $b2;
1839 ####
1840 # 'x' with padrange
1841 my($a, $b, $c, $d, @e);
1842 $c = $a x $b;
1843 $a x= $b;
1844 @e = ($a) x $d;
1845 @e = ($a, $b) x $d;
1846 @e = ($a, $b, $c) x $d;
1847 @e = ($a, 1) x $d;
1848 ####
1849 # @_ with padrange
1850 my($a, $b, $c) = @_;
1851 ####
1852 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1853 # lexical subroutine
1854 use feature 'lexical_subs';
1855 no warnings "experimental::lexical_subs";
1856 my sub f {}
1857 print f();
1858 >>>>
1859 use feature 'lexical_subs';
1860 BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x54\x05\x55\x01"}
1861 my sub f {
1862     BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x54\x05\x01"}
1863     
1864 }
1865 BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x54\x05\x01"}
1866 print f();
1867 ####
1868 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1869 # lexical "state" subroutine
1870 use feature 'state', 'lexical_subs';
1871 no warnings 'experimental::lexical_subs';
1872 state sub f {}
1873 print f();
1874 >>>>
1875 use feature 'lexical_subs';
1876 BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x54\x05\x55\x01"}
1877 CORE::state sub f {
1878     BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x54\x05\x01"}
1879     use feature 'state';
1880     
1881 }
1882 BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x54\x05\x01"}
1883 use feature 'state';
1884 print f();
1885 ####
1886 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1887 # lexical subroutine scoping
1888 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
1889 {
1890   {
1891     my sub a { die; }
1892     {
1893       foo();
1894       my sub b;
1895       b ;
1896       main::b();
1897       &main::b;
1898       &main::b();
1899       my $b = \&main::b;
1900       sub b { $b; }
1901     }
1902   }
1903   b();
1904 }
1905 ####
1906 # self-referential lexical subroutine
1907 # CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
1908 ();
1909 state sub sb2;
1910 sub sb2 {
1911     sb2 ;
1912 }
1913 ####
1914 # lexical subroutine with outer declaration and inner definition
1915 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
1916 ();
1917 my sub f;
1918 my sub g {
1919     ();
1920     sub f { }
1921 }
1922 ####
1923 # Elements of %# should not be confused with $#{ array }
1924 () = ${#}{'foo'};
1925 ####
1926 # $; [perl #123357]
1927 $_ = $;;
1928 do {
1929     $;
1930 };
1931 ####
1932 # Ampersand calls and scalar context
1933 # OPTIONS -P
1934 package prototest;
1935 sub foo($$);
1936 foo(bar(),baz());
1937 >>>>
1938 package prototest;
1939 &foo(scalar bar(), scalar baz());
1940 ####
1941 # coderef2text and prototyped sub calls [perl #123435]
1942 is 'foo', 'oo';
1943 ####
1944 # prototypes with unary precedence
1945 package prototest;
1946 sub dollar($) {}
1947 sub optdollar(;$) {}
1948 sub optoptdollar(;;$) {}
1949 sub splat(*) {}
1950 sub optsplat(;*) {}
1951 sub optoptsplat(;;*) {}
1952 sub bar(_) {}
1953 sub optbar(;_) {}
1954 sub optoptbar(;;_) {}
1955 sub plus(+) {}
1956 sub optplus(;+) {}
1957 sub optoptplus(;;+) {}
1958 sub wack(\$) {}
1959 sub optwack(;\$) {}
1960 sub optoptwack(;;\$) {}
1961 sub wackbrack(\[$]) {}
1962 sub optwackbrack(;\[$]) {}
1963 sub optoptwackbrack(;;\[$]) {}
1964 dollar($a < $b);
1965 optdollar($a < $b);
1966 optoptdollar($a < $b);
1967 splat($a < $b);     # Some of these deparse with â€˜&’; if that changes, just
1968 optsplat($a < $b);  # change the tests.
1969 optoptsplat($a < $b);
1970 bar($a < $b);
1971 optbar($a < $b);
1972 optoptbar($a < $b);
1973 plus($a < $b);
1974 optplus($a < $b);
1975 optoptplus($a < $b);
1976 wack($a = $b);
1977 optwack($a = $b);
1978 optoptwack($a = $b);
1979 wackbrack($a = $b);
1980 optwackbrack($a = $b);
1981 optoptwackbrack($a = $b);
1982 >>>>
1983 package prototest;
1984 dollar($a < $b);
1985 optdollar($a < $b);
1986 optoptdollar($a < $b);
1987 &splat($a < $b);
1988 &optsplat($a < $b);
1989 &optoptsplat($a < $b);
1990 bar($a < $b);
1991 optbar($a < $b);
1992 optoptbar($a < $b);
1993 &plus($a < $b);
1994 &optplus($a < $b);
1995 &optoptplus($a < $b);
1996 &wack(\($a = $b));
1997 &optwack(\($a = $b));
1998 &optoptwack(\($a = $b));
1999 &wackbrack(\($a = $b));
2000 &optwackbrack(\($a = $b));
2001 &optoptwackbrack(\($a = $b));
2002 ####
2003 # ensure aelemfast works in the range -128..127 and that there's no
2004 # funky edge cases
2005 my $x;
2006 no strict 'vars';
2007 $x = $a[-256] + $a[-255] + $a[-129] + $a[-128] + $a[-127] + $a[-1] + $a[0];
2008 $x = $a[1] + $a[126] + $a[127] + $a[128] + $a[255] + $a[256];
2009 my @b;
2010 $x = $b[-256] + $b[-255] + $b[-129] + $b[-128] + $b[-127] + $b[-1] + $b[0];
2011 $x = $b[1] + $b[126] + $b[127] + $b[128] + $b[255] + $b[256];
2012 ####
2013 # 'm' must be preserved in m??
2014 m??;
2015 ####
2016 # \(@array) and \(..., (@array), ...)
2017 my(@array, %hash, @a, @b, %c, %d);
2018 () = \(@array);
2019 () = \(%hash);
2020 () = \(@a, (@b), (%c), %d);
2021 () = \(@Foo::array);
2022 () = \(%Foo::hash);
2023 () = \(@Foo::a, (@Foo::b), (%Foo::c), %Foo::d);
2024 ####
2025 # subs synonymous with keywords
2026 main::our();
2027 main::pop();
2028 state();
2029 use feature 'state';
2030 main::state();
2031 ####
2032 # lvalue references
2033 # CONTEXT use feature "state", 'refaliasing', 'lexical_subs'; no warnings 'experimental';
2034 our $x;
2035 \$x = \$x;
2036 my $m;
2037 \$m = \$x;
2038 \my $n = \$x;
2039 (\$x) = @_;
2040 \($x) = @_;
2041 \($m) = @_;
2042 (\$m) = @_;
2043 \my($p) = @_;
2044 (\my $r) = @_;
2045 \($x, my $a) = @{[\$x, \$x]};
2046 (\$x, \my $b) = @{[\$x, \$x]};
2047 \local $x = \3;
2048 \local($x) = \3;
2049 \state $c = \3;
2050 \state($d) = \3;
2051 \our $e = \3;
2052 \our($f) = \3;
2053 \$_[0] = foo();
2054 \($_[1]) = foo();
2055 my @a;
2056 \$a[0] = foo();
2057 \($a[1]) = foo();
2058 \local($a[1]) = foo();
2059 \@a[0,1] = foo();
2060 \(@a[2,3]) = foo();
2061 \local @a[0,1] = (\$a)x2;
2062 \$_{a} = foo();
2063 \($_{b}) = foo();
2064 my %h;
2065 \$h{a} = foo();
2066 \($h{b}) = foo();
2067 \local $h{a} = \$x;
2068 \local($h{b}) = \$x;
2069 \@h{'a','b'} = foo();
2070 \(@h{2,3}) = foo();
2071 \local @h{'a','b'} = (\$x)x2;
2072 \@_ = foo();
2073 \@a = foo();
2074 (\@_) = foo();
2075 (\@a) = foo();
2076 \my @c = foo();
2077 (\my @d) = foo();
2078 \(@_) = foo();
2079 \(@a) = foo();
2080 \my(@g) = foo();
2081 \local @_ = \@_;
2082 (\local @_) = \@_;
2083 \state @e = [1..3];
2084 \state(@f) = \3;
2085 \our @i = [1..3];
2086 \our(@h) = \3;
2087 \%_ = foo();
2088 \%h = foo();
2089 (\%_) = foo();
2090 (\%h) = foo();
2091 \my %c = foo();
2092 (\my %d) = foo();
2093 \local %_ = \%h;
2094 (\local %_) = \%h;
2095 \state %y = {1,2};
2096 \our %z = {1,2};
2097 (\our %zz) = {1,2};
2098 \&a = foo();
2099 (\&a) = foo();
2100 \(&a) = foo();
2101 {
2102   my sub a;
2103   \&a = foo();
2104   (\&a) = foo();
2105   \(&a) = foo();
2106 }
2107 (\$_, $_) = \(1, 2);
2108 $_ == 3 ? \$_ : $_ = \3;
2109 $_ == 3 ? \$_ : \$x = \3;
2110 \($_ == 3 ? $_ : $x) = \3;
2111 for \my $topic (\$1, \$2) {
2112     die;
2113 }
2114 for \state $topic (\$1, \$2) {
2115     die;
2116 }
2117 for \our $topic (\$1, \$2) {
2118     die;
2119 }
2120 for \$_ (\$1, \$2) {
2121     die;
2122 }
2123 for \my @a ([1,2], [3,4]) {
2124     die;
2125 }
2126 for \state @a ([1,2], [3,4]) {
2127     die;
2128 }
2129 for \our @a ([1,2], [3,4]) {
2130     die;
2131 }
2132 for \@_ ([1,2], [3,4]) {
2133     die;
2134 }
2135 for \my %a ({5,6}, {7,8}) {
2136     die;
2137 }
2138 for \our %a ({5,6}, {7,8}) {
2139     die;
2140 }
2141 for \state %a ({5,6}, {7,8}) {
2142     die;
2143 }
2144 for \%_ ({5,6}, {7,8}) {
2145     die;
2146 }
2147 {
2148     my sub a;
2149     for \&a (sub { 9; }, sub { 10; }) {
2150         die;
2151     }
2152 }
2153 for \&a (sub { 9; }, sub { 10; }) {
2154     die;
2155 }
2156 >>>>
2157 our $x;
2158 \$x = \$x;
2159 my $m;
2160 \$m = \$x;
2161 \my $n = \$x;
2162 (\$x) = @_;
2163 (\$x) = @_;
2164 (\$m) = @_;
2165 (\$m) = @_;
2166 (\my $p) = @_;
2167 (\my $r) = @_;
2168 (\$x, \my $a) = @{[\$x, \$x];};
2169 (\$x, \my $b) = @{[\$x, \$x];};
2170 \local $x = \3;
2171 (\local $x) = \3;
2172 \state $c = \3;
2173 (\state $d) = \3;
2174 \our $e = \3;
2175 (\our $f) = \3;
2176 \$_[0] = foo();
2177 (\$_[1]) = foo();
2178 my @a;
2179 \$a[0] = foo();
2180 (\$a[1]) = foo();
2181 (\local $a[1]) = foo();
2182 (\@a[0, 1]) = foo();
2183 (\@a[2, 3]) = foo();
2184 (\local @a[0, 1]) = (\$a) x 2;
2185 \$_{'a'} = foo();
2186 (\$_{'b'}) = foo();
2187 my %h;
2188 \$h{'a'} = foo();
2189 (\$h{'b'}) = foo();
2190 \local $h{'a'} = \$x;
2191 (\local $h{'b'}) = \$x;
2192 (\@h{'a', 'b'}) = foo();
2193 (\@h{2, 3}) = foo();
2194 (\local @h{'a', 'b'}) = (\$x) x 2;
2195 \@_ = foo();
2196 \@a = foo();
2197 (\@_) = foo();
2198 (\@a) = foo();
2199 \my @c = foo();
2200 (\my @d) = foo();
2201 (\(@_)) = foo();
2202 (\(@a)) = foo();
2203 (\(my @g)) = foo();
2204 \local @_ = \@_;
2205 (\local @_) = \@_;
2206 \state @e = [1..3];
2207 (\(state @f)) = \3;
2208 \our @i = [1..3];
2209 (\(our @h)) = \3;
2210 \%_ = foo();
2211 \%h = foo();
2212 (\%_) = foo();
2213 (\%h) = foo();
2214 \my %c = foo();
2215 (\my %d) = foo();
2216 \local %_ = \%h;
2217 (\local %_) = \%h;
2218 \state %y = {1, 2};
2219 \our %z = {1, 2};
2220 (\our %zz) = {1, 2};
2221 \&a = foo();
2222 (\&a) = foo();
2223 (\&a) = foo();
2224 {
2225   my sub a;
2226   \&a = foo();
2227   (\&a) = foo();
2228   (\&a) = foo();
2229 }
2230 (\$_, $_) = \(1, 2);
2231 $_ == 3 ? \$_ : $_ = \3;
2232 $_ == 3 ? \$_ : \$x = \3;
2233 ($_ == 3 ? \$_ : \$x) = \3;
2234 foreach \my $topic (\$1, \$2) {
2235     die;
2236 }
2237 foreach \state $topic (\$1, \$2) {
2238     die;
2239 }
2240 foreach \our $topic (\$1, \$2) {
2241     die;
2242 }
2243 foreach \$_ (\$1, \$2) {
2244     die;
2245 }
2246 foreach \my @a ([1, 2], [3, 4]) {
2247     die;
2248 }
2249 foreach \state @a ([1, 2], [3, 4]) {
2250     die;
2251 }
2252 foreach \our @a ([1, 2], [3, 4]) {
2253     die;
2254 }
2255 foreach \@_ ([1, 2], [3, 4]) {
2256     die;
2257 }
2258 foreach \my %a ({5, 6}, {7, 8}) {
2259     die;
2260 }
2261 foreach \our %a ({5, 6}, {7, 8}) {
2262     die;
2263 }
2264 foreach \state %a ({5, 6}, {7, 8}) {
2265     die;
2266 }
2267 foreach \%_ ({5, 6}, {7, 8}) {
2268     die;
2269 }
2270 {
2271     my sub a;
2272     foreach \&a (sub { 9; } , sub { 10; } ) {
2273         die;
2274     }
2275 }
2276 foreach \&a (sub { 9; } , sub { 10; } ) {
2277     die;
2278 }
2279 ####
2280 # join $foo, pos
2281 my $foo;
2282 $_ = join $foo, pos
2283 >>>>
2284 my $foo;
2285 $_ = join('???', pos $_);
2286 ####
2287 # exists $a[0]
2288 our @a;
2289 exists $a[0];
2290 ####
2291 # my @a; exists $a[0]
2292 my @a;
2293 exists $a[0];
2294 ####
2295 # delete $a[0]
2296 our @a;
2297 delete $a[0];
2298 ####
2299 # my @a; delete $a[0]
2300 my @a;
2301 delete $a[0];
2302 ####
2303 # $_[0][$_[1]]
2304 $_[0][$_[1]];
2305 ####
2306 # f($a[0]);
2307 my @a;
2308 f($a[0]);
2309 ####
2310 #qr/\Q$h{'key'}\E/;
2311 my %h;
2312 qr/\Q$h{'key'}\E/;
2313 ####
2314 # my $x = "$h{foo}";
2315 my %h;
2316 my $x = "$h{'foo'}";
2317 ####
2318 # weird constant hash key
2319 my %h;
2320 my $x = $h{"\000\t\x{100}"};
2321 ####
2322 # multideref and packages
2323 package foo;
2324 my(%bar) = ('a', 'b');
2325 our(@bar) = (1, 2);
2326 $bar{'k'} = $bar[200];
2327 $main::bar{'k'} = $main::bar[200];
2328 $foo::bar{'k'} = $foo::bar[200];
2329 package foo2;
2330 $bar{'k'} = $bar[200];
2331 $main::bar{'k'} = $main::bar[200];
2332 $foo::bar{'k'} = $foo::bar[200];
2333 >>>>
2334 package foo;
2335 my(%bar) = ('a', 'b');
2336 our(@bar) = (1, 2);
2337 $bar{'k'} = $bar[200];
2338 $main::bar{'k'} = $main::bar[200];
2339 $foo::bar{'k'} = $bar[200];
2340 package foo2;
2341 $bar{'k'} = $foo::bar[200];
2342 $main::bar{'k'} = $main::bar[200];
2343 $foo::bar{'k'} = $foo::bar[200];
2344 ####
2345 # multideref and local
2346 my %h;
2347 local $h{'foo'}[0] = 1;
2348 ####
2349 # multideref and exists
2350 my(%h, $i);
2351 my $e = exists $h{'foo'}[$i];
2352 ####
2353 # multideref and delete
2354 my(%h, $i);
2355 my $e = delete $h{'foo'}[$i];
2356 ####
2357 # multideref with leading expression
2358 my $r;
2359 my $x = ($r // [])->{'foo'}[0];
2360 ####
2361 # multideref with complex middle index
2362 my(%h, $i, $j, $k);
2363 my $x = $h{'foo'}[$i + $j]{$k};
2364 ####
2365 # chdir
2366 chdir 'file';
2367 chdir FH;
2368 chdir;