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