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