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