4 splice @INC, 0, 0, 't', '.';
6 if (($Config::Config{'extensions'} !~ /\bB\b/) ){
7 print "1..0 # Skip -- Perl configured without B module\n";
16 my $tests = 52; # not counting those in the __DATA__ section
19 my $deparse = B::Deparse->new();
20 isa_ok($deparse, 'B::Deparse', 'instantiate a B::Deparse object');
27 # This code is pinched from the t/lib/common.pl for TODO.
28 # It's not clear how to avoid duplication
29 my %meta = (context => '');
30 foreach my $what (qw(skip todo context options)) {
31 s/^#\s*\U$what\E\s*(.*)\n//m and $meta{$what} = $1;
32 # If the SKIP reason starts ? then it's taken as a code snippet to
33 # evaluate. This provides the flexibility to have conditional SKIPs
34 if ($meta{$what} && $meta{$what} =~ s/^\?//) {
35 my $temp = eval $meta{$what};
37 die "# In \U$what\E code reason:\n# $meta{$what}\n$@";
45 die "Missing name in test $_" unless defined $desc;
48 SKIP: { skip($meta{skip}) };
52 my ($input, $expected);
53 if (/(.*)\n>>>>\n(.*)/s) {
54 ($input, $expected) = ($1, $2);
57 ($input, $expected) = ($_, $_);
60 # parse options if necessary
61 my $deparse = $meta{options}
62 ? $deparse{$meta{options}} ||=
63 new B::Deparse split /,/, $meta{options}
66 my $code = "$meta{context};\n" . <<'EOC' . "sub {$input\n}";
67 # Tell B::Deparse about our ambient pragmas
68 my ($hint_bits, $warning_bits, $hinthash);
70 ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H);
72 $deparse->ambient_pragmas (
73 hint_bits => $hint_bits,
74 warning_bits => $warning_bits,
78 my $coderef = eval $code;
80 local $::TODO = $meta{todo};
82 is($@, "", "compilation of $desc")
83 or diag "=============================================\n"
84 . "CODE:\n--------\n$code\n--------\n"
85 . "=============================================\n";
88 my $deparsed = $deparse->coderef2text( $coderef );
89 my $regex = $expected;
90 $regex =~ s/(\S+)/\Q$1/g;
91 $regex =~ s/\s+/\\s+/g;
92 $regex = '^\{\s*' . $regex . '\s*\}$';
94 like($deparsed, qr/$regex/, $desc)
95 or diag "=============================================\n"
96 . "CODE:\n--------\n$input\n--------\n"
97 . "EXPECTED:\n--------\n{\n$expected\n}\n--------\n"
98 . "GOT:\n--------\n$deparsed\n--------\n"
99 . "=============================================\n";
103 # Reset the ambient pragmas
107 ($b, $w, $h) = ($^H, ${^WARNING_BITS}, \%^H);
109 $deparse->ambient_pragmas (
116 use constant 'c', 'stuff';
117 is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
118 'the subroutine generated by use constant deparses');
121 is($deparse->coderef2text(sub{(-1) ** $a }), "{\n (-1) ** \$a;\n}",
122 'anon sub capturing an external lexical');
124 use constant cr => ['hello'];
125 my $string = "sub " . $deparse->coderef2text(\&cr);
126 my $val = (eval $string)->() or diag $string;
127 is(ref($val), 'ARRAY', 'constant array references deparse');
128 is($val->[0], 'hello', 'and return the correct value');
130 my $path = join " ", map { qq["-I$_"] } @INC;
132 $a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
133 $a =~ s/-e syntax OK\n//g;
134 $a =~ s/.*possible typo.*\n//; # Remove warning line
135 $a =~ s/.*-i used with no filenames.*\n//; # Remove warning line
136 $b = quotemeta <<'EOF';
137 BEGIN { $^I = ".bak"; }
139 BEGIN { $/ = "\n"; $\ = "\n"; }
140 LINE: while (defined($_ = readline ARGV)) {
142 our(@F) = split(' ', $_, 0);
146 $b =~ s/our\\\(\\\@F\\\)/our[( ]\@F\\)?/; # accept both our @F and our(@F)
148 'command line flags deparse as BEGIN blocks setting control variables');
150 $a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`;
151 $a =~ s/-e syntax OK\n//g;
152 is($a, "use constant ('PI', 4);\n",
153 "Proxy Constant Subroutines must not show up as (incorrect) prototypes");
155 $a = `$^X $path "-MO=Deparse" -e "sub foo(){1}" 2>&1`;
156 $a =~ s/-e syntax OK\n//g;
157 is($a, "sub foo () {\n 1;\n}\n",
158 "Main prog consisting of just a constant (via empty proto)");
160 $a = readpipe qq|$^X $path "-MO=Deparse"|
161 .qq| -e "package F; sub f(){0} sub s{}"|
162 .qq| -e "#line 123 four-five-six"|
163 .qq| -e "package G; sub g(){0} sub s{}" 2>&1|;
164 $a =~ s/-e syntax OK\n//g;
165 like($a, qr/sub F::f \(\) \{\s*0;?\s*}/,
166 "Constant is dumped in package in which other subs are dumped");
167 unlike($a, qr/sub g/,
168 "Constant is not dumped in package in which other subs are not dumped");
170 #Re: perlbug #35857, patch #24505
171 #handle warnings::register-ed packages properly.
172 package B::Deparse::Wrapper;
175 use warnings::register;
177 my $deparser = B::Deparse->new();
178 return $deparser->coderef2text(shift);
182 use overload '0+' => sub { 42 };
187 use constant GLIPP => 'glipp';
188 use constant PI => 4;
189 use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
190 use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
191 BEGIN { delete $::Fcntl::{O_APPEND}; }
192 use POSIX qw/O_CREAT/;
195 my $res = B::Deparse::Wrapper::getcode($val);
196 like($res, qr/use warnings/,
197 '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
200 my $x=sub { ++$q,++$p };
202 eval <<EOFCODE and test($x);
206 use warnings::register;
211 # Exotic sub declarations
212 $a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
213 $a =~ s/-e syntax OK\n//g;
214 is($a, <<'EOCODG', "sub :::: and sub ::::::");
224 $a = `$^X $path "-MO=Deparse,-l" -e "map{ eval(0) }()" 2>&1`;
225 $a =~ s/-e syntax OK\n//g;
226 is($a, <<'EOCODH', "[perl #117311] [PATCH] -l option ('#line ...') does not emit ^Ls in the output");
235 my $code = <<"EOCODE";
237 our \$\x{1e1f}\x{14d}\x{14d};
241 = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
242 s/$ \n//x for $deparsed, $code;
243 is $deparsed, $code, 'our $funny_Unicode_chars';
248 `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
249 $a =~ s/-e syntax OK\n//g;
250 is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
252 *CORE::GLOBAL::require = sub {
261 `$^X $path "-MO=Deparse" -e "BEGIN{*Acme::Acme:: = *Acme::}" 2>&1`;
262 like($a, qr/-e syntax OK/,
263 "Deparse does not hang when traversing stash circularities");
267 is($deparse->coderef2text(sub{ print "foo@{]}" }),
270 }>, 'curly around to interpolate "@{]}"');
271 is($deparse->coderef2text(sub{ print "foo@{-}" }),
274 }>, 'no need to curly around to interpolate "@-"');
276 # Strict hints in %^H are mercilessly suppressed
278 `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
279 unlike($a, qr/BEGIN/,
280 "Deparse does not emit strict hh hints");
282 # ambient_pragmas should not mess with strict settings.
284 skip "requires 5.11", 1 unless $] >= 5.011;
287 # Clear out all hints
290 new B::Deparse -> ambient_pragmas(strict => 'all');
292 use 5.011; # should enable strict
293 ok !eval '$do_noT_create_a_variable_with_this_name = 1',
294 'ambient_pragmas do not mess with compiling scope';
298 # multiple statements on format lines
299 $a = `$^X $path "-MO=Deparse" -e "format =" -e "\@" -e "x();z()" -e. 2>&1`;
300 $a =~ s/-e syntax OK\n//g;
301 is($a, <<'EOCODH', 'multiple statements on format lines');
308 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
309 prog => "format =\n\@\n\$;\n.\n"),
310 <<'EOCODM', '$; on format line';
317 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse,-l', $path ],
318 prog => "format =\n\@\n\$foo\n.\n"),
319 <<'EOCODM', 'formats with -l';
326 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
327 prog => "{ my \$x; format =\n\@\n\$x\n.\n}"),
328 <<'EOCODN', 'formats nested inside blocks';
339 $a = readpipe qq`$^X $path "-MO=Deparse" -e "use feature q|:all|;`
340 .qq` my sub format; CORE::format =" -e. 2>&1`;
341 like($a, qr/CORE::format/, 'CORE::format when lex format sub is in scope');
343 # literal big chars under 'use utf8'
344 is($deparse->coderef2text(sub{ use utf8; /€/; }),
350 # STDERR when deparsing sub calls
351 # For a short while the output included 'While deparsing'
352 $a = `$^X $path "-MO=Deparse" -e "foo()" 2>&1`;
353 $a =~ s/-e syntax OK\n//g;
354 is($a, <<'EOCODI', 'no extra output when deparsing foo()');
358 # Sub calls compiled before importation
359 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
362 Test::More::->import;
366 'sub calls compiled before importation of prototype subs';
368 # [perl #121050] Prototypes with whitespace
369 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
371 sub _121050(\$ \$) { }
373 sub _121050empty( ) {}
374 () = _121050empty() + 1;
376 <<'EOCODP', '[perl #121050] prototypes with whitespace';
377 sub _121050 (\$ \$) {
381 sub _121050empty ( ) {
384 () = _121050empty + 1;
388 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
389 .qq`"use feature q|:all|; my sub no; CORE::no less" 2>&1`;
390 like($a, qr/my sub no;\n.*CORE::no less;/s,
391 'CORE::no after my sub no');
394 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
395 .qq`"use feature q|:all|; my sub use; CORE::use less" 2>&1`;
396 like($a, qr/my sub use;\n.*CORE::use less;/s,
397 'CORE::use after my sub use');
400 $a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
401 .qq`"use feature q|:all|; my sub __DATA__; `
402 .qq`CORE::__DATA__" 2>&1`;
403 like($a, qr/my sub __DATA__;\n.*CORE::__DATA__/s,
404 'CORE::__DATA__ after my sub __DATA__');
407 $a = readpipe qq`$^X $path "-MO=Deparse" -e "sub foo{}" 2>&1`;
408 like($a, qr/sub foo\s*\{\s+\}/, 'sub declarations');
409 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
410 prog => 'sub f($); sub f($){}'),
411 qr/sub f\s*\(\$\)\s*\{\s*\}/,
412 'predeclared prototyped subs';
413 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
414 prog => 'use Scalar::Util q-weaken-;
416 BEGIN { weaken($_=\$::{f}) }'),
417 qr/sub f\s*\(\$\)\s*;/,
418 'prototyped stub with weak reference to the stash entry';
419 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
420 prog => 'sub f () { 42 }'),
421 qr/sub f\s*\(\)\s*\{\s*42;\s*\}/,
422 'constant perl sub declaration';
426 skip "BEGIN output is wrong on old perls", 1 if $] < 5.021006;
440 $a = readpipe qq`$^X $path "-MO=Deparse" -e "$prog" 2>&1`;
441 $a =~ s/-e syntax OK\n//g;
442 is($a, <<'EOCODJ', 'BEGIN blocks');
462 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ], prog => '
471 '), <<'EOCODL', 'BEGIN blocks at the end of their enclosing blocks';
488 # BEGIN blocks should not be called __ANON__
489 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
490 prog => 'sub BEGIN { } CHECK { delete $::{BEGIN} }'),
491 qr/sub BEGIN/, 'anonymised BEGIN';
494 my $prog = 'use constant FOO => do { 1 }; no overloading; die';
495 $a = readpipe qq`$^X $path "-MO=-qq,Deparse" -e "$prog" 2>&1`;
496 is($a, <<'EOCODK', '[perl #115066] use statements accidentally nested');
497 use constant ('FOO', do {
504 # BEGIN blocks inside predeclared subs
505 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
509 sub run_tests { BEGIN { } die }'),
510 qr/sub run_tests \{\s*sub BEGIN/,
511 'BEGIN block inside predeclared sub';
513 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
514 prog => 'package foo; use overload qr=>sub{}'),
515 qr/package foo;\s*use overload/,
518 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
519 prog => 'use feature lexical_subs=>; my sub f;sub main::f{}'),
520 qr/^sub main::f \{/m,
521 'sub decl when lex sub is in scope';
523 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
524 prog => 'sub foo{foo()}'),
525 qr/^sub foo \{\s+foo\(\)/m,
528 like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
529 prog => 'use feature lexical_subs=>state=>;
530 state sub sb5; sub { sub sb5 { } }'),
531 qr/sub \{\s*\(\);\s*sub sb5 \{/m,
532 'state sub in anon sub but declared outside';
534 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
535 prog => 'BEGIN { $::{f}=\!0 }'),
536 "sub BEGIN {\n \$main::{'f'} = \\1;\n}\n",
537 '&PL_sv_yes constant (used to croak)';
539 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
540 prog => '$x =~ (1?/$a/:0)'),
541 '$x =~ ($_ =~ /$a/);'."\n",
542 '$foo =~ <branch-folded match> under taint mode';
544 unlike runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-w' ],
545 prog => 'BEGIN { undef &foo }'),
546 qr'Use of uninitialized value',
547 'no warnings for undefined sub';
549 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
550 prog => 'sub f { 1; } BEGIN { *g = \&f; }'),
551 "sub f {\n 1;\n}\nsub BEGIN {\n *g = \\&f;\n}\n",
552 "sub glob alias shouldn't impede emitting original sub";
554 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
555 prog => 'package Foo; sub f { 1; } BEGIN { *g = \&f; }'),
556 "package Foo;\nsub f {\n 1;\n}\nsub BEGIN {\n *g = \\&f;\n}\n",
557 "sub glob alias outside main shouldn't impede emitting original sub";
559 is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
560 prog => 'package Foo; sub f { 1; } BEGIN { *Bar::f = \&f; }'),
561 "package Foo;\nsub f {\n 1;\n}\nsub BEGIN {\n *Bar::f = \\&f;\n}\n",
562 "sub glob alias in separate package shouldn't impede emitting original sub";
565 done_testing($tests);
568 # TODO [perl #120950] This succeeds when run a 2nd time
572 # y/uni/code/ [perl #120950] This 2nd instance succeeds
578 # Constants in a block
579 # CONTEXT no warnings;
585 # List of constants in void context
586 # CONTEXT no warnings;
593 # Lexical and simple arithmetic
595 ++$test and $test /= 2;
598 $test /= 2 if ++$test;
603 # Assignment to list x
604 ((undef) x 3) = undef;
608 my $test = sub : lvalue {
616 my $test = sub : method {
622 # anonsub attrs at statement start
623 my $x = do { +sub : lvalue { my $y; } };
624 my $z = do { foo: +sub : method { my $a; } };
626 # block with continue
634 # lexical and package scalars
638 # lexical and package arrays
643 # lexical and package hashes
648 our($foo, $bar, $baz);
650 # CONTEXT { package Dog } use feature "state";
651 # variables with declared classes
661 my Dog ($foo, @bar, %baz);
662 our Dog ($phoo, @barr, %bazz);
663 state Dog ($fough, @barre, %bazze);
667 local our($rhu, $barb);
671 $_ .= <> . <ARGV> . <$foo>;
677 $_ .= readline(ARGV) . readline(ARGV) . readline($foo);
697 my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
701 # TODO ? ord("A") != 65 && "EBCDIC"
702 my $baz = "B\366\x{100}";
703 my $bba = qr/B\366\x{100}/;
708 s/x/complex_expression();/e;
723 # 2 arguments in a 3 argument for
724 for (my $i = 0; $i < 2;) {
729 for (my $i = 0; $i < 2; ++$i) {
733 # 3 argument for again
734 for (my $i = 0; $i < 2; ++$i) {
738 # 3-argument for with inverted condition
739 for (my $i; not $i;) {
742 for (my $i; not $i; ++$i) {
745 for (my $a; not +($1 || 2) ** 2;) {
748 Something_to_put_the_loop_in_void_context();
752 while ($i) { my $z = 1; } continue { $i = 99; }
755 foreach my $i (1, 2) {
760 # foreach with my under -p
773 foreach my $i (1, 2) {
778 foreach our $i (1, 2) {
782 # foreach with my and our
784 foreach our $i (1, 2) {
789 # CONTEXT use feature "state";
790 foreach state $i (1, 2) {
794 # foreach with sub call
795 foreach $_ (hcaerof()) {
801 print reverse sort(@x);
805 print((sort {$b cmp $a} @x));
807 # reverse sort with block
809 print((reverse sort {$b <=> $a} @x));
813 print $_ foreach (reverse @a);
815 # foreach reverse (not inplace)
817 print $_ foreach (reverse 1, 2..5);
821 @ary = split(' ', 'foo', 0);
824 @ary = split(' ', 'foo', 0);
827 our @array = split(//, 'foo', 0);
830 my @array = split(//, 'foo', 0);
834 @array = split(/x(?{ $c++; })y/, 'foo', 0);
838 ($x, $y) = split(/$p(?{ $c++; })y/, 'foo', 2);
842 @ary = split(/$pat/, 'foo', 0);
846 @ary = split(/$pat/, 'foo', 0);
850 local @array = split(/$pat/, 'foo', 0);
853 my @array = split(/$pat/, 'foo', 0);
859 do { my $x = 1; $x };
861 # <20061012113037.GJ25805@c4.convolution.nl>
880 sub foo {} foo & & & foo;
885 # variables as method names
888 'Foo'->$bar('orz') = 'a stranger stranger than before';
890 # constants as method names
893 # constants as method names without ()
896 # [perl #47359] "indirect" method call notation
900 foo{@bar}1 xor foo();
903 (foo { @bar } 1)->foo;
904 (foo { @bar } 1), foo();
905 foo { @bar } 1 xor foo();
907 # indirops with blocks
909 print {*STDOUT;} 'foo';
910 printf {*STDOUT;} 'foo';
911 say {*STDOUT;} 'foo';
912 system {'foo';} '-foo';
913 exec {'foo';} '-foo';
915 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
916 # CONTEXT use feature ':5.10';
920 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
921 # CONTEXT use 5.10.0;
922 # say in the context of use 5.10.0
925 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
926 # say with use 5.10.0
934 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
935 # say with use feature ':5.10';
939 use feature 'say', 'state', 'switch';
942 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
943 # CONTEXT use feature ':5.10';
944 # say with use 5.10.0 in the context of use feature
952 # SKIP ?$] < 5.010 && "say not implemented on this Perl version"
953 # CONTEXT use 5.10.0;
954 # say with use feature ':5.10' in the context of use 5.10.0
960 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
961 # CONTEXT use feature ':5.15';
965 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
966 # CONTEXT use 5.15.0;
967 # __SUB__ in the context of use 5.15.0
970 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
971 # __SUB__ with use 5.15.0
979 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
980 # __SUB__ with use feature ':5.15';
984 use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
987 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
988 # CONTEXT use feature ':5.15';
989 # __SUB__ with use 5.15.0 in the context of use feature
997 # SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
998 # CONTEXT use 5.15.0;
999 # __SUB__ with use feature ':5.15' in the context of use 5.15.0
1000 use feature ':5.15';
1005 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
1006 # CONTEXT use feature ':5.10';
1010 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
1011 # CONTEXT use feature ':5.10';
1012 # state var assignment
1014 my $y = (state $x = 42);
1017 # SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
1018 # CONTEXT use feature ':5.10';
1019 # state vars in anonymous subroutines
1026 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
1031 # SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
1032 # keys @array; values @array
1033 keys @$a if keys @ARGV;
1034 values @ARGV if values @$a;
1036 # Anonymous arrays and hashes, and references to them
1042 # SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
1043 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
1044 # implicit smartmatch in given/when
1046 when ('bar') { continue; }
1047 when ($_ ~~ 'quux') { continue; }
1051 # conditions in elsifs (regression in change #33710 which fixed bug #37302)
1054 elsif ($a and $b) { x(); }
1055 elsif ($a or $b) { x(); }
1058 # interpolation in regexps
1062 # TODO new undocumented cpan-bug #33708
1066 # TODO hash constants not yet fixed
1068 use constant H => { "#" => 1 }; H->{"#"}
1070 # TODO optimized away 0 not yet fixed
1072 foreach my $i (@_) { 0 }
1074 # tests with not, not optimized
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;
1094 # tests with not, optimized
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;
1115 x() unless $a or $b;
1117 x() unless $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;
1129 # tests that should be constant folded
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() }
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
1186 if ($a == 1) { x() } elsif ($b == 2) { z() }
1187 if (do { foo(); GLIPP }) { x() }
1188 if (do { $a++; GLIPP }) { x() }
1191 if ($a == 1) { x(); } elsif ($b == 2) { z(); }
1192 if (do { foo(); GLIPP }) { x(); }
1193 if (do { ++$a; GLIPP }) { x(); }
1195 # TODO constant deparsing has been backed out for 5.12
1196 # tests for deparsing constants
1199 # TODO constant deparsing has been backed out for 5.12
1200 # tests for deparsing imported constants
1203 # TODO constant deparsing has been backed out for 5.12
1204 # tests for deparsing re-exported constants
1207 # TODO constant deparsing has been backed out for 5.12
1208 # tests for deparsing imported constants that got deleted from the original namespace
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
1217 eval '@Fcntl::O_EXCL = qw/affe tiger/;';
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;
1236 # TODO Subsets of warnings could be encoded textually, rather than as bitflips.
1237 # subsets of warnings
1238 no warnings 'deprecated';
1241 # TODO Better test for CPAN #33708 - the deparsed code has different behaviour
1257 # SKIP ?$] > 5.013006 && ":= is now a syntax error"
1258 # := treated as an empty attribute list
1265 # : = empty attribute list
1284 # #71870 Use of uninitialized value in bitwise and B::Deparse
1286 @a = split(/foo/, $s, 0);
1288 @a = split(/$r/, $s, 0);
1291 # package declaration before label
1297 # shift optimisation
1302 # shift optimisation
1305 # shift optimisation
1310 # shift optimisation
1314 "foo" =~ (1 ? /foo/ : /bar/);
1315 "foo" =~ (1 ? y/foo// : /bar/);
1316 "foo" =~ (1 ? y/foo//r : /bar/);
1317 "foo" =~ (1 ? s/foo// : /bar/);
1319 'foo' =~ ($_ =~ /foo/);
1320 'foo' =~ ($_ =~ tr/fo//);
1321 'foo' =~ ($_ =~ tr/fo//r);
1322 'foo' =~ ($_ =~ s/foo//);
1324 # The fix for [perl #20444] broke this.
1327 # [perl #81424] match against aelemfast_lex
1343 use constant QR_CONSTANT => qr/a/soupmix;
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;
1359 use feature "unicode_strings";
1360 print /a/d, s/b/c/d;
1364 print /a/d, s/b/c/d;
1368 print /a/d, s/b/c/d;
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;
1377 use feature 'unicode_strings';
1378 print /a/d, s/b/c/d;
1381 BEGIN { $^H{'reflags'} = '0';
1382 $^H{'reflags_charset'} = '2'; }
1383 print /a/d, s/b/c/d;
1387 use feature ':5.12';
1388 print /a/d, s/b/c/d;
1391 # all the flags (qr//)
1403 use feature 'unicode_strings';
1406 # all the flags (m//)
1420 use feature 'unicode_strings';
1423 # all the flags (s///)
1438 use feature 'unicode_strings';
1441 # tr/// with all the flags: empty replacement
1452 # tr/// with all the flags: short replacement
1463 # tr/// with all the flags: equal length replacement
1470 # tr with extended table (/c)
1476 tr/\000-\375/A-C/cd;
1477 tr/\000-\375/A-D/cd;
1478 tr/\000-\375/A-I/cd;
1479 tr/\000-\375/AB/cds;
1480 tr/\000-\375/A-C/cds;
1481 tr/\000-\375/A-D/cds;
1482 tr/\000-\375/A-I/cds;
1484 # [perl #119807] s//\(3)/ge should not warn when deparsed (\3 warns)
1488 "" =~ /a(?{ print q|
1491 '' =~ /a(?{ print "\n"; })/;
1494 $_ = qr/(??{<<END})/
1499 $_ = qr/(??{ "f.o\nb.r\n"; })/;
1501 # More regexp code block madness
1508 /a(??{ die $b; })a/;
1509 /$a(??{ die $b; })/;
1510 /@a(??{ die $b; })/;
1512 qr/a(?{ die $b; })a/;
1513 qr/$a(?{ die $b; })/;
1514 qr/@a(?{ die $b; })/;
1515 qr/(??{ die $b; })/;
1516 qr/a(??{ die $b; })a/;
1517 qr/$a(??{ die $b; })/;
1518 qr/@a(??{ die $b; })/;
1520 s/a(?{ die $b; })a//;
1521 s/$a(?{ die $b; })//;
1522 s/@a(?{ die $b; })//;
1523 s/(??{ die $b; })//;
1524 s/a(??{ die $b; })a//;
1525 s/$a(??{ die $b; })//;
1526 s/@a(??{ die $b; })//;
1528 # /(?x)<newline><tab>/
1533 tr/a/b/r + $a =~ tr/p/q/r;
1535 # y///d in list [perl #119815]
1546 # SKIP ?$] >= 5.023 && "autoderef deleted in this Perl version"
1547 # CONTEXT no warnings 'experimental::autoderef';
1552 # readpipe with complex expression
1558 # aelemfast for a lexical
1562 # feature features without feature
1563 # CONTEXT no warnings 'experimental::smartmatch';
1578 # feature features when feature has been disabled by use VERSION
1579 # CONTEXT no warnings 'experimental::smartmatch';
1580 use feature (sprintf(":%vd", $^V));
1608 # (the above test with CONTEXT, and the output is equivalent but different)
1609 # CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
1610 # feature features when feature has been disabled by use VERSION
1611 use feature (sprintf(":%vd", $^V));
1627 use feature ':default';
1641 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1642 # lexical subroutines and keywords of the same name
1643 # CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental';
1667 CORE::default { die; }
1668 CORE::if ($1) { die; }
1669 CORE::if ($1) { die; }
1670 CORE::elsif ($1) { die; }
1672 CORE::for (die; $1; die) { die; }
1673 CORE::foreach $_ (1 .. 10) { die; }
1674 die CORE::foreach (1);
1675 CORE::given ($1) { die; }
1680 () = (CORE::q['], CORE::qq["$_], CORE::qr//, CORE::qx[`]);
1683 () = CORE::sub { die; } ;
1685 CORE::unless ($1) { die; }
1686 CORE::until ($1) { die; }
1689 CORE::when ($1 ~~ $2) { die; }
1690 CORE::while ($1) { die; }
1694 use feature 'current_sub', 'evalbytes';
1700 no feature 'unicode_strings';
1703 use feature 'current_sub', 'evalbytes';
1706 use feature ':default';
1709 use feature ':5.12';
1711 no feature 'unicode_strings';
1714 # $#- $#+ $#{%} etc.
1716 @x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
1717 @x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
1718 @x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
1719 @x = ($#{;}, $#{:}, $#{1}), $#_;
1722 # It's a known TODO that warnings are deparsed as bits, not textually.
1726 # [perl #86060] $( $| $) in regexps need braces
1737 # sort(foo(bar)) is interpreted as sort &foo(bar)
1738 # sort foo(bar) is interpreted as sort foo bar
1739 # parentheses are not optional in this case
1740 print sort(foo('bar'));
1742 print sort(foo('bar'));
1745 substr(my $a, 0, 0) = (foo(), bar());
1748 # This following line works around an unfixed bug that we are not trying to
1750 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1752 BEGIN { $^H{'foo'} = undef; }
1754 BEGIN { $^H{'bar'} = undef; }
1756 BEGIN { $^H{'baz'} = undef; }
1764 BEGIN { $^H{q[']} = '('; }
1767 # This following line works around an unfixed bug that we are not trying to
1769 # CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
1770 # hint hash changes that serialise the same way with sort %hh
1771 BEGIN { $^H{'a'} = 'b'; }
1773 BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
1778 # [perl #47361] do({}) and do +{} (variants of do-file)
1792 # [perl #77096] functions that do not follow the llafr
1793 () = (return 1) + time;
1794 () = (return ($1 + $2) * $3) + time;
1795 () = (return ($a xor $b)) + time;
1796 () = (do 'file') + time;
1797 () = (do ($1 + $2) * $3) + time;
1798 () = (do ($1 xor $2)) + time;
1800 () = (require 'foo') + 3;
1801 () = (require foo) + 3;
1802 () = (CORE::dump 1) + 3;
1813 # require(foo()) and do(foo())
1825 # [perl #97476] not() *does* follow the llafr
1826 $_ = ($a xor not +($1 || 2) ** 2);
1828 # Precedence conundrums with argument-less function calls
1836 # loopexes have assignment prec
1837 () = (CORE::dump a) | 'b';
1838 () = (goto a) | 'b';
1839 () = (last a) | 'b';
1840 () = (next a) | 'b';
1841 () = (redo a) | 'b';
1843 # [perl #63558] open local(*FH)
1845 pipe local *FH, local *FH;
1847 # [perl #91416] open "string"
1860 () = 'open'->[0]; #aelemfast
1865 () = 'open'->[$_]; #aelem
1870 () = 'open'->{0}; #helem
1891 () = 'a::]b'->{'0'};
1893 # [perl #74740] -(f()) vs -f()
1899 #[perl #30504] foreach-my postfix/prefix difference
1900 $_ = 'foo' foreach my ($foo1, $bar1, $baz1);
1901 foreach (my ($foo2, $bar2, $baz2)) { $_ = 'foo' }
1902 foreach my $i (my ($foo3, $bar3, $baz3)) { $i = 'foo' }
1904 $_ = 'foo' foreach (my($foo1, $bar1, $baz1));
1905 foreach $_ (my($foo2, $bar2, $baz2)) {
1908 foreach my $i (my($foo3, $bar3, $baz3)) {
1912 #[perl #108224] foreach with continue block
1913 foreach (1 .. 3) { print } continue { print "\n" }
1914 foreach (1 .. 3) { } continue { }
1915 foreach my $i (1 .. 3) { print $i } continue { print "\n" }
1916 foreach my $i (1 .. 3) { } continue { }
1918 foreach $_ (1 .. 3) {
1924 foreach $_ (1 .. 3) {
1930 foreach my $i (1 .. 3) {
1936 foreach my $i (1 .. 3) {
1957 # 'my' works with padrange op
1964 ($m3, $m4) = (1, 2);
1966 my($m5, $m6) = (1, 2);
1967 my($m7, undef, $m8) = (1, 2, 3);
1968 @z = ($m7, undef, $m8);
1969 ($m7, undef, $m8) = (1, 2, 3);
1971 # 'our/local' works with padrange op
1982 ($o3, $o4) = (1, 2);
1983 local($o3, $o4) = (1, 2);
1985 @z = local($o3, $o4);
1986 our($o5, $o6) = (1, 2);
1987 our($o7, undef, $o8) = (1, 2, 3);
1988 @z = ($o7, undef, $o8);
1989 @z = local($o7, undef, $o8);
1990 ($o7, undef, $o8) = (1, 2, 3);
1991 local($o7, undef, $o8) = (1, 2, 3);
1993 # 'state' works with padrange op
1994 # CONTEXT no strict; use feature 'state';
2001 ($s3, $s4) = (1, 2);
2003 # assignment of state lists isn't implemented yet
2004 #state($s5, $s6) = (1, 2);
2005 #state($s7, undef, $s8) = (1, 2, 3);
2006 #@z = ($s7, undef, $s8);
2007 ($s7, undef, $s8) = (1, 2, 3);
2009 # anon arrays with padrange
2014 # slices with padrange
2020 # binops with padrange
2034 my($a, $b, $c, $d, @e);
2039 @e = ($a, $b, $c) x $d;
2043 my($a, $b, $c) = @_;
2045 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
2046 # lexical subroutine
2047 # CONTEXT use feature 'lexical_subs';
2048 no warnings "experimental::lexical_subs";
2052 BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"}
2058 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
2059 # lexical "state" subroutine
2060 # CONTEXT use feature 'state', 'lexical_subs';
2061 no warnings 'experimental::lexical_subs';
2065 BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"}
2071 # SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
2072 # lexical subroutine scoping
2073 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
2091 # self-referential lexical subroutine
2092 # CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
2099 # lexical subroutine with outer declaration and inner definition
2100 # CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
2108 # TODO only partially fixed
2109 # lexical state subroutine with outer declaration and inner definition
2110 # CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
2123 # Elements of %# should not be confused with $#{ array }
2132 # Ampersand calls and scalar context
2139 &foo(scalar bar(), scalar baz());
2141 # coderef2text and prototyped sub calls [perl #123435]
2144 # prototypes with unary precedence
2147 sub optdollar(;$) {}
2148 sub optoptdollar(;;$) {}
2151 sub optoptsplat(;;*) {}
2154 sub optoptbar(;;_) {}
2157 sub optoptplus(;;+) {}
2160 sub optoptwack(;;\$) {}
2161 sub wackbrack(\[$]) {}
2162 sub optwackbrack(;\[$]) {}
2163 sub optoptwackbrack(;;\[$]) {}
2166 optoptdollar($a < $b);
2167 splat($a < $b); # Some of these deparse with ‘&’; if that changes, just
2168 optsplat($a < $b); # change the tests.
2169 optoptsplat($a < $b);
2175 optoptplus($a < $b);
2178 optoptwack($a = $b);
2180 optwackbrack($a = $b);
2181 optoptwackbrack($a = $b);
2186 optoptdollar($a < $b);
2189 &optoptsplat($a < $b);
2195 &optoptplus($a < $b);
2197 &optwack(\($a = $b));
2198 &optoptwack(\($a = $b));
2199 &wackbrack(\($a = $b));
2200 &optwackbrack(\($a = $b));
2201 &optoptwackbrack(\($a = $b));
2203 # ensure aelemfast works in the range -128..127 and that there's no
2207 $x = $a[-256] + $a[-255] + $a[-129] + $a[-128] + $a[-127] + $a[-1] + $a[0];
2208 $x = $a[1] + $a[126] + $a[127] + $a[128] + $a[255] + $a[256];
2210 $x = $b[-256] + $b[-255] + $b[-129] + $b[-128] + $b[-127] + $b[-1] + $b[0];
2211 $x = $b[1] + $b[126] + $b[127] + $b[128] + $b[255] + $b[256];
2213 # 'm' must be preserved in m??
2216 # \(@array) and \(..., (@array), ...)
2217 my(@array, %hash, @a, @b, %c, %d);
2220 () = \(@a, (@b), (%c), %d);
2221 () = \(@Foo::array);
2223 () = \(@Foo::a, (@Foo::b), (%Foo::c), %Foo::d);
2225 # subs synonymous with keywords
2229 use feature 'state';
2233 # CONTEXT use feature "state", 'refaliasing', 'lexical_subs'; no warnings 'experimental';
2245 \($x, my $a) = @{[\$x, \$x]};
2246 (\$x, \my $b) = @{[\$x, \$x]};
2258 \local($a[1]) = foo();
2261 \local @a[0,1] = (\$a)x2;
2268 \local($h{b}) = \$x;
2269 \@h{'a','b'} = foo();
2271 \local @h{'a','b'} = (\$x)x2;
2307 (\$_, $_) = \(1, 2);
2308 $_ == 3 ? \$_ : $_ = \3;
2309 $_ == 3 ? \$_ : \$x = \3;
2310 \($_ == 3 ? $_ : $x) = \3;
2311 for \my $topic (\$1, \$2) {
2314 for \state $topic (\$1, \$2) {
2317 for \our $topic (\$1, \$2) {
2320 for \$_ (\$1, \$2) {
2323 for \my @a ([1,2], [3,4]) {
2326 for \state @a ([1,2], [3,4]) {
2329 for \our @a ([1,2], [3,4]) {
2332 for \@_ ([1,2], [3,4]) {
2335 for \my %a ({5,6}, {7,8}) {
2338 for \our %a ({5,6}, {7,8}) {
2341 for \state %a ({5,6}, {7,8}) {
2344 for \%_ ({5,6}, {7,8}) {
2349 for \&a (sub { 9; }, sub { 10; }) {
2353 for \&a (sub { 9; }, sub { 10; }) {
2368 (\$x, \my $a) = @{[\$x, \$x];};
2369 (\$x, \my $b) = @{[\$x, \$x];};
2381 (\local $a[1]) = foo();
2382 (\@a[0, 1]) = foo();
2383 (\@a[2, 3]) = foo();
2384 (\local @a[0, 1]) = (\$a) x 2;
2390 \local $h{'a'} = \$x;
2391 (\local $h{'b'}) = \$x;
2392 (\@h{'a', 'b'}) = foo();
2393 (\@h{2, 3}) = foo();
2394 (\local @h{'a', 'b'}) = (\$x) x 2;
2420 (\our %zz) = {1, 2};
2430 (\$_, $_) = \(1, 2);
2431 $_ == 3 ? \$_ : $_ = \3;
2432 $_ == 3 ? \$_ : \$x = \3;
2433 ($_ == 3 ? \$_ : \$x) = \3;
2434 foreach \my $topic (\$1, \$2) {
2437 foreach \state $topic (\$1, \$2) {
2440 foreach \our $topic (\$1, \$2) {
2443 foreach \$_ (\$1, \$2) {
2446 foreach \my @a ([1, 2], [3, 4]) {
2449 foreach \state @a ([1, 2], [3, 4]) {
2452 foreach \our @a ([1, 2], [3, 4]) {
2455 foreach \@_ ([1, 2], [3, 4]) {
2458 foreach \my %a ({5, 6}, {7, 8}) {
2461 foreach \our %a ({5, 6}, {7, 8}) {
2464 foreach \state %a ({5, 6}, {7, 8}) {
2467 foreach \%_ ({5, 6}, {7, 8}) {
2472 foreach \&a (sub { 9; } , sub { 10; } ) {
2476 foreach \&a (sub { 9; } , sub { 10; } ) {
2485 $_ = join('???', pos $_);
2491 # my @a; exists $a[0]
2499 # my @a; delete $a[0]
2514 # my $x = "$h{foo}";
2516 my $x = "$h{'foo'}";
2518 # weird constant hash key
2520 my $x = $h{"\000\t\x{100}"};
2522 # multideref and packages
2524 my(%bar) = ('a', 'b');
2526 $bar{'k'} = $bar[200];
2527 $main::bar{'k'} = $main::bar[200];
2528 $foo::bar{'k'} = $foo::bar[200];
2530 $bar{'k'} = $bar[200];
2531 $main::bar{'k'} = $main::bar[200];
2532 $foo::bar{'k'} = $foo::bar[200];
2535 my(%bar) = ('a', 'b');
2537 $bar{'k'} = $bar[200];
2538 $main::bar{'k'} = $main::bar[200];
2539 $foo::bar{'k'} = $bar[200];
2541 $bar{'k'} = $foo::bar[200];
2542 $main::bar{'k'} = $main::bar[200];
2543 $foo::bar{'k'} = $foo::bar[200];
2545 # multideref and local
2547 local $h{'foo'}[0] = 1;
2549 # multideref and exists
2551 my $e = exists $h{'foo'}[$i];
2553 # multideref and delete
2555 my $e = delete $h{'foo'}[$i];
2557 # multideref with leading expression
2559 my $x = +($r // [])->{'foo'}[0];
2561 # multideref with complex middle index
2563 my $x = $h{'foo'}[$i + $j]{$k};
2565 # multideref with trailing non-simple index that initially looks simple
2566 # (i.e. the constant "3")
2568 my $x = +($r || {})->{'foo'}[$i + $j]{3 + $k};
2576 # CONTEXT use feature "bitwise"; no warnings "experimental::bitwise";
2593 # Should really use 'no warnings "experimental::signatures"',
2594 # but it doesn't yet deparse correctly.
2595 # anon subs used because this test framework doesn't deparse named subs
2596 # in the DATA code snippets.
2600 use feature 'signatures';
2602 sub ($a, $, $b = $glo::bal, $c = $a, $d = 'foo', $e = -37, $f = 0, $g = 1, $h = undef, $i = $a + 1, $j = /foo/, @) {
2608 # Signature and prototype
2610 use feature 'signatures';
2612 my $f = sub : prototype($$) ($a, $b) {
2618 # Signature and prototype and attrs
2620 use feature 'signatures';
2622 my $f = sub : prototype($$) lvalue ($a, $b) {
2628 # Signature and attrs
2630 use feature 'signatures';
2632 my $f = sub : lvalue method ($a, $b) {
2638 # named array slurp, null body
2640 use feature 'signatures';
2648 use feature 'signatures';
2656 use feature 'signatures';
2662 # parenthesised default arg
2664 use feature 'signatures';
2665 sub ($a, $b = (/foo/), $c = 1) {
2670 # parenthesised default arg with TARGMY
2672 use feature 'signatures';
2673 sub ($a, $b = ($a + 1), $c = 1) {
2680 use feature 'signatures';
2686 # padrange op within pattern code blocks
2687 /(?{ my($x, $y) = (); })/;
2689 /$a(?{ my($x, $y) = (); })/;
2690 my $r1 = qr/(?{ my($x, $y) = (); })/;
2691 my $r2 = qr/$a(?{ my($x, $y) = (); })/;
2693 # don't remove pattern whitespace escapes
2700 my $s1 :foo(f1, f2) bar(b1, b2);
2701 my @a1 :foo(f1, f2) bar(b1, b2);
2702 my %h1 :foo(f1, f2) bar(b1, b2);
2703 my($s2, @a2, %h2) :foo(f1, f2) bar(b1, b2);
2705 # my class attributes
2707 my Foo::Bar $s1 :foo(f1, f2) bar(b1, b2);
2708 my Foo::Bar @a1 :foo(f1, f2) bar(b1, b2);
2709 my Foo::Bar %h1 :foo(f1, f2) bar(b1, b2);
2710 my Foo::Bar ($s2, @a2, %h2) :foo(f1, f2) bar(b1, b2);
2712 my Foo::Bar $s3 :foo(f1, f2) bar(b1, b2);
2713 my Foo::Bar @a3 :foo(f1, f2) bar(b1, b2);
2714 my Foo::Bar %h3 :foo(f1, f2) bar(b1, b2);
2715 my Foo::Bar ($s4, @a4, %h4) :foo(f1, f2) bar(b1, b2);
2717 # avoid false positives in my $x :attribute
2718 'attributes'->import('main', \my $x1, 'foo(bar)'), my $y1;
2719 'attributes'->import('Fooo', \my $x2, 'foo(bar)'), my $y2;
2721 # hash slices and hash key/value slices
2724 @a = @h{'foo', 'bar'};
2725 @a = %h{'foo', 'bar'};
2726 @a = delete @h{'foo', 'bar'};
2727 @a = delete %h{'foo', 'bar'};
2728 @oa = @oh{'foo', 'bar'};
2729 @oa = %oh{'foo', 'bar'};
2730 @oa = delete @oh{'foo', 'bar'};
2731 @oa = delete %oh{'foo', 'bar'};
2733 # keys optimised away in void and scalar context
2747 # eq,const optimised away for (index() == -1)
2750 $c = index($a, $b) == 2;
2751 $c = rindex($a, $b) == 2;
2752 $c = index($a, $b) == -1;
2753 $c = rindex($a, $b) == -1;
2754 $c = index($a, $b) != -1;
2755 $c = rindex($a, $b) != -1;
2756 $c = (index($a, $b) == -1);
2757 $c = (rindex($a, $b) == -1);
2758 $c = (index($a, $b) != -1);
2759 $c = (rindex($a, $b) != -1);
2761 # eq,const,sassign,madmy optimised away for (index() == -1)
2764 $c = index($a, $b) == 2;
2765 $c = rindex($a, $b) == 2;
2766 $c = index($a, $b) == -1;
2767 $c = rindex($a, $b) == -1;
2768 $c = index($a, $b) != -1;
2769 $c = rindex($a, $b) != -1;
2770 $c = (index($a, $b) == -1);
2771 $c = (rindex($a, $b) == -1);
2772 $c = (index($a, $b) != -1);
2773 $c = (rindex($a, $b) != -1);
2776 my($a, $b, $c, $d, @a);
2777 $d = length $a . $b . $c;
2778 $d = length($a) . $b . $c;
2780 push @a, ($a . '') * $b;
2781 unshift @a, "$a" * ($b . '');
2782 print $a . 'x' . $b . $c;
2783 print $a . 'x' . $b . $c, $d;
2784 print $b . $c . ($a . $b);
2785 print $b . $c . ($a . $b);
2787 print $a . "\x{100}";
2789 # double-quoted multiconcat
2790 my($a, $b, $c, $d, @a);
2791 print "${a}x\x{100}$b$c";
2792 print "$a\Q$b\E$c\Ua$a\E\Lb$b\uc$c\E$a${b}c$c";
2793 print "A=$a[length 'b' . $c . 'd'] b=$b";
2795 print "\x{101}$a\x{100}";
2803 # sprintf multiconcat
2804 my($a, $b, $c, $d, @a);
2805 print sprintf("%s%s%%%sx%s\x{100}%s", $a, $b, $c, scalar @a, $d);
2807 # multiconcat with lexical assign
2808 my($a, $b, $c, $d, $e, @a);
2812 $d = 'foo' . $a . 'bar';
2815 $d = $a . $b . $c . @a;
2816 $e = ($d = $a . $b . $c);
2818 $a = $b . $c . ($a . $b);
2819 $e = f($d = !$a . $b) . $c;
2820 $d = "${a}x\x{100}$b$c";
2821 f($d = !$a . $b . $c);
2823 # multiconcat with lexical my
2824 my($a, $b, $c, $d, $e, @a);
2825 my $d1 = 'foo' . $a;
2828 my $d4 = 'foo' . $a . 'bar';
2830 my $d6 = $a . $b . $c;
2831 my $e7 = ($d = $a . $b . $c);
2832 my $d8 = !$a . $b . $c;
2833 my $d9 = $b . $c . ($a . $b);
2834 my $da = f($d = !$a . $b) . $c;
2835 my $dc = "${a}x\x{100}$b$c";
2836 f(my $db = !$a . $b . $c);
2837 my $dd = $a . $b . $c . @a;
2839 # multiconcat with lexical append
2840 my($a, $b, $c, $d, $e, @a);
2847 $d .= 'foo' . $a . 'bar';
2851 $e .= ($d = $a . $b . $c);
2852 $d .= !$a . $b . $c;
2853 $a .= $b . $c . ($a . $b);
2854 $e .= f($d .= !$a . $b) . $c;
2855 f($d .= !$a . $b . $c);
2856 $d .= "${a}x\x{100}$b$c";
2858 # multiconcat with expression assign
2864 $d = 'foo' . $a . 'bar';
2868 $e = ($d = $a . $b . $c);
2869 $a["-$b-"] = !$a . $b . $c;
2870 $a[$b]{$c}{$d ? $a : $b . $c} = !$a . $b . $c;
2871 $a = $b . $c . ($a . $b);
2872 $e = f($d = !$a . $b) . $c;
2873 $d = "${a}x\x{100}$b$c";
2874 f($d = !$a . $b . $c);
2876 # multiconcat with expression concat
2882 $d .= 'foo' . $a . 'bar';
2886 $e .= ($d .= $a . $b . $c);
2887 $a["-$b-"] .= !$a . $b . $c;
2888 $a[$b]{$c}{$d ? $a : $b . $c} .= !$a . $b . $c;
2889 $a .= $b . $c . ($a . $b);
2890 $e .= f($d .= !$a . $b) . $c;
2891 $d .= "${a}x\x{100}$b$c";
2892 f($d .= !$a . $b . $c);
2894 # multiconcat with CORE::sprintf
2895 # CONTEXT sub sprintf {}
2897 my $x = CORE::sprintf('%s%s', $a, $b);
2899 # multiconcat with backticks
2904 # multiconcat within qr//
2906 $r = qr/abc\Q$a-$b\Exyz/;
2908 # tr with unprintable characters
2913 # CORE::foo special case in bareword parsing
2914 print $CORE::foo, $CORE::foo::bar;
2915 print @CORE::foo, @CORE::foo::bar;
2916 print %CORE::foo, %CORE::foo::bar;
2917 print $CORE::foo{'a'}, $CORE::foo::bar{'a'};
2918 print &CORE::foo, &CORE::foo::bar;
2919 print &CORE::foo(), &CORE::foo::bar();
2920 print \&CORE::foo, \&CORE::foo::bar;
2921 print *CORE::foo, *CORE::foo::bar;
2922 print stat CORE::foo::, stat CORE::foo::bar;
2923 print CORE::foo:: 1;
2924 print CORE::foo::bar 2;
2926 # trailing colons on glob names
2929 print $foo, $foo::, $foo::::;
2930 print @foo, @foo::, @foo::::;
2931 print %foo, %foo::, %foo::::;
2932 print $foo{'a'}, $foo::{'a'}, $foo::::{'a'};
2933 print &foo, &foo::, &foo::::;
2934 print &foo(), &foo::(), &foo::::();
2935 print \&foo, \&foo::, \&foo::::;
2936 print *foo, *foo::, *foo::::;
2937 print stat Foo, stat Foo::::;
2941 # trailing colons mixed with CORE
2943 print $CORE, $CORE::, $CORE::::;
2944 print @CORE, @CORE::, @CORE::::;
2945 print %CORE, %CORE::, %CORE::::;
2946 print $CORE{'a'}, $CORE::{'a'}, $CORE::::{'a'};
2947 print &CORE, &CORE::, &CORE::::;
2948 print &CORE(), &CORE::(), &CORE::::();
2949 print \&CORE, \&CORE::, \&CORE::::;
2950 print *CORE, *CORE::, *CORE::::;
2951 print stat CORE, stat CORE::::;
2954 print $CORE::foo, $CORE::foo::, $CORE::foo::::;
2955 print @CORE::foo, @CORE::foo::, @CORE::foo::::;
2956 print %CORE::foo, %CORE::foo::, %CORE::foo::::;
2957 print $CORE::foo{'a'}, $CORE::foo::{'a'}, $CORE::foo::::{'a'};
2958 print &CORE::foo, &CORE::foo::, &CORE::foo::::;
2959 print &CORE::foo(), &CORE::foo::(), &CORE::foo::::();
2960 print \&CORE::foo, \&CORE::foo::, \&CORE::foo::::;
2961 print *CORE::foo, *CORE::foo::, *CORE::foo::::;
2962 print stat CORE::foo::, stat CORE::foo::::;
2963 print CORE::foo:: 1;
2964 print CORE::foo:::: 2;
2984 print exists &main::foo;
2985 print exists &{foo};
2988 print exists &main::foo;
2989 print exists &{foo};
2990 print exists &main::bar;
2991 # precedence of optimised-away 'keys' (OPpPADHV_ISKEYS/OPpRV2HV_ISKEYS)
2998 $res = keys(%h1) / 2 - 1;
2999 $res = keys(%h2) / 2 - 1;
3000 $res = keys(%$r1) / 2 - 1;
3001 $res = keys(%$r2) / 2 - 1;
3003 # ditto in presence of sub keys {}
3004 # CONTEXT sub keys {}
3009 CORE::keys(%h1) / 2;
3010 $res = CORE::keys %h1;
3011 $res = CORE::keys %h2;
3012 $res = CORE::keys %$r1;
3013 $res = CORE::keys %$r2;
3014 $res = CORE::keys(%h1) / 2 - 1;
3015 $res = CORE::keys(%h2) / 2 - 1;
3016 $res = CORE::keys(%$r1) / 2 - 1;
3017 $res = CORE::keys(%$r2) / 2 - 1;
3019 # concat: STACKED: ambiguity between .= and optimised nested
3022 (($a .= $a) .= $a) .= $a;
3024 # multiconcat: $$ within string
3029 # single state aggregate assignment
3030 # CONTEXT use feature "state";
3031 state @a = (1, 2, 3);
3032 state %h = ('a', 1, 'b', 2);
3034 # state var with attribute
3035 # CONTEXT use feature "state";
3037 state $y :shared = 1;
3039 state @b :shared = (1, 2);
3041 state %i :shared = ('a', 1, 'b', 2);
3043 # \our @a shouldn't be a list
3045 my(@l) = \our((@b));