This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Change OA_DANGEROUS description in regen/opcode*
[perl5.git] / lib / B / Deparse.t
CommitLineData
87a42246
MS
1#!./perl
2
3BEGIN {
62a6bb71 4 unshift @INC, 't';
9cd8f857
NC
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 }
87a42246
MS
10}
11
87a42246
MS
12use warnings;
13use strict;
507a68aa 14use Test::More;
87a42246 15
7741ceed 16my $tests = 25; # not counting those in the __DATA__ section
3036b99c 17
87a42246 18use B::Deparse;
09d856fb 19my $deparse = B::Deparse->new();
507a68aa 20isa_ok($deparse, 'B::Deparse', 'instantiate a B::Deparse object');
4da9a2ca 21my %deparse;
87a42246 22
ad46c0be
RH
23$/ = "\n####\n";
24while (<DATA>) {
25 chomp;
d8cf01c3 26 $tests ++;
e9c69003
NC
27 # This code is pinched from the t/lib/common.pl for TODO.
28 # It's not clear how to avoid duplication
a6087f24 29 my %meta = (context => '');
4da9a2ca 30 foreach my $what (qw(skip todo context options)) {
c4a350e6 31 s/^#\s*\U$what\E\s*(.*)\n//m and $meta{$what} = $1;
b871937f
NC
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
c4a350e6
NC
34 if ($meta{$what} && $meta{$what} =~ s/^\?//) {
35 my $temp = eval $meta{$what};
b871937f 36 if ($@) {
c4a350e6 37 die "# In \U$what\E code reason:\n# $meta{$what}\n$@";
b871937f 38 }
c4a350e6 39 $meta{$what} = $temp;
e9c69003 40 }
e9c69003
NC
41 }
42
4a4b8592 43 s/^\s*#\s*(.*)$//mg;
507a68aa
NC
44 my $desc = $1;
45 die "Missing name in test $_" unless defined $desc;
e9c69003 46
c4a350e6 47 if ($meta{skip}) {
e9c69003 48 # Like this to avoid needing a label SKIP:
c4a350e6 49 Test::More->builder->skip($meta{skip});
e9c69003
NC
50 next;
51 }
52
ad46c0be
RH
53 my ($input, $expected);
54 if (/(.*)\n>>>>\n(.*)/s) {
55 ($input, $expected) = ($1, $2);
56 }
57 else {
58 ($input, $expected) = ($_, $_);
59 }
87a42246 60
4da9a2ca
FC
61 # parse options if necessary
62 my $deparse = $meta{options}
63 ? $deparse{$meta{options}} ||=
64 new B::Deparse split /,/, $meta{options}
65 : $deparse;
66
a6087f24
NC
67 my $coderef = eval "$meta{context};\n" . <<'EOC' . "sub {$input}";
68# Tell B::Deparse about our ambient pragmas
69my ($hint_bits, $warning_bits, $hinthash);
70BEGIN {
71 ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H);
72}
73$deparse->ambient_pragmas (
74 hint_bits => $hint_bits,
75 warning_bits => $warning_bits,
76 '%^H' => $hinthash,
77);
78EOC
87a42246 79
ad46c0be 80 if ($@) {
507a68aa 81 is($@, "", "compilation of $desc");
ad46c0be
RH
82 }
83 else {
84 my $deparsed = $deparse->coderef2text( $coderef );
31c6271a
RD
85 my $regex = $expected;
86 $regex =~ s/(\S+)/\Q$1/g;
87 $regex =~ s/\s+/\\s+/g;
88 $regex = '^\{\s*' . $regex . '\s*\}$';
b871937f 89
c4a350e6 90 local $::TODO = $meta{todo};
507a68aa 91 like($deparsed, qr/$regex/, $desc);
87a42246 92 }
87a42246
MS
93}
94
9187b6e4
FC
95# Reset the ambient pragmas
96{
97 my ($b, $w, $h);
98 BEGIN {
99 ($b, $w, $h) = ($^H, ${^WARNING_BITS}, \%^H);
100 }
101 $deparse->ambient_pragmas (
102 hint_bits => $b,
103 warning_bits => $w,
104 '%^H' => $h,
105 );
106}
107
87a42246 108use constant 'c', 'stuff';
507a68aa
NC
109is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
110 'the subroutine generated by use constant deparses');
87a42246 111
09d856fb 112my $a = 0;
507a68aa
NC
113is($deparse->coderef2text(sub{(-1) ** $a }), "{\n (-1) ** \$a;\n}",
114 'anon sub capturing an external lexical');
87a42246 115
d989cdac
SM
116use constant cr => ['hello'];
117my $string = "sub " . $deparse->coderef2text(\&cr);
0707d6cc 118my $val = (eval $string)->() or diag $string;
507a68aa
NC
119is(ref($val), 'ARRAY', 'constant array references deparse');
120is($val->[0], 'hello', 'and return the correct value');
87a42246 121
87a42246 122my $path = join " ", map { qq["-I$_"] } @INC;
87a42246 123
7cde0a5f 124$a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
e69a2255 125$a =~ s/-e syntax OK\n//g;
d2bc402e 126$a =~ s/.*possible typo.*\n//; # Remove warning line
82f96200 127$a =~ s/.*-i used with no filenames.*\n//; # Remove warning line
87a42246
MS
128$a =~ s{\\340\\242}{\\s} if (ord("\\") == 224); # EBCDIC, cp 1047 or 037
129$a =~ s{\\274\\242}{\\s} if (ord("\\") == 188); # $^O eq 'posix-bc'
c96cf1c0 130$b = quotemeta <<'EOF';
d2bc402e
RGS
131BEGIN { $^I = ".bak"; }
132BEGIN { $^W = 1; }
133BEGIN { $/ = "\n"; $\ = "\n"; }
87a42246
MS
134LINE: while (defined($_ = <ARGV>)) {
135 chomp $_;
f86ea535 136 our(@F) = split(' ', $_, 0);
87a42246
MS
137 '???';
138}
87a42246 139EOF
c96cf1c0
FC
140$b =~ s/our\\\(\\\@F\\\)/our[( ]\@F\\)?/; # accept both our @F and our(@F)
141like($a, qr/$b/,
507a68aa 142 'command line flags deparse as BEGIN blocks setting control variables');
87a42246 143
5b4ee549
NC
144$a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`;
145$a =~ s/-e syntax OK\n//g;
146is($a, "use constant ('PI', 4);\n",
147 "Proxy Constant Subroutines must not show up as (incorrect) prototypes");
148
579a54dc 149#Re: perlbug #35857, patch #24505
b3980c39
YO
150#handle warnings::register-ed packages properly.
151package B::Deparse::Wrapper;
152use strict;
153use warnings;
154use warnings::register;
155sub getcode {
579a54dc 156 my $deparser = B::Deparse->new();
b3980c39
YO
157 return $deparser->coderef2text(shift);
158}
159
2990415a
FR
160package Moo;
161use overload '0+' => sub { 42 };
162
b3980c39
YO
163package main;
164use strict;
165use warnings;
71c4dbc3 166use constant GLIPP => 'glipp';
2990415a
FR
167use constant PI => 4;
168use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
3779476a 169use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
aaf9c2b2 170BEGIN { delete $::Fcntl::{O_APPEND}; }
2990415a 171use POSIX qw/O_CREAT/;
b3980c39 172sub test {
579a54dc
RGS
173 my $val = shift;
174 my $res = B::Deparse::Wrapper::getcode($val);
507a68aa
NC
175 like($res, qr/use warnings/,
176 '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
b3980c39
YO
177}
178my ($q,$p);
179my $x=sub { ++$q,++$p };
180test($x);
181eval <<EOFCODE and test($x);
182 package bar;
183 use strict;
184 use warnings;
185 use warnings::register;
186 package main;
187 1
188EOFCODE
189
d1dc589d
FC
190# Exotic sub declarations
191$a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
192$a =~ s/-e syntax OK\n//g;
193is($a, <<'EOCODG', "sub :::: and sub ::::::");
194sub :::: {
195
196}
197sub :::::: {
198
199}
200EOCODG
201
f2734596 202# [perl #117311]
203$a = `$^X $path "-MO=Deparse,-l" -e "map{ eval(0) }()" 2>&1`;
204$a =~ s/-e syntax OK\n//g;
205is($a, <<'EOCODH', "[perl #117311] [PATCH] -l option ('#line ...') does not emit ^Ls in the output");
206#line 1 "-e"
207map {
208#line 1 "-e"
209eval 0;} ();
210EOCODH
211
640d5d41
FC
212# [perl #33752]
213{
214 my $code = <<"EOCODE";
215{
216 our \$\x{1e1f}\x{14d}\x{14d};
217}
218EOCODE
219 my $deparsed
220 = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
221 s/$ \n//x for $deparsed, $code;
222 is $deparsed, $code, 'our $funny_Unicode_chars';
223}
224
bdabb2d5
FC
225# [perl #62500]
226$a =
227 `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
228$a =~ s/-e syntax OK\n//g;
229is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
230sub BEGIN {
231 *CORE::GLOBAL::require = sub {
232 1;
233 }
234 ;
235}
236EOCODF
237
894e98ac
FC
238# [perl #91384]
239$a =
240 `$^X $path "-MO=Deparse" -e "BEGIN{*Acme::Acme:: = *Acme::}" 2>&1`;
241like($a, qr/-e syntax OK/,
242 "Deparse does not hang when traversing stash circularities");
243
bb8996b8 244# [perl #93990]
08412a26 245@] = ();
73f4c4fe 246is($deparse->coderef2text(sub{ print "foo@{]}" }),
bb8996b8 247q<{
73f4c4fe 248 print "foo@{]}";
08412a26 249}>, 'curly around to interpolate "@{]}"');
73f4c4fe 250is($deparse->coderef2text(sub{ print "foo@{-}" }),
bb8996b8 251q<{
73f4c4fe 252 print "foo@-";
bb8996b8
HY
253}>, 'no need to curly around to interpolate "@-"');
254
1c74777c
FC
255# Strict hints in %^H are mercilessly suppressed
256$a =
257 `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
258unlike($a, qr/BEGIN/,
259 "Deparse does not emit strict hh hints");
260
3036b99c
FC
261# ambient_pragmas should not mess with strict settings.
262SKIP: {
263 skip "requires 5.11", 1 unless $] >= 5.011;
264 eval q`
3036b99c 265 BEGIN {
d1718a7c 266 # Clear out all hints
3036b99c 267 %^H = ();
d1718a7c 268 $^H = 0;
3036b99c
FC
269 new B::Deparse -> ambient_pragmas(strict => 'all');
270 }
271 use 5.011; # should enable strict
272 ok !eval '$do_noT_create_a_variable_with_this_name = 1',
273 'ambient_pragmas do not mess with compiling scope';
274 `;
275}
276
93a8ff62
FC
277# multiple statements on format lines
278$a = `$^X $path "-MO=Deparse" -e "format =" -e "\@" -e "x();z()" -e. 2>&1`;
279$a =~ s/-e syntax OK\n//g;
93a8ff62
FC
280is($a, <<'EOCODH', 'multiple statements on format lines');
281format STDOUT =
282@
283x(); z()
284.
285EOCODH
286
7741ceed
FC
287# CORE::format
288$a = readpipe qq`$^X $path "-MO=Deparse" -e "use feature q|:all|;`
289 .qq` my sub format; CORE::format =" -e. 2>&1`;
290like($a, qr/CORE::format/, 'CORE::format when lex format sub is in scope');
291
fea7fb25
DM
292# literal big chars under 'use utf8'
293is($deparse->coderef2text(sub{ use utf8; /€/; }),
294'{
295 /\x{20ac}/;
296}',
297"qr/euro/");
298
e54915d6
FC
299# STDERR when deparsing sub calls
300# For a short while the output included 'While deparsing'
301$a = `$^X $path "-MO=Deparse" -e "foo()" 2>&1`;
302$a =~ s/-e syntax OK\n//g;
303is($a, <<'EOCODI', 'no extra output when deparsing foo()');
304foo();
305EOCODI
306
7741ceed
FC
307# CORE::no
308$a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
309 .qq`"use feature q|:all|; my sub no; CORE::no less" 2>&1`;
310like($a, qr/my sub no;\n\(\);\nCORE::no less;/,
311 'CORE::no after my sub no');
312
313# CORE::use
314$a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
315 .qq`"use feature q|:all|; my sub use; CORE::use less" 2>&1`;
316like($a, qr/my sub use;\n\(\);\nCORE::use less;/,
317 'CORE::use after my sub use');
318
319# CORE::__DATA__
320$a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
321 .qq`"use feature q|:all|; my sub __DATA__; `
322 .qq`CORE::__DATA__" 2>&1`;
323like($a, qr/my sub __DATA__;\n\(\);\nCORE::__DATA__/,
324 'CORE::__DATA__ after my sub __DATA__');
325
93a8ff62 326
d8cf01c3 327done_testing($tests);
507a68aa 328
ad46c0be 329__DATA__
b8346d05
KW
330# TODO [perl #120950] This succeeds when run a 2nd time
331# y/uni/code/
332tr/\x{345}/\x{370}/;
333####
334# y/uni/code/ [perl #120950] This 2nd instance succeeds
335tr/\x{345}/\x{370}/;
336####
507a68aa 337# A constant
ad46c0be
RH
3381;
339####
507a68aa 340# Constants in a block
f5b5c2a3 341# CONTEXT no warnings;
ad46c0be 342{
ad46c0be
RH
343 '???';
344 2;
345}
346####
507a68aa 347# Lexical and simple arithmetic
ad46c0be
RH
348my $test;
349++$test and $test /= 2;
350>>>>
351my $test;
352$test /= 2 if ++$test;
353####
507a68aa 354# list x
ad46c0be
RH
355-((1, 2) x 2);
356####
507a68aa 357# lvalue sub
ad46c0be
RH
358{
359 my $test = sub : lvalue {
360 my $x;
361 }
362 ;
363}
364####
507a68aa 365# method
ad46c0be
RH
366{
367 my $test = sub : method {
368 my $x;
369 }
370 ;
371}
372####
507a68aa 373# block with continue
87a42246 374{
ad46c0be 375 234;
f99a63a2 376}
ad46c0be
RH
377continue {
378 123;
87a42246 379}
ce4e655d 380####
507a68aa 381# lexical and package scalars
ce4e655d
RH
382my $x;
383print $main::x;
384####
507a68aa 385# lexical and package arrays
ce4e655d
RH
386my @x;
387print $main::x[1];
14a55f98 388####
507a68aa 389# lexical and package hashes
14a55f98
RH
390my %x;
391$x{warn()};
ad8caead 392####
66786896
FC
393# our (LIST)
394our($foo, $bar, $baz);
395####
56cd2ef8
FC
396# CONTEXT { package Dog } use feature "state";
397# variables with declared classes
398my Dog $spot;
399our Dog $spotty;
400state Dog $spotted;
401my Dog @spot;
402our Dog @spotty;
403state Dog @spotted;
404my Dog %spot;
405our Dog %spotty;
406state Dog %spotted;
407my Dog ($foo, @bar, %baz);
408our Dog ($phoo, @barr, %bazz);
409state Dog ($fough, @barre, %bazze);
410####
f3515641
FC
411# local our
412local our $rhubarb;
5f4d8496 413local our($rhu, $barb);
f3515641 414####
507a68aa 415# <>
ad8caead
RGS
416my $foo;
417$_ .= <ARGV> . <$foo>;
cef22867 418####
507a68aa 419# \x{}
11454c59 420my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
4ae52e81 421####
507a68aa 422# s///e
4ae52e81 423s/x/'y';/e;
ef90d20a
FC
424s/x/$a;/e;
425s/x/complex_expression();/e;
241416b8 426####
507a68aa 427# block
241416b8
DM
428{ my $x; }
429####
507a68aa 430# while 1
241416b8
DM
431while (1) { my $k; }
432####
507a68aa 433# trailing for
241416b8
DM
434my ($x,@a);
435$x=1 for @a;
436>>>>
437my($x, @a);
0bb5f065 438$x = 1 foreach (@a);
241416b8 439####
507a68aa 440# 2 arguments in a 3 argument for
241416b8
DM
441for (my $i = 0; $i < 2;) {
442 my $z = 1;
443}
444####
507a68aa 445# 3 argument for
241416b8
DM
446for (my $i = 0; $i < 2; ++$i) {
447 my $z = 1;
448}
449####
507a68aa 450# 3 argument for again
241416b8
DM
451for (my $i = 0; $i < 2; ++$i) {
452 my $z = 1;
453}
454####
22584011
FC
455# 3-argument for with inverted condition
456for (my $i; not $i;) {
457 die;
458}
459for (my $i; not $i; ++$i) {
460 die;
461}
88a758b5
FC
462for (my $a; not +($1 || 2) ** 2;) {
463 die;
464}
22584011
FC
465Something_to_put_the_loop_in_void_context();
466####
507a68aa 467# while/continue
241416b8
DM
468my $i;
469while ($i) { my $z = 1; } continue { $i = 99; }
470####
507a68aa 471# foreach with my
09d856fb 472foreach my $i (1, 2) {
241416b8
DM
473 my $z = 1;
474}
475####
4da9a2ca
FC
476# OPTIONS -p
477# foreach with my under -p
478foreach my $i (1) {
479 die;
480}
481####
507a68aa 482# foreach
241416b8
DM
483my $i;
484foreach $i (1, 2) {
485 my $z = 1;
486}
487####
507a68aa 488# foreach, 2 mys
241416b8
DM
489my $i;
490foreach my $i (1, 2) {
491 my $z = 1;
492}
493####
507a68aa 494# foreach with our
241416b8
DM
495foreach our $i (1, 2) {
496 my $z = 1;
497}
498####
507a68aa 499# foreach with my and our
241416b8
DM
500my $i;
501foreach our $i (1, 2) {
502 my $z = 1;
503}
3ac6e0f9 504####
bcff4148
FC
505# foreach with state
506# CONTEXT use feature "state";
507foreach state $i (1, 2) {
508 state $z = 1;
509}
510####
507a68aa 511# reverse sort
3ac6e0f9
RGS
512my @x;
513print reverse sort(@x);
514####
507a68aa 515# sort with cmp
3ac6e0f9
RGS
516my @x;
517print((sort {$b cmp $a} @x));
518####
507a68aa 519# reverse sort with block
3ac6e0f9
RGS
520my @x;
521print((reverse sort {$b <=> $a} @x));
36d57d93 522####
507a68aa 523# foreach reverse
36d57d93
RGS
524our @a;
525print $_ foreach (reverse @a);
aae53c41 526####
507a68aa 527# foreach reverse (not inplace)
aae53c41
RGS
528our @a;
529print $_ foreach (reverse 1, 2..5);
f86ea535 530####
507a68aa 531# bug #38684
f86ea535
SM
532our @ary;
533@ary = split(' ', 'foo', 0);
31c6271a 534####
de183bbb
FC
535# Split to our array
536our @array = split(//, 'foo', 0);
537####
ef7999f1
FC
538# Split to my array
539my @array = split(//, 'foo', 0);
540####
507a68aa 541# bug #40055
31c6271a
RD
542do { () };
543####
507a68aa 544# bug #40055
31c6271a 545do { my $x = 1; $x };
d9002312 546####
507a68aa 547# <20061012113037.GJ25805@c4.convolution.nl>
d9002312
SM
548my $f = sub {
549 +{[]};
550} ;
8b2d6640 551####
507a68aa 552# bug #43010
8b2d6640
FC
553'!@$%'->();
554####
507a68aa 555# bug #43010
8b2d6640
FC
556::();
557####
507a68aa 558# bug #43010
8b2d6640
FC
559'::::'->();
560####
507a68aa 561# bug #43010
8b2d6640 562&::::;
09d856fb 563####
1b38d782
FC
564# [perl #77172]
565package rt77172;
566sub foo {} foo & & & foo;
567>>>>
568package rt77172;
569foo(&{&} & foo());
570####
507a68aa 571# variables as method names
09d856fb
CK
572my $bar;
573'Foo'->$bar('orz');
35a99a08 574'Foo'->$bar('orz') = 'a stranger stranger than before';
09d856fb 575####
507a68aa 576# constants as method names
09d856fb
CK
577'Foo'->bar('orz');
578####
507a68aa 579# constants as method names without ()
09d856fb 580'Foo'->bar;
0ced6c29 581####
28bfcb02 582# [perl #47359] "indirect" method call notation
1bf8bbb0
FC
583our @bar;
584foo{@bar}+1,->foo;
585(foo{@bar}+1),foo();
586foo{@bar}1 xor foo();
587>>>>
588our @bar;
589(foo { @bar } 1)->foo;
590(foo { @bar } 1), foo();
591foo { @bar } 1 xor foo();
592####
e9c69003 593# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
205fef88 594# CONTEXT use feature ':5.10';
507a68aa 595# say
7ddd1a01
NC
596say 'foo';
597####
8f57bb34 598# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
8f57bb34
NC
599# CONTEXT use 5.10.0;
600# say in the context of use 5.10.0
601say 'foo';
602####
603# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
8f57bb34
NC
604# say with use 5.10.0
605use 5.10.0;
606say 'foo';
607>>>>
608no feature;
609use feature ':5.10';
610say 'foo';
611####
612# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
613# say with use feature ':5.10';
614use feature ':5.10';
615say 'foo';
616>>>>
617use feature 'say', 'state', 'switch';
618say 'foo';
619####
620# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
8f57bb34
NC
621# CONTEXT use feature ':5.10';
622# say with use 5.10.0 in the context of use feature
623use 5.10.0;
624say 'foo';
625>>>>
626no feature;
627use feature ':5.10';
628say 'foo';
629####
630# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
631# CONTEXT use 5.10.0;
632# say with use feature ':5.10' in the context of use 5.10.0
633use feature ':5.10';
634say 'foo';
635>>>>
636say 'foo';
637####
638# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
639# CONTEXT use feature ':5.15';
640# __SUB__
641__SUB__;
642####
643# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
8f57bb34
NC
644# CONTEXT use 5.15.0;
645# __SUB__ in the context of use 5.15.0
646__SUB__;
647####
648# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
8f57bb34
NC
649# __SUB__ with use 5.15.0
650use 5.15.0;
651__SUB__;
652>>>>
653no feature;
654use feature ':5.16';
655__SUB__;
656####
657# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
658# __SUB__ with use feature ':5.15';
659use feature ':5.15';
660__SUB__;
661>>>>
662use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
663__SUB__;
664####
665# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
8f57bb34
NC
666# CONTEXT use feature ':5.15';
667# __SUB__ with use 5.15.0 in the context of use feature
668use 5.15.0;
669__SUB__;
670>>>>
671no feature;
672use feature ':5.16';
673__SUB__;
674####
675# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
676# CONTEXT use 5.15.0;
677# __SUB__ with use feature ':5.15' in the context of use 5.15.0
678use feature ':5.15';
679__SUB__;
680>>>>
681__SUB__;
682####
e9c69003 683# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
205fef88 684# CONTEXT use feature ':5.10';
507a68aa 685# state vars
0ced6c29
RGS
686state $x = 42;
687####
e9c69003 688# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
205fef88 689# CONTEXT use feature ':5.10';
507a68aa 690# state var assignment
7ddd1a01
NC
691{
692 my $y = (state $x = 42);
693}
694####
e9c69003 695# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
205fef88 696# CONTEXT use feature ':5.10';
c4a6f826 697# state vars in anonymous subroutines
7ddd1a01
NC
698$a = sub {
699 state $x;
700 return $x++;
701}
702;
644741fd
NC
703####
704# SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
507a68aa 705# each @array;
644741fd
NC
706each @ARGV;
707each @$a;
708####
709# SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
507a68aa 710# keys @array; values @array
644741fd
NC
711keys @$a if keys @ARGV;
712values @ARGV if values @$a;
35925e80 713####
507a68aa 714# Anonymous arrays and hashes, and references to them
35925e80
RGS
715my $a = {};
716my $b = \{};
717my $c = [];
718my $d = \[];
9210de83
FR
719####
720# SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
0f539b13 721# CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
507a68aa 722# implicit smartmatch in given/when
9210de83
FR
723given ('foo') {
724 when ('bar') { continue; }
725 when ($_ ~~ 'quux') { continue; }
726 default { 0; }
727}
7ecdd211 728####
507a68aa 729# conditions in elsifs (regression in change #33710 which fixed bug #37302)
7ecdd211
PJ
730if ($a) { x(); }
731elsif ($b) { x(); }
732elsif ($a and $b) { x(); }
733elsif ($a or $b) { x(); }
734else { x(); }
03b22f1b 735####
507a68aa 736# interpolation in regexps
03b22f1b
RGS
737my($y, $t);
738/x${y}z$t/;
227375e1 739####
4a4b8592 740# TODO new undocumented cpan-bug #33708
507a68aa 741# cpan-bug #33708
227375e1
RU
742%{$_ || {}}
743####
4a4b8592 744# TODO hash constants not yet fixed
507a68aa 745# cpan-bug #33708
227375e1
RU
746use constant H => { "#" => 1 }; H->{"#"}
747####
4a4b8592 748# TODO optimized away 0 not yet fixed
507a68aa 749# cpan-bug #33708
227375e1 750foreach my $i (@_) { 0 }
edbe35ea 751####
507a68aa 752# tests with not, not optimized
07f3cdf5 753my $c;
edbe35ea
VP
754x() unless $a;
755x() if not $a and $b;
756x() if $a and not $b;
757x() unless not $a and $b;
758x() unless $a and not $b;
759x() if not $a or $b;
760x() if $a or not $b;
761x() unless not $a or $b;
762x() unless $a or not $b;
07f3cdf5
VP
763x() if $a and not $b and $c;
764x() if not $a and $b and not $c;
765x() unless $a and not $b and $c;
766x() unless not $a and $b and not $c;
767x() if $a or not $b or $c;
768x() if not $a or $b or not $c;
769x() unless $a or not $b or $c;
770x() unless not $a or $b or not $c;
edbe35ea 771####
507a68aa 772# tests with not, optimized
07f3cdf5 773my $c;
edbe35ea
VP
774x() if not $a;
775x() unless not $a;
776x() if not $a and not $b;
777x() unless not $a and not $b;
778x() if not $a or not $b;
779x() unless not $a or not $b;
07f3cdf5
VP
780x() if not $a and not $b and $c;
781x() unless not $a and not $b and $c;
782x() if not $a or not $b or $c;
783x() unless not $a or not $b or $c;
784x() if not $a and not $b and not $c;
785x() unless not $a and not $b and not $c;
786x() if not $a or not $b or not $c;
787x() unless not $a or not $b or not $c;
788x() unless not $a or not $b or not $c;
edbe35ea 789>>>>
07f3cdf5 790my $c;
edbe35ea
VP
791x() unless $a;
792x() if $a;
793x() unless $a or $b;
794x() if $a or $b;
795x() unless $a and $b;
07f3cdf5
VP
796x() if $a and $b;
797x() if not $a || $b and $c;
798x() unless not $a || $b and $c;
799x() if not $a && $b or $c;
800x() unless not $a && $b or $c;
801x() unless $a or $b or $c;
802x() if $a or $b or $c;
803x() unless $a and $b and $c;
804x() if $a and $b and $c;
805x() unless not $a && $b && $c;
71c4dbc3 806####
507a68aa 807# tests that should be constant folded
71c4dbc3
VP
808x() if 1;
809x() if GLIPP;
810x() if !GLIPP;
811x() if GLIPP && GLIPP;
812x() if !GLIPP || GLIPP;
813x() if do { GLIPP };
814x() if do { no warnings 'void'; 5; GLIPP };
815x() if do { !GLIPP };
816if (GLIPP) { x() } else { z() }
817if (!GLIPP) { x() } else { z() }
818if (GLIPP) { x() } elsif (GLIPP) { z() }
819if (!GLIPP) { x() } elsif (GLIPP) { z() }
820if (GLIPP) { x() } elsif (!GLIPP) { z() }
821if (!GLIPP) { x() } elsif (!GLIPP) { z() }
822if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
823if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
824if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
825>>>>
826x();
827x();
828'???';
829x();
830x();
831x();
832x();
833do {
834 '???'
835};
836do {
837 x()
838};
839do {
840 z()
841};
842do {
843 x()
844};
845do {
846 z()
847};
848do {
849 x()
850};
851'???';
852do {
853 t()
854};
855'???';
856!1;
857####
719c50dc
RGS
858# TODO constant deparsing has been backed out for 5.12
859# XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
507a68aa 860# tests that shouldn't be constant folded
ac0f1413
NC
861# It might be fundamentally impossible to make this work on ithreads, in which
862# case the TODO should become a SKIP
71c4dbc3
VP
863x() if $a;
864if ($a == 1) { x() } elsif ($b == 2) { z() }
865if (do { foo(); GLIPP }) { x() }
866if (do { $a++; GLIPP }) { x() }
867>>>>
868x() if $a;
869if ($a == 1) { x(); } elsif ($b == 2) { z(); }
2990415a
FR
870if (do { foo(); GLIPP }) { x(); }
871if (do { ++$a; GLIPP }) { x(); }
872####
0fa4a265 873# TODO constant deparsing has been backed out for 5.12
507a68aa 874# tests for deparsing constants
2990415a
FR
875warn PI;
876####
0fa4a265 877# TODO constant deparsing has been backed out for 5.12
507a68aa 878# tests for deparsing imported constants
3779476a 879warn O_TRUNC;
2990415a 880####
0fa4a265 881# TODO constant deparsing has been backed out for 5.12
507a68aa 882# tests for deparsing re-exported constants
2990415a
FR
883warn O_CREAT;
884####
0fa4a265 885# TODO constant deparsing has been backed out for 5.12
507a68aa 886# tests for deparsing imported constants that got deleted from the original namespace
aaf9c2b2 887warn O_APPEND;
2990415a 888####
0fa4a265
DM
889# TODO constant deparsing has been backed out for 5.12
890# XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
507a68aa 891# tests for deparsing constants which got turned into full typeglobs
ac0f1413
NC
892# It might be fundamentally impossible to make this work on ithreads, in which
893# case the TODO should become a SKIP
2990415a
FR
894warn O_EXCL;
895eval '@Fcntl::O_EXCL = qw/affe tiger/;';
896warn O_EXCL;
897####
0fa4a265 898# TODO constant deparsing has been backed out for 5.12
507a68aa 899# tests for deparsing of blessed constant with overloaded numification
2990415a 900warn OVERLOADED_NUMIFICATION;
79289e05 901####
507a68aa 902# strict
79289e05 903no strict;
415d4c68
FC
904print $x;
905use strict 'vars';
906print $main::x;
907use strict 'subs';
908print $main::x;
909use strict 'refs';
910print $main::x;
911no strict 'vars';
79289e05
NC
912$x;
913####
914# TODO Subsets of warnings could be encoded textually, rather than as bitflips.
507a68aa 915# subsets of warnings
79289e05
NC
916no warnings 'deprecated';
917my $x;
918####
919# TODO Better test for CPAN #33708 - the deparsed code has different behaviour
507a68aa 920# CPAN #33708
79289e05
NC
921use strict;
922no warnings;
923
924foreach (0..3) {
925 my $x = 2;
926 {
927 my $x if 0;
928 print ++$x, "\n";
929 }
930}
d83f38d8 931####
507a68aa 932# no attribute list
d83f38d8
NC
933my $pi = 4;
934####
2dc78664
NC
935# SKIP ?$] > 5.013006 && ":= is now a syntax error"
936# := treated as an empty attribute list
d83f38d8
NC
937no warnings;
938my $pi := 4;
939>>>>
940no warnings;
941my $pi = 4;
942####
507a68aa 943# : = empty attribute list
d83f38d8
NC
944my $pi : = 4;
945>>>>
946my $pi = 4;
689e417f 947####
507a68aa 948# in place sort
689e417f
VP
949our @a;
950my @b;
951@a = sort @a;
952@b = sort @b;
953();
954####
507a68aa 955# in place reverse
689e417f
VP
956our @a;
957my @b;
958@a = reverse @a;
959@b = reverse @b;
960();
06fc6867 961####
507a68aa 962# #71870 Use of uninitialized value in bitwise and B::Deparse
06fc6867
VP
963my($r, $s, @a);
964@a = split(/foo/, $s, 0);
965$r = qr/foo/;
966@a = split(/$r/, $s, 0);
967();
98a1a137 968####
507a68aa 969# package declaration before label
98a1a137
Z
970{
971 package Foo;
972 label: print 123;
973}
538f5756 974####
507a68aa 975# shift optimisation
538f5756
RZ
976shift;
977>>>>
978shift();
979####
507a68aa 980# shift optimisation
538f5756
RZ
981shift @_;
982####
507a68aa 983# shift optimisation
538f5756
RZ
984pop;
985>>>>
986pop();
987####
507a68aa 988# shift optimisation
538f5756 989pop @_;
a539498a 990####
507a68aa 991#[perl #20444]
a539498a
FC
992"foo" =~ (1 ? /foo/ : /bar/);
993"foo" =~ (1 ? y/foo// : /bar/);
5e5a1632 994"foo" =~ (1 ? y/foo//r : /bar/);
a539498a
FC
995"foo" =~ (1 ? s/foo// : /bar/);
996>>>>
997'foo' =~ ($_ =~ /foo/);
998'foo' =~ ($_ =~ tr/fo//);
5e5a1632 999'foo' =~ ($_ =~ tr/fo//r);
a539498a 1000'foo' =~ ($_ =~ s/foo//);
e0ab66ad 1001####
5e5a1632
FC
1002# The fix for [perl #20444] broke this.
1003'foo' =~ do { () };
1004####
4b58603b
FC
1005# [perl #81424] match against aelemfast_lex
1006my @s;
1007print /$s[1]/;
1008####
36727b53
FC
1009# /$#a/
1010print /$#main::a/;
1011####
b9bc576f 1012# [perl #91318] /regexp/applaud
09622ee2
FC
1013print /a/a, s/b/c/a;
1014print /a/aa, s/b/c/aa;
1015print /a/p, s/b/c/p;
1016print /a/l, s/b/c/l;
1017print /a/u, s/b/c/u;
b9bc576f
FC
1018{
1019 use feature "unicode_strings";
09622ee2 1020 print /a/d, s/b/c/d;
b9bc576f
FC
1021}
1022{
1023 use re "/u";
09622ee2 1024 print /a/d, s/b/c/d;
b9bc576f 1025}
dff5ffe4
FC
1026{
1027 use 5.012;
1028 print /a/d, s/b/c/d;
1029}
b9bc576f 1030>>>>
09622ee2
FC
1031print /a/a, s/b/c/a;
1032print /a/aa, s/b/c/aa;
1033print /a/p, s/b/c/p;
1034print /a/l, s/b/c/l;
1035print /a/u, s/b/c/u;
b9bc576f 1036{
a8095af7 1037 use feature 'unicode_strings';
09622ee2 1038 print /a/d, s/b/c/d;
b9bc576f
FC
1039}
1040{
0bb01b05
FC
1041 BEGIN { $^H{'reflags'} = '0';
1042 $^H{'reflags_charset'} = '2'; }
09622ee2 1043 print /a/d, s/b/c/d;
b9bc576f 1044}
dff5ffe4
FC
1045{
1046 no feature;
1047 use feature ':5.12';
1048 print /a/d, s/b/c/d;
1049}
b9bc576f 1050####
9f125c4a
FC
1051# [perl #119807] s//\(3)/ge should not warn when deparsed (\3 warns)
1052s/foo/\(3);/eg;
1053####
e7afc405
FC
1054# y///r
1055tr/a/b/r;
cb8157e3 1056####
cb8578ff 1057# [perl #90898]
f4002a4b 1058<a,>;
09dcfa7d
FC
1059####
1060# [perl #91008]
d401967c 1061# CONTEXT no warnings 'experimental::autoderef';
09dcfa7d
FC
1062each $@;
1063keys $~;
1064values $!;
5d8c42c2
FC
1065####
1066# readpipe with complex expression
1067readpipe $a + $b;
93bad3fd
NC
1068####
1069# aelemfast
1070$b::a[0] = 1;
1071####
1072# aelemfast for a lexical
1073my @a;
1074$a[0] = 1;
80e3f4ad
FC
1075####
1076# feature features without feature
0f539b13 1077# CONTEXT no warnings 'experimental::smartmatch';
80e3f4ad 1078CORE::state $x;
223b1722
FC
1079CORE::say $x;
1080CORE::given ($x) {
1081 CORE::when (3) {
1082 continue;
1083 }
1084 CORE::default {
1085 CORE::break;
1086 }
1087}
1088CORE::evalbytes '';
1089() = CORE::__SUB__;
838f2281 1090() = CORE::fc $x;
223b1722
FC
1091####
1092# feature features when feature has been disabled by use VERSION
0f539b13 1093# CONTEXT no warnings 'experimental::smartmatch';
223b1722
FC
1094use feature (sprintf(":%vd", $^V));
1095use 1;
1096CORE::state $x;
1097CORE::say $x;
1098CORE::given ($x) {
1099 CORE::when (3) {
1100 continue;
1101 }
1102 CORE::default {
1103 CORE::break;
1104 }
1105}
1106CORE::evalbytes '';
1107() = CORE::__SUB__;
1108>>>>
205fef88
NC
1109CORE::state $x;
1110CORE::say $x;
1111CORE::given ($x) {
1112 CORE::when (3) {
1113 continue;
1114 }
1115 CORE::default {
1116 CORE::break;
1117 }
1118}
1119CORE::evalbytes '';
1120() = CORE::__SUB__;
1121####
1122# (the above test with CONTEXT, and the output is equivalent but different)
0f539b13 1123# CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
205fef88
NC
1124# feature features when feature has been disabled by use VERSION
1125use feature (sprintf(":%vd", $^V));
1126use 1;
1127CORE::state $x;
1128CORE::say $x;
1129CORE::given ($x) {
1130 CORE::when (3) {
1131 continue;
1132 }
1133 CORE::default {
1134 CORE::break;
1135 }
1136}
1137CORE::evalbytes '';
1138() = CORE::__SUB__;
1139>>>>
0bb01b05
FC
1140no feature;
1141use feature ':default';
223b1722 1142CORE::state $x;
80e3f4ad
FC
1143CORE::say $x;
1144CORE::given ($x) {
1145 CORE::when (3) {
1146 continue;
1147 }
1148 CORE::default {
e36901c8 1149 CORE::break;
80e3f4ad
FC
1150 }
1151}
7d789282 1152CORE::evalbytes '';
84ed0108 1153() = CORE::__SUB__;
6ec73527 1154####
7741ceed
FC
1155# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1156# lexical subroutines and keywords of the same name
1157# CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental';
1158my sub default;
1159my sub else;
1160my sub elsif;
1161my sub for;
1162my sub foreach;
1163my sub given;
1164my sub if;
1165my sub m;
1166my sub no;
1167my sub package;
1168my sub q;
1169my sub qq;
1170my sub qr;
1171my sub qx;
1172my sub require;
1173my sub s;
1174my sub sub;
1175my sub tr;
1176my sub unless;
1177my sub until;
1178my sub use;
1179my sub when;
1180my sub while;
1181CORE::default { die; }
1182CORE::if ($1) { die; }
1183CORE::if ($1) { die; }
1184CORE::elsif ($1) { die; }
1185CORE::else { die; }
1186CORE::for (die; $1; die) { die; }
1187CORE::foreach $_ (1 .. 10) { die; }
1188die CORE::foreach (1);
1189CORE::given ($1) { die; }
1190CORE::m[/];
1191CORE::m?/?;
1192CORE::package foo;
1193CORE::no strict;
1194() = (CORE::q['], CORE::qq["$_], CORE::qr//, CORE::qx[`]);
1195CORE::require 1;
1196CORE::s///;
1197() = CORE::sub { die; } ;
1198CORE::tr///;
1199CORE::unless ($1) { die; }
1200CORE::until ($1) { die; }
1201die CORE::until $1;
1202CORE::use strict;
1203CORE::when ($1 ~~ $2) { die; }
1204CORE::while ($1) { die; }
1205die CORE::while $1;
1206####
0bb01b05
FC
1207# Feature hints
1208use feature 'current_sub', 'evalbytes';
1209print;
1210use 1;
1211print;
1212use 5.014;
1213print;
1214no feature 'unicode_strings';
1215print;
1216>>>>
a8095af7 1217use feature 'current_sub', 'evalbytes';
0bb01b05
FC
1218print $_;
1219no feature;
1220use feature ':default';
1221print $_;
1222no feature;
1223use feature ':5.12';
1224print $_;
a8095af7 1225no feature 'unicode_strings';
0bb01b05
FC
1226print $_;
1227####
6ec73527
FC
1228# $#- $#+ $#{%} etc.
1229my @x;
5b6da579 1230@x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
6ec73527
FC
1231@x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
1232@x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
1233@x = ($#{;}, $#{:});
61154ac0 1234####
ff683671
NC
1235# ${#} interpolated
1236# It's a known TODO that warnings are deparsed as bits, not textually.
1237no warnings;
61154ac0 1238() = "${#}a";
958ed56b 1239####
337d7381
FC
1240# [perl #86060] $( $| $) in regexps need braces
1241/${(}/;
1242/${|}/;
1243/${)}/;
1244/${(}${|}${)}/;
1245####
958ed56b
FC
1246# ()[...]
1247my(@a) = ()[()];
521795fe
FC
1248####
1249# sort(foo(bar))
1250# sort(foo(bar)) is interpreted as sort &foo(bar)
1251# sort foo(bar) is interpreted as sort foo bar
1252# parentheses are not optional in this case
1253print sort(foo('bar'));
1254>>>>
1255print sort(foo('bar'));
24fcb59f
FC
1256####
1257# substr assignment
1258substr(my $a, 0, 0) = (foo(), bar());
1259$a++;
04be0204 1260####
d1718a7c
FC
1261# This following line works around an unfixed bug that we are not trying to
1262# test for here:
1263# CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
04be0204
FC
1264# hint hash
1265BEGIN { $^H{'foo'} = undef; }
1266{
1267 BEGIN { $^H{'bar'} = undef; }
1268 {
1269 BEGIN { $^H{'baz'} = undef; }
1270 {
1271 print $_;
1272 }
1273 print $_;
1274 }
1275 print $_;
1276}
035146a3
FC
1277BEGIN { $^H{q[']} = '('; }
1278print $_;
c306e834 1279####
d1718a7c
FC
1280# This following line works around an unfixed bug that we are not trying to
1281# test for here:
1282# CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
c306e834
FC
1283# hint hash changes that serialise the same way with sort %hh
1284BEGIN { $^H{'a'} = 'b'; }
1285{
1286 BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
1287 print $_;
1288}
1289print $_;
94bb57f9
FC
1290####
1291# [perl #47361] do({}) and do +{} (variants of do-file)
1292do({});
1293do +{};
8b46c09b
FC
1294sub foo::do {}
1295package foo;
1296CORE::do({});
1297CORE::do +{};
94bb57f9
FC
1298>>>>
1299do({});
1300do({});
8b46c09b
FC
1301package foo;
1302CORE::do({});
1303CORE::do({});
9c56d9ea
FC
1304####
1305# [perl #77096] functions that do not follow the llafr
1306() = (return 1) + time;
1307() = (return ($1 + $2) * $3) + time;
1308() = (return ($a xor $b)) + time;
1309() = (do 'file') + time;
1310() = (do ($1 + $2) * $3) + time;
1311() = (do ($1 xor $2)) + time;
41df74e3
FC
1312() = (goto 1) + 3;
1313() = (require 'foo') + 3;
1314() = (require foo) + 3;
266da325 1315() = (CORE::dump 1) + 3;
41df74e3
FC
1316() = (last 1) + 3;
1317() = (next 1) + 3;
1318() = (redo 1) + 3;
5830412d
FC
1319() = (-R $_) + 3;
1320() = (-W $_) + 3;
1321() = (-X $_) + 3;
1322() = (-r $_) + 3;
1323() = (-w $_) + 3;
1324() = (-x $_) + 3;
2462c3cc 1325####
1cabb3b3
FC
1326# [perl #97476] not() *does* follow the llafr
1327$_ = ($a xor not +($1 || 2) ** 2);
1328####
4d8ac5c7
FC
1329# Precedence conundrums with argument-less function calls
1330() = (eof) + 1;
1331() = (return) + 1;
1332() = (return, 1);
7bc8c979
FC
1333() = warn;
1334() = warn() + 1;
4d8ac5c7
FC
1335() = setpgrp() + 1;
1336####
1eb0b7be
FC
1337# loopexes have assignment prec
1338() = (CORE::dump a) | 'b';
1339() = (goto a) | 'b';
1340() = (last a) | 'b';
1341() = (next a) | 'b';
1342() = (redo a) | 'b';
1343####
2462c3cc
FC
1344# [perl #63558] open local(*FH)
1345open local *FH;
564cd6cb 1346pipe local *FH, local *FH;
843b15cc 1347####
b89b7257
FC
1348# [perl #91416] open "string"
1349open 'open';
1350open '####';
1351open '^A';
1352open "\ca";
1353>>>>
1354open *open;
1355open '####';
1356open '^A';
1357open *^A;
1358####
be6cf5cf
FC
1359# "string"->[] ->{}
1360no strict 'vars';
1361() = 'open'->[0]; #aelemfast
1362() = '####'->[0];
1363() = '^A'->[0];
1364() = "\ca"->[0];
b861b87f 1365() = 'a::]b'->[0];
10e8e32b
FC
1366() = 'open'->[$_]; #aelem
1367() = '####'->[$_];
1368() = '^A'->[$_];
1369() = "\ca"->[$_];
b861b87f 1370() = 'a::]b'->[$_];
10e8e32b
FC
1371() = 'open'->{0}; #helem
1372() = '####'->{0};
1373() = '^A'->{0};
1374() = "\ca"->{0};
b861b87f 1375() = 'a::]b'->{0};
be6cf5cf 1376>>>>
415d4c68 1377no strict 'vars';
be6cf5cf
FC
1378() = $open[0];
1379() = '####'->[0];
1380() = '^A'->[0];
1381() = $^A[0];
b861b87f 1382() = 'a::]b'->[0];
10e8e32b
FC
1383() = $open[$_];
1384() = '####'->[$_];
1385() = '^A'->[$_];
1386() = $^A[$_];
b861b87f 1387() = 'a::]b'->[$_];
10e8e32b
FC
1388() = $open{'0'};
1389() = '####'->{'0'};
1390() = '^A'->{'0'};
1391() = $^A{'0'};
b861b87f 1392() = 'a::]b'->{'0'};
be6cf5cf 1393####
843b15cc
FC
1394# [perl #74740] -(f()) vs -f()
1395$_ = -(f());
c75b4828
FC
1396####
1397# require <binop>
1398require 'a' . $1;
afb60448
HY
1399####
1400#[perl #30504] foreach-my postfix/prefix difference
1401$_ = 'foo' foreach my ($foo1, $bar1, $baz1);
1402foreach (my ($foo2, $bar2, $baz2)) { $_ = 'foo' }
1403foreach my $i (my ($foo3, $bar3, $baz3)) { $i = 'foo' }
1404>>>>
1405$_ = 'foo' foreach (my($foo1, $bar1, $baz1));
1406foreach $_ (my($foo2, $bar2, $baz2)) {
1407 $_ = 'foo';
1408}
1409foreach my $i (my($foo3, $bar3, $baz3)) {
1410 $i = 'foo';
1411}
1412####
1413#[perl #108224] foreach with continue block
1414foreach (1 .. 3) { print } continue { print "\n" }
1415foreach (1 .. 3) { } continue { }
1416foreach my $i (1 .. 3) { print $i } continue { print "\n" }
1417foreach my $i (1 .. 3) { } continue { }
1418>>>>
1419foreach $_ (1 .. 3) {
1420 print $_;
1421}
1422continue {
1423 print "\n";
1424}
1425foreach $_ (1 .. 3) {
1426 ();
1427}
1428continue {
1429 ();
1430}
1431foreach my $i (1 .. 3) {
1432 print $i;
1433}
1434continue {
1435 print "\n";
1436}
1437foreach my $i (1 .. 3) {
1438 ();
1439}
1440continue {
1441 ();
1442}
bc1cc2c3
DM
1443####
1444# file handles
1445no strict;
1446my $mfh;
1447open F;
1448open *F;
1449open $fh;
1450open $mfh;
1451open 'a+b';
1452select *F;
1453select F;
1454select $f;
1455select $mfh;
1456select 'a+b';
a7fd8ef6
DM
1457####
1458# 'my' works with padrange op
1459my($z, @z);
1460my $m1;
1461$m1 = 1;
1462$z = $m1;
1463my $m2 = 2;
1464my($m3, $m4);
1465($m3, $m4) = (1, 2);
1466@z = ($m3, $m4);
1467my($m5, $m6) = (1, 2);
1468my($m7, undef, $m8) = (1, 2, 3);
1469@z = ($m7, undef, $m8);
1470($m7, undef, $m8) = (1, 2, 3);
1471####
1472# 'our/local' works with padrange op
1473no strict;
1474our($z, @z);
1475our $o1;
1476local $o11;
1477$o1 = 1;
1478local $o1 = 1;
1479$z = $o1;
1480$z = local $o1;
1481our $o2 = 2;
1482our($o3, $o4);
1483($o3, $o4) = (1, 2);
1484local($o3, $o4) = (1, 2);
1485@z = ($o3, $o4);
1486@z = local($o3, $o4);
1487our($o5, $o6) = (1, 2);
1488our($o7, undef, $o8) = (1, 2, 3);
1489@z = ($o7, undef, $o8);
1490@z = local($o7, undef, $o8);
1491($o7, undef, $o8) = (1, 2, 3);
1492local($o7, undef, $o8) = (1, 2, 3);
1493####
1494# 'state' works with padrange op
1495no strict;
1496use feature 'state';
1497state($z, @z);
1498state $s1;
1499$s1 = 1;
1500$z = $s1;
1501state $s2 = 2;
1502state($s3, $s4);
1503($s3, $s4) = (1, 2);
1504@z = ($s3, $s4);
1505# assignment of state lists isn't implemented yet
1506#state($s5, $s6) = (1, 2);
1507#state($s7, undef, $s8) = (1, 2, 3);
1508#@z = ($s7, undef, $s8);
1509($s7, undef, $s8) = (1, 2, 3);
1510####
1511# anon lists with padrange
1512my($a, $b);
1513my $c = [$a, $b];
1514my $d = {$a, $b};
1515####
1516# slices with padrange
1517my($a, $b);
1518my(@x, %y);
1519@x = @x[$a, $b];
1520@x = @y{$a, $b};
1521####
1522# binops with padrange
1523my($a, $b, $c);
1524$c = $a cmp $b;
1525$c = $a + $b;
1526$a += $b;
1527$c = $a - $b;
1528$a -= $b;
1529$c = my $a1 cmp $b;
1530$c = my $a2 + $b;
1531$a += my $b1;
1532$c = my $a3 - $b;
1533$a -= my $b2;
1534####
1535# 'x' with padrange
1536my($a, $b, $c, $d, @e);
1537$c = $a x $b;
1538$a x= $b;
1539@e = ($a) x $d;
1540@e = ($a, $b) x $d;
1541@e = ($a, $b, $c) x $d;
1542@e = ($a, 1) x $d;
d5524600
DM
1543####
1544# @_ with padrange
1545my($a, $b, $c) = @_;
ce4062e7
AC
1546####
1547# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1548# TODO unimplemented in B::Deparse; RT #116553
1549# lexical subroutine
1550use feature 'lexical_subs';
601448c3 1551no warnings "experimental::lexical_subs";
ce4062e7
AC
1552my sub f {}
1553print f();
f0cf3754
AC
1554####
1555# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1556# TODO unimplemented in B::Deparse; RT #116553
1557# lexical "state" subroutine
1558use feature 'state', 'lexical_subs';
1559no warnings 'experimental::lexical_subs';
1560state sub f {}
1561print f();
bcbe2b27 1562####
8443930e
FC
1563# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1564# TODO unimplemented in B::Deparse; RT #116553
1565# lexical subroutine scoping
1566# CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
1567{
1568 {
1569 my sub a { die; }
1570 {
1571 foo();
1572 my sub b;
1573 b();
1574 main::b();
1575 my $b;
1576 sub b { $b }
1577 }
1578 }
1579 b();
1580}
1581####
bcbe2b27
FC
1582# Elements of %# should not be confused with $#{ array }
1583() = ${#}{'foo'};
c4cf781e
FC
1584####
1585# [perl #121050] Prototypes with whitespace
1586sub _121050(\$ \$) { }
1587_121050($a,$b);
1588sub _121050empty( ) {}
1589() = _121050empty() + 1;
1590>>>>
1591_121050 $a, $b;
1592() = _121050empty + 1;
b024352e
DM
1593####
1594# ensure aelemfast works in the range -128..127 and that there's no
1595# funky edge cases
1596my $x;
1597no strict 'vars';
1598$x = $a[-256] + $a[-255] + $a[-129] + $a[-128] + $a[-127] + $a[-1] + $a[0];
1599$x = $a[1] + $a[126] + $a[127] + $a[128] + $a[255] + $a[256];
1600my @b;
1601$x = $b[-256] + $b[-255] + $b[-129] + $b[-128] + $b[-127] + $b[-1] + $b[0];
1602$x = $b[1] + $b[126] + $b[127] + $b[128] + $b[255] + $b[256];
e09d73a6
DIM
1603####
1604# 'm' must be preserved in m??
1605m??;
c8ec376c
FC
1606####
1607# \(@array) and \(..., (@array), ...)
1608my(@array, %hash, @a, @b, %c, %d);
1609() = \(@array);
1610() = \(%hash);
1611() = \(@a, (@b), (%c), %d);
1612() = \(@Foo::array);
1613() = \(%Foo::hash);
1614() = \(@Foo::a, (@Foo::b), (%Foo::c), %Foo::d);
a958cfbb
FC
1615####
1616# subs synonymous with keywords
1617main::our();
1618main::pop();
1619state();
1620use feature 'state';
1621main::state();
9187b6e4
FC
1622####
1623# lvalue references
1624# CONTEXT use feature "state", 'lvalue_refs', 'lexical_subs'; no warnings 'experimental';
1625our $x;
1626\$x = \$x;
1627my $m;
1628\$m = \$x;
1629\my $n = \$x;
1630(\$x) = @_;
1631\($x) = @_;
1632\($m) = @_;
1633(\$m) = @_;
1634\my($p) = @_;
1635(\my $r) = @_;
1636\($x, my $a) = @{[\$x, \$x]};
1637(\$x, \my $b) = @{[\$x, \$x]};
1638\local $x = \3;
1639\local($x) = \3;
1640\state $c = \3;
1641\state($d) = \3;
1642\our $e = \3;
1643\our($f) = \3;
1644\$_[0] = foo();
1645\($_[1]) = foo();
1646my @a;
1647\$a[0] = foo();
1648\($a[1]) = foo();
1649\local($a[1]) = foo();
1650\@a[0,1] = foo();
1651\(@a[2,3]) = foo();
1652\local @a[0,1] = (\$a)x2;
1653\$_{a} = foo();
1654\($_{b}) = foo();
1655my %h;
1656\$h{a} = foo();
1657\($h{b}) = foo();
1658\local $h{a} = \$x;
1659\local($h{b}) = \$x;
1660\@h{'a','b'} = foo();
1661\(@h{2,3}) = foo();
1662\local @h{'a','b'} = (\$x)x2;
1663\@_ = foo();
1664\@a = foo();
1665(\@_) = foo();
1666(\@a) = foo();
1667\my @c = foo();
1668(\my @d) = foo();
1669\(@_) = foo();
1670\(@a) = foo();
1671\my(@g) = foo();
1672\local @_ = \@_;
1673(\local @_) = \@_;
1674\state @e = [1..3];
1675\state(@f) = \3;
1676\our @i = [1..3];
1677\our(@h) = \3;
1678\%_ = foo();
1679\%h = foo();
1680(\%_) = foo();
1681(\%h) = foo();
1682\my %c = foo();
1683(\my %d) = foo();
1684\local %_ = \%h;
1685(\local %_) = \%h;
1686\state %y = {1,2};
1687\our %z = {1,2};
1688(\our %zz) = {1,2};
1689\&a = foo();
1690(\&a) = foo();
1691\(&a) = foo();
1692{
1693 my sub a;
1694 \&a = foo();
1695 (\&a) = foo();
1696 \(&a) = foo();
1697}
1698(\$_, $_) = \(1, 2);
1699$_ == 3 ? \$_ : $_ = \3;
1700$_ == 3 ? \$_ : \$x = \3;
1701\($_ == 3 ? $_ : $x) = \3;
1702for \my $topic (\$1, \$2) {
1703 die;
1704}
1705for \state $topic (\$1, \$2) {
1706 die;
1707}
1708for \our $topic (\$1, \$2) {
1709 die;
1710}
1711for \$_ (\$1, \$2) {
1712 die;
1713}
1714for \my @a ([1,2], [3,4]) {
1715 die;
1716}
1717for \state @a ([1,2], [3,4]) {
1718 die;
1719}
1720for \our @a ([1,2], [3,4]) {
1721 die;
1722}
1723for \@_ ([1,2], [3,4]) {
1724 die;
1725}
1726for \my %a ({5,6}, {7,8}) {
1727 die;
1728}
1729for \our %a ({5,6}, {7,8}) {
1730 die;
1731}
1732for \state %a ({5,6}, {7,8}) {
1733 die;
1734}
1735for \%_ ({5,6}, {7,8}) {
1736 die;
1737}
1738{
1739 my sub a;
1740 for \&a (sub { 9; }, sub { 10; }) {
1741 die;
1742 }
1743}
1744for \&a (sub { 9; }, sub { 10; }) {
1745 die;
1746}
1747>>>>
1748our $x;
1749\$x = \$x;
1750my $m;
1751\$m = \$x;
1752\my $n = \$x;
1753(\$x) = @_;
1754(\$x) = @_;
1755(\$m) = @_;
1756(\$m) = @_;
1757(\my $p) = @_;
1758(\my $r) = @_;
1759(\$x, \my $a) = @{[\$x, \$x];};
1760(\$x, \my $b) = @{[\$x, \$x];};
1761\local $x = \3;
1762(\local $x) = \3;
1763\state $c = \3;
1764(\state $d) = \3;
1765\our $e = \3;
1766(\our $f) = \3;
1767\$_[0] = foo();
1768(\$_[1]) = foo();
1769my @a;
1770\$a[0] = foo();
1771(\$a[1]) = foo();
1772(\local $a[1]) = foo();
1773(\@a[0, 1]) = foo();
1774(\@a[2, 3]) = foo();
1775(\local @a[0, 1]) = (\$a) x 2;
1776\$_{'a'} = foo();
1777(\$_{'b'}) = foo();
1778my %h;
1779\$h{'a'} = foo();
1780(\$h{'b'}) = foo();
1781\local $h{'a'} = \$x;
1782(\local $h{'b'}) = \$x;
1783(\@h{'a', 'b'}) = foo();
1784(\@h{2, 3}) = foo();
1785(\local @h{'a', 'b'}) = (\$x) x 2;
1786\@_ = foo();
1787\@a = foo();
1788(\@_) = foo();
1789(\@a) = foo();
1790\my @c = foo();
1791(\my @d) = foo();
1792(\(@_)) = foo();
1793(\(@a)) = foo();
1794(\(my @g)) = foo();
1795\local @_ = \@_;
1796(\local @_) = \@_;
1797\state @e = [1..3];
1798(\(state @f)) = \3;
1799\our @i = [1..3];
1800(\(our @h)) = \3;
1801\%_ = foo();
1802\%h = foo();
1803(\%_) = foo();
1804(\%h) = foo();
1805\my %c = foo();
1806(\my %d) = foo();
1807\local %_ = \%h;
1808(\local %_) = \%h;
1809\state %y = {1, 2};
1810\our %z = {1, 2};
1811(\our %zz) = {1, 2};
1812\&a = foo();
1813(\&a) = foo();
1814(\&a) = foo();
1815{
1816 my sub a;
1817 \&a = foo();
1818 (\&a) = foo();
1819 (\&a) = foo();
1820}
1821(\$_, $_) = \(1, 2);
1822$_ == 3 ? \$_ : $_ = \3;
1823$_ == 3 ? \$_ : \$x = \3;
1824($_ == 3 ? \$_ : \$x) = \3;
1825foreach \my $topic (\$1, \$2) {
1826 die;
1827}
1828foreach \state $topic (\$1, \$2) {
1829 die;
1830}
1831foreach \our $topic (\$1, \$2) {
1832 die;
1833}
1834foreach \$_ (\$1, \$2) {
1835 die;
1836}
1837foreach \my @a ([1, 2], [3, 4]) {
1838 die;
1839}
1840foreach \state @a ([1, 2], [3, 4]) {
1841 die;
1842}
1843foreach \our @a ([1, 2], [3, 4]) {
1844 die;
1845}
1846foreach \@_ ([1, 2], [3, 4]) {
1847 die;
1848}
1849foreach \my %a ({5, 6}, {7, 8}) {
1850 die;
1851}
1852foreach \our %a ({5, 6}, {7, 8}) {
1853 die;
1854}
1855foreach \state %a ({5, 6}, {7, 8}) {
1856 die;
1857}
1858foreach \%_ ({5, 6}, {7, 8}) {
1859 die;
1860}
1861{
1862 my sub a;
1863 foreach \&a (sub { 9; } , sub { 10; } ) {
1864 die;
1865 }
1866}
1867foreach \&a (sub { 9; } , sub { 10; } ) {
1868 die;
1869}