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