This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #81424] Make Deparse handle /aelemfast_lex/
[perl5.git] / dist / B-Deparse / t / 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;
e9c69003 14BEGIN {
c4a6f826 15 # BEGIN block is actually a subroutine :-)
e9c69003
NC
16 return unless $] > 5.009;
17 require feature;
18 feature->import(':5.10');
19}
507a68aa 20use Test::More;
1bb3cfc5 21use Config ();
87a42246
MS
22
23use B::Deparse;
09d856fb 24my $deparse = B::Deparse->new();
507a68aa 25isa_ok($deparse, 'B::Deparse', 'instantiate a B::Deparse object');
87a42246
MS
26
27# Tell B::Deparse about our ambient pragmas
0ced6c29
RGS
28{ my ($hint_bits, $warning_bits, $hinthash);
29 BEGIN { ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H); }
87a42246
MS
30 $deparse->ambient_pragmas (
31 hint_bits => $hint_bits,
32 warning_bits => $warning_bits,
0ced6c29 33 '%^H' => $hinthash,
87a42246
MS
34 );
35}
36
ad46c0be
RH
37$/ = "\n####\n";
38while (<DATA>) {
39 chomp;
e9c69003
NC
40 # This code is pinched from the t/lib/common.pl for TODO.
41 # It's not clear how to avoid duplication
b871937f
NC
42 # Now tweaked a bit to do skip or todo
43 my %reason;
44 foreach my $what (qw(skip todo)) {
45 s/^#\s*\U$what\E\s*(.*)\n//m and $reason{$what} = $1;
46 # If the SKIP reason starts ? then it's taken as a code snippet to
47 # evaluate. This provides the flexibility to have conditional SKIPs
48 if ($reason{$what} && $reason{$what} =~ s/^\?//) {
49 my $temp = eval $reason{$what};
50 if ($@) {
51 die "# In \U$what\E code reason:\n# $reason{$what}\n$@";
52 }
53 $reason{$what} = $temp;
e9c69003 54 }
e9c69003
NC
55 }
56
4a4b8592 57 s/^\s*#\s*(.*)$//mg;
507a68aa
NC
58 my $desc = $1;
59 die "Missing name in test $_" unless defined $desc;
e9c69003 60
b871937f 61 if ($reason{skip}) {
e9c69003 62 # Like this to avoid needing a label SKIP:
b871937f 63 Test::More->builder->skip($reason{skip});
e9c69003
NC
64 next;
65 }
66
ad46c0be
RH
67 my ($input, $expected);
68 if (/(.*)\n>>>>\n(.*)/s) {
69 ($input, $expected) = ($1, $2);
70 }
71 else {
72 ($input, $expected) = ($_, $_);
73 }
87a42246 74
ad46c0be 75 my $coderef = eval "sub {$input}";
87a42246 76
ad46c0be 77 if ($@) {
507a68aa 78 is($@, "", "compilation of $desc");
ad46c0be
RH
79 }
80 else {
81 my $deparsed = $deparse->coderef2text( $coderef );
31c6271a
RD
82 my $regex = $expected;
83 $regex =~ s/(\S+)/\Q$1/g;
84 $regex =~ s/\s+/\\s+/g;
85 $regex = '^\{\s*' . $regex . '\s*\}$';
b871937f 86
4a4b8592 87 local $::TODO = $reason{todo};
507a68aa 88 like($deparsed, qr/$regex/, $desc);
87a42246 89 }
87a42246
MS
90}
91
87a42246 92use constant 'c', 'stuff';
507a68aa
NC
93is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
94 'the subroutine generated by use constant deparses');
87a42246 95
09d856fb 96my $a = 0;
507a68aa
NC
97is($deparse->coderef2text(sub{(-1) ** $a }), "{\n (-1) ** \$a;\n}",
98 'anon sub capturing an external lexical');
87a42246 99
d989cdac
SM
100use constant cr => ['hello'];
101my $string = "sub " . $deparse->coderef2text(\&cr);
0707d6cc 102my $val = (eval $string)->() or diag $string;
507a68aa
NC
103is(ref($val), 'ARRAY', 'constant array references deparse');
104is($val->[0], 'hello', 'and return the correct value');
87a42246 105
87a42246 106my $path = join " ", map { qq["-I$_"] } @INC;
87a42246 107
7cde0a5f 108$a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
e69a2255 109$a =~ s/-e syntax OK\n//g;
d2bc402e 110$a =~ s/.*possible typo.*\n//; # Remove warning line
87a42246
MS
111$a =~ s{\\340\\242}{\\s} if (ord("\\") == 224); # EBCDIC, cp 1047 or 037
112$a =~ s{\\274\\242}{\\s} if (ord("\\") == 188); # $^O eq 'posix-bc'
113$b = <<'EOF';
d2bc402e
RGS
114BEGIN { $^I = ".bak"; }
115BEGIN { $^W = 1; }
116BEGIN { $/ = "\n"; $\ = "\n"; }
87a42246
MS
117LINE: while (defined($_ = <ARGV>)) {
118 chomp $_;
f86ea535 119 our(@F) = split(' ', $_, 0);
87a42246
MS
120 '???';
121}
87a42246 122EOF
507a68aa
NC
123is($a, $b,
124 'command line flags deparse as BEGIN blocks setting control variables');
87a42246 125
5b4ee549
NC
126$a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`;
127$a =~ s/-e syntax OK\n//g;
128is($a, "use constant ('PI', 4);\n",
129 "Proxy Constant Subroutines must not show up as (incorrect) prototypes");
130
579a54dc 131#Re: perlbug #35857, patch #24505
b3980c39
YO
132#handle warnings::register-ed packages properly.
133package B::Deparse::Wrapper;
134use strict;
135use warnings;
136use warnings::register;
137sub getcode {
579a54dc 138 my $deparser = B::Deparse->new();
b3980c39
YO
139 return $deparser->coderef2text(shift);
140}
141
2990415a
FR
142package Moo;
143use overload '0+' => sub { 42 };
144
b3980c39
YO
145package main;
146use strict;
147use warnings;
71c4dbc3 148use constant GLIPP => 'glipp';
2990415a
FR
149use constant PI => 4;
150use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
3779476a 151use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
aaf9c2b2 152BEGIN { delete $::Fcntl::{O_APPEND}; }
2990415a 153use POSIX qw/O_CREAT/;
b3980c39 154sub test {
579a54dc
RGS
155 my $val = shift;
156 my $res = B::Deparse::Wrapper::getcode($val);
507a68aa
NC
157 like($res, qr/use warnings/,
158 '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
b3980c39
YO
159}
160my ($q,$p);
161my $x=sub { ++$q,++$p };
162test($x);
163eval <<EOFCODE and test($x);
164 package bar;
165 use strict;
166 use warnings;
167 use warnings::register;
168 package main;
169 1
170EOFCODE
171
d1dc589d
FC
172# Exotic sub declarations
173$a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
174$a =~ s/-e syntax OK\n//g;
175is($a, <<'EOCODG', "sub :::: and sub ::::::");
176sub :::: {
177
178}
179sub :::::: {
180
181}
182EOCODG
183
640d5d41
FC
184# [perl #33752]
185{
186 my $code = <<"EOCODE";
187{
188 our \$\x{1e1f}\x{14d}\x{14d};
189}
190EOCODE
191 my $deparsed
192 = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
193 s/$ \n//x for $deparsed, $code;
194 is $deparsed, $code, 'our $funny_Unicode_chars';
195}
196
bdabb2d5
FC
197# [perl #62500]
198$a =
199 `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
200$a =~ s/-e syntax OK\n//g;
201is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
202sub BEGIN {
203 *CORE::GLOBAL::require = sub {
204 1;
205 }
206 ;
207}
208EOCODF
209
894e98ac
FC
210# [perl #91384]
211$a =
212 `$^X $path "-MO=Deparse" -e "BEGIN{*Acme::Acme:: = *Acme::}" 2>&1`;
213like($a, qr/-e syntax OK/,
214 "Deparse does not hang when traversing stash circularities");
215
bb8996b8 216# [perl #93990]
5c19ffe6 217@* = ();
bb8996b8
HY
218is($deparse->coderef2text(sub{ print "@{*}" }),
219q<{
220 print "@{*}";
221}>, 'curly around to interpolate "@{*}"');
222is($deparse->coderef2text(sub{ print "@{-}" }),
223q<{
224 print "@-";
225}>, 'no need to curly around to interpolate "@-"');
226
507a68aa
NC
227done_testing();
228
ad46c0be 229__DATA__
507a68aa 230# A constant
ad46c0be
RH
2311;
232####
507a68aa 233# Constants in a block
ad46c0be
RH
234{
235 no warnings;
236 '???';
237 2;
238}
239####
507a68aa 240# Lexical and simple arithmetic
ad46c0be
RH
241my $test;
242++$test and $test /= 2;
243>>>>
244my $test;
245$test /= 2 if ++$test;
246####
507a68aa 247# list x
ad46c0be
RH
248-((1, 2) x 2);
249####
507a68aa 250# lvalue sub
ad46c0be
RH
251{
252 my $test = sub : lvalue {
253 my $x;
254 }
255 ;
256}
257####
507a68aa 258# method
ad46c0be
RH
259{
260 my $test = sub : method {
261 my $x;
262 }
263 ;
264}
265####
507a68aa 266# block with continue
87a42246 267{
ad46c0be 268 234;
f99a63a2 269}
ad46c0be
RH
270continue {
271 123;
87a42246 272}
ce4e655d 273####
507a68aa 274# lexical and package scalars
ce4e655d
RH
275my $x;
276print $main::x;
277####
507a68aa 278# lexical and package arrays
ce4e655d
RH
279my @x;
280print $main::x[1];
14a55f98 281####
507a68aa 282# lexical and package hashes
14a55f98
RH
283my %x;
284$x{warn()};
ad8caead 285####
507a68aa 286# <>
ad8caead
RGS
287my $foo;
288$_ .= <ARGV> . <$foo>;
cef22867 289####
507a68aa 290# \x{}
11454c59 291my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
4ae52e81 292####
507a68aa 293# s///e
4ae52e81 294s/x/'y';/e;
241416b8 295####
507a68aa 296# block
241416b8
DM
297{ my $x; }
298####
507a68aa 299# while 1
241416b8
DM
300while (1) { my $k; }
301####
507a68aa 302# trailing for
241416b8
DM
303my ($x,@a);
304$x=1 for @a;
305>>>>
306my($x, @a);
0bb5f065 307$x = 1 foreach (@a);
241416b8 308####
507a68aa 309# 2 arguments in a 3 argument for
241416b8
DM
310for (my $i = 0; $i < 2;) {
311 my $z = 1;
312}
313####
507a68aa 314# 3 argument for
241416b8
DM
315for (my $i = 0; $i < 2; ++$i) {
316 my $z = 1;
317}
318####
507a68aa 319# 3 argument for again
241416b8
DM
320for (my $i = 0; $i < 2; ++$i) {
321 my $z = 1;
322}
323####
507a68aa 324# while/continue
241416b8
DM
325my $i;
326while ($i) { my $z = 1; } continue { $i = 99; }
327####
507a68aa 328# foreach with my
09d856fb 329foreach my $i (1, 2) {
241416b8
DM
330 my $z = 1;
331}
332####
507a68aa 333# foreach
241416b8
DM
334my $i;
335foreach $i (1, 2) {
336 my $z = 1;
337}
338####
507a68aa 339# foreach, 2 mys
241416b8
DM
340my $i;
341foreach my $i (1, 2) {
342 my $z = 1;
343}
344####
507a68aa 345# foreach
241416b8
DM
346foreach my $i (1, 2) {
347 my $z = 1;
348}
349####
507a68aa 350# foreach with our
241416b8
DM
351foreach our $i (1, 2) {
352 my $z = 1;
353}
354####
507a68aa 355# foreach with my and our
241416b8
DM
356my $i;
357foreach our $i (1, 2) {
358 my $z = 1;
359}
3ac6e0f9 360####
507a68aa 361# reverse sort
3ac6e0f9
RGS
362my @x;
363print reverse sort(@x);
364####
507a68aa 365# sort with cmp
3ac6e0f9
RGS
366my @x;
367print((sort {$b cmp $a} @x));
368####
507a68aa 369# reverse sort with block
3ac6e0f9
RGS
370my @x;
371print((reverse sort {$b <=> $a} @x));
36d57d93 372####
507a68aa 373# foreach reverse
36d57d93
RGS
374our @a;
375print $_ foreach (reverse @a);
aae53c41 376####
507a68aa 377# foreach reverse (not inplace)
aae53c41
RGS
378our @a;
379print $_ foreach (reverse 1, 2..5);
f86ea535 380####
507a68aa 381# bug #38684
f86ea535
SM
382our @ary;
383@ary = split(' ', 'foo', 0);
31c6271a 384####
507a68aa 385# bug #40055
31c6271a
RD
386do { () };
387####
507a68aa 388# bug #40055
31c6271a 389do { my $x = 1; $x };
d9002312 390####
507a68aa 391# <20061012113037.GJ25805@c4.convolution.nl>
d9002312
SM
392my $f = sub {
393 +{[]};
394} ;
8b2d6640 395####
507a68aa 396# bug #43010
8b2d6640
FC
397'!@$%'->();
398####
507a68aa 399# bug #43010
8b2d6640
FC
400::();
401####
507a68aa 402# bug #43010
8b2d6640
FC
403'::::'->();
404####
507a68aa 405# bug #43010
8b2d6640 406&::::;
09d856fb 407####
1b38d782
FC
408# [perl #77172]
409package rt77172;
410sub foo {} foo & & & foo;
411>>>>
412package rt77172;
413foo(&{&} & foo());
414####
507a68aa 415# variables as method names
09d856fb
CK
416my $bar;
417'Foo'->$bar('orz');
35a99a08 418'Foo'->$bar('orz') = 'a stranger stranger than before';
09d856fb 419####
507a68aa 420# constants as method names
09d856fb
CK
421'Foo'->bar('orz');
422####
507a68aa 423# constants as method names without ()
09d856fb 424'Foo'->bar;
0ced6c29 425####
28bfcb02 426# [perl #47359] "indirect" method call notation
1bf8bbb0
FC
427our @bar;
428foo{@bar}+1,->foo;
429(foo{@bar}+1),foo();
430foo{@bar}1 xor foo();
431>>>>
432our @bar;
433(foo { @bar } 1)->foo;
434(foo { @bar } 1), foo();
435foo { @bar } 1 xor foo();
436####
e9c69003 437# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
507a68aa 438# say
7ddd1a01
NC
439say 'foo';
440####
e9c69003 441# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
507a68aa 442# state vars
0ced6c29
RGS
443state $x = 42;
444####
e9c69003 445# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
507a68aa 446# state var assignment
7ddd1a01
NC
447{
448 my $y = (state $x = 42);
449}
450####
e9c69003 451# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
c4a6f826 452# state vars in anonymous subroutines
7ddd1a01
NC
453$a = sub {
454 state $x;
455 return $x++;
456}
457;
644741fd
NC
458####
459# SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
507a68aa 460# each @array;
644741fd
NC
461each @ARGV;
462each @$a;
463####
464# SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
507a68aa 465# keys @array; values @array
644741fd
NC
466keys @$a if keys @ARGV;
467values @ARGV if values @$a;
35925e80 468####
507a68aa 469# Anonymous arrays and hashes, and references to them
35925e80
RGS
470my $a = {};
471my $b = \{};
472my $c = [];
473my $d = \[];
9210de83
FR
474####
475# SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
507a68aa 476# implicit smartmatch in given/when
9210de83
FR
477given ('foo') {
478 when ('bar') { continue; }
479 when ($_ ~~ 'quux') { continue; }
480 default { 0; }
481}
7ecdd211 482####
507a68aa 483# conditions in elsifs (regression in change #33710 which fixed bug #37302)
7ecdd211
PJ
484if ($a) { x(); }
485elsif ($b) { x(); }
486elsif ($a and $b) { x(); }
487elsif ($a or $b) { x(); }
488else { x(); }
03b22f1b 489####
507a68aa 490# interpolation in regexps
03b22f1b
RGS
491my($y, $t);
492/x${y}z$t/;
227375e1 493####
4a4b8592 494# TODO new undocumented cpan-bug #33708
507a68aa 495# cpan-bug #33708
227375e1
RU
496%{$_ || {}}
497####
4a4b8592 498# TODO hash constants not yet fixed
507a68aa 499# cpan-bug #33708
227375e1
RU
500use constant H => { "#" => 1 }; H->{"#"}
501####
4a4b8592 502# TODO optimized away 0 not yet fixed
507a68aa 503# cpan-bug #33708
227375e1 504foreach my $i (@_) { 0 }
edbe35ea 505####
507a68aa 506# tests with not, not optimized
07f3cdf5 507my $c;
edbe35ea
VP
508x() unless $a;
509x() if not $a and $b;
510x() if $a and not $b;
511x() unless not $a and $b;
512x() unless $a and not $b;
513x() if not $a or $b;
514x() if $a or not $b;
515x() unless not $a or $b;
516x() unless $a or not $b;
07f3cdf5
VP
517x() if $a and not $b and $c;
518x() if not $a and $b and not $c;
519x() unless $a and not $b and $c;
520x() unless not $a and $b and not $c;
521x() if $a or not $b or $c;
522x() if not $a or $b or not $c;
523x() unless $a or not $b or $c;
524x() unless not $a or $b or not $c;
edbe35ea 525####
507a68aa 526# tests with not, optimized
07f3cdf5 527my $c;
edbe35ea
VP
528x() if not $a;
529x() unless not $a;
530x() if not $a and not $b;
531x() unless not $a and not $b;
532x() if not $a or not $b;
533x() unless not $a or not $b;
07f3cdf5
VP
534x() if not $a and not $b and $c;
535x() unless not $a and not $b and $c;
536x() if not $a or not $b or $c;
537x() unless not $a or not $b or $c;
538x() if not $a and not $b and not $c;
539x() unless not $a and not $b and not $c;
540x() if not $a or not $b or not $c;
541x() unless not $a or not $b or not $c;
542x() unless not $a or not $b or not $c;
edbe35ea 543>>>>
07f3cdf5 544my $c;
edbe35ea
VP
545x() unless $a;
546x() if $a;
547x() unless $a or $b;
548x() if $a or $b;
549x() unless $a and $b;
07f3cdf5
VP
550x() if $a and $b;
551x() if not $a || $b and $c;
552x() unless not $a || $b and $c;
553x() if not $a && $b or $c;
554x() unless not $a && $b or $c;
555x() unless $a or $b or $c;
556x() if $a or $b or $c;
557x() unless $a and $b and $c;
558x() if $a and $b and $c;
559x() unless not $a && $b && $c;
71c4dbc3 560####
507a68aa 561# tests that should be constant folded
71c4dbc3
VP
562x() if 1;
563x() if GLIPP;
564x() if !GLIPP;
565x() if GLIPP && GLIPP;
566x() if !GLIPP || GLIPP;
567x() if do { GLIPP };
568x() if do { no warnings 'void'; 5; GLIPP };
569x() if do { !GLIPP };
570if (GLIPP) { x() } else { z() }
571if (!GLIPP) { x() } else { z() }
572if (GLIPP) { x() } elsif (GLIPP) { z() }
573if (!GLIPP) { x() } elsif (GLIPP) { z() }
574if (GLIPP) { x() } elsif (!GLIPP) { z() }
575if (!GLIPP) { x() } elsif (!GLIPP) { z() }
576if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
577if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
578if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
579>>>>
580x();
581x();
582'???';
583x();
584x();
585x();
586x();
587do {
588 '???'
589};
590do {
591 x()
592};
593do {
594 z()
595};
596do {
597 x()
598};
599do {
600 z()
601};
602do {
603 x()
604};
605'???';
606do {
607 t()
608};
609'???';
610!1;
611####
719c50dc
RGS
612# TODO constant deparsing has been backed out for 5.12
613# XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
507a68aa 614# tests that shouldn't be constant folded
ac0f1413
NC
615# It might be fundamentally impossible to make this work on ithreads, in which
616# case the TODO should become a SKIP
71c4dbc3
VP
617x() if $a;
618if ($a == 1) { x() } elsif ($b == 2) { z() }
619if (do { foo(); GLIPP }) { x() }
620if (do { $a++; GLIPP }) { x() }
621>>>>
622x() if $a;
623if ($a == 1) { x(); } elsif ($b == 2) { z(); }
2990415a
FR
624if (do { foo(); GLIPP }) { x(); }
625if (do { ++$a; GLIPP }) { x(); }
626####
0fa4a265 627# TODO constant deparsing has been backed out for 5.12
507a68aa 628# tests for deparsing constants
2990415a
FR
629warn PI;
630####
0fa4a265 631# TODO constant deparsing has been backed out for 5.12
507a68aa 632# tests for deparsing imported constants
3779476a 633warn O_TRUNC;
2990415a 634####
0fa4a265 635# TODO constant deparsing has been backed out for 5.12
507a68aa 636# tests for deparsing re-exported constants
2990415a
FR
637warn O_CREAT;
638####
0fa4a265 639# TODO constant deparsing has been backed out for 5.12
507a68aa 640# tests for deparsing imported constants that got deleted from the original namespace
aaf9c2b2 641warn O_APPEND;
2990415a 642####
0fa4a265
DM
643# TODO constant deparsing has been backed out for 5.12
644# XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
507a68aa 645# tests for deparsing constants which got turned into full typeglobs
ac0f1413
NC
646# It might be fundamentally impossible to make this work on ithreads, in which
647# case the TODO should become a SKIP
2990415a
FR
648warn O_EXCL;
649eval '@Fcntl::O_EXCL = qw/affe tiger/;';
650warn O_EXCL;
651####
0fa4a265 652# TODO constant deparsing has been backed out for 5.12
507a68aa 653# tests for deparsing of blessed constant with overloaded numification
2990415a 654warn OVERLOADED_NUMIFICATION;
79289e05
NC
655####
656# TODO Only strict 'refs' currently supported
507a68aa 657# strict
79289e05
NC
658no strict;
659$x;
660####
661# TODO Subsets of warnings could be encoded textually, rather than as bitflips.
507a68aa 662# subsets of warnings
79289e05
NC
663no warnings 'deprecated';
664my $x;
665####
666# TODO Better test for CPAN #33708 - the deparsed code has different behaviour
507a68aa 667# CPAN #33708
79289e05
NC
668use strict;
669no warnings;
670
671foreach (0..3) {
672 my $x = 2;
673 {
674 my $x if 0;
675 print ++$x, "\n";
676 }
677}
d83f38d8 678####
507a68aa 679# no attribute list
d83f38d8
NC
680my $pi = 4;
681####
2dc78664
NC
682# SKIP ?$] > 5.013006 && ":= is now a syntax error"
683# := treated as an empty attribute list
d83f38d8
NC
684no warnings;
685my $pi := 4;
686>>>>
687no warnings;
688my $pi = 4;
689####
507a68aa 690# : = empty attribute list
d83f38d8
NC
691my $pi : = 4;
692>>>>
693my $pi = 4;
689e417f 694####
507a68aa 695# in place sort
689e417f
VP
696our @a;
697my @b;
698@a = sort @a;
699@b = sort @b;
700();
701####
507a68aa 702# in place reverse
689e417f
VP
703our @a;
704my @b;
705@a = reverse @a;
706@b = reverse @b;
707();
06fc6867 708####
507a68aa 709# #71870 Use of uninitialized value in bitwise and B::Deparse
06fc6867
VP
710my($r, $s, @a);
711@a = split(/foo/, $s, 0);
712$r = qr/foo/;
713@a = split(/$r/, $s, 0);
714();
98a1a137 715####
507a68aa 716# package declaration before label
98a1a137
Z
717{
718 package Foo;
719 label: print 123;
720}
538f5756 721####
507a68aa 722# shift optimisation
538f5756
RZ
723shift;
724>>>>
725shift();
726####
507a68aa 727# shift optimisation
538f5756
RZ
728shift @_;
729####
507a68aa 730# shift optimisation
538f5756
RZ
731pop;
732>>>>
733pop();
734####
507a68aa 735# shift optimisation
538f5756 736pop @_;
a539498a 737####
507a68aa 738#[perl #20444]
a539498a
FC
739"foo" =~ (1 ? /foo/ : /bar/);
740"foo" =~ (1 ? y/foo// : /bar/);
5e5a1632 741"foo" =~ (1 ? y/foo//r : /bar/);
a539498a
FC
742"foo" =~ (1 ? s/foo// : /bar/);
743>>>>
744'foo' =~ ($_ =~ /foo/);
745'foo' =~ ($_ =~ tr/fo//);
5e5a1632 746'foo' =~ ($_ =~ tr/fo//r);
a539498a 747'foo' =~ ($_ =~ s/foo//);
e0ab66ad 748####
5e5a1632
FC
749# The fix for [perl #20444] broke this.
750'foo' =~ do { () };
751####
4b58603b
FC
752# [perl #81424] match against aelemfast_lex
753my @s;
754print /$s[1]/;
755####
e0ab66ad
NC
756# Test @threadsv_names under 5005threads
757foreach $' (1, 2) {
758 sleep $';
759}
e7afc405
FC
760####
761# y///r
762tr/a/b/r;
cb8157e3
FC
763####
764# y/uni/code/
765tr/\x{345}/\x{370}/;
cb8578ff
FC
766####
767# [perl #90898]
f4002a4b 768<a,>;
09dcfa7d
FC
769####
770# [perl #91008]
771each $@;
772keys $~;
773values $!;
5d8c42c2
FC
774####
775# readpipe with complex expression
776readpipe $a + $b;
93bad3fd
NC
777####
778# aelemfast
779$b::a[0] = 1;
780####
781# aelemfast for a lexical
782my @a;
783$a[0] = 1;
80e3f4ad
FC
784####
785# feature features without feature
786BEGIN {
787 delete $^H{'feature_say'};
788 delete $^H{'feature_state'};
789 delete $^H{'feature_switch'};
790}
791CORE::state $x;
792CORE::say $x;
793CORE::given ($x) {
794 CORE::when (3) {
795 continue;
796 }
797 CORE::default {
e36901c8 798 CORE::break;
80e3f4ad
FC
799 }
800}
7d789282 801CORE::evalbytes '';
84ed0108 802() = CORE::__SUB__;
6ec73527
FC
803####
804# $#- $#+ $#{%} etc.
805my @x;
806@x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
807@x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
808@x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
809@x = ($#{;}, $#{:});
61154ac0
FC
810####
811# ${#} interpolated (the first line magically disables the warning)
812() = *#;
813() = "${#}a";
958ed56b
FC
814####
815# ()[...]
816my(@a) = ()[()];
521795fe
FC
817####
818# sort(foo(bar))
819# sort(foo(bar)) is interpreted as sort &foo(bar)
820# sort foo(bar) is interpreted as sort foo bar
821# parentheses are not optional in this case
822print sort(foo('bar'));
823>>>>
824print sort(foo('bar'));
24fcb59f
FC
825####
826# substr assignment
827substr(my $a, 0, 0) = (foo(), bar());
828$a++;
04be0204
FC
829####
830# hint hash
831BEGIN { $^H{'foo'} = undef; }
832{
833 BEGIN { $^H{'bar'} = undef; }
834 {
835 BEGIN { $^H{'baz'} = undef; }
836 {
837 print $_;
838 }
839 print $_;
840 }
841 print $_;
842}
035146a3
FC
843BEGIN { $^H{q[']} = '('; }
844print $_;
c306e834
FC
845####
846# hint hash changes that serialise the same way with sort %hh
847BEGIN { $^H{'a'} = 'b'; }
848{
849 BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
850 print $_;
851}
852print $_;
94bb57f9
FC
853####
854# [perl #47361] do({}) and do +{} (variants of do-file)
855do({});
856do +{};
8b46c09b
FC
857sub foo::do {}
858package foo;
859CORE::do({});
860CORE::do +{};
94bb57f9
FC
861>>>>
862do({});
863do({});
8b46c09b
FC
864package foo;
865CORE::do({});
866CORE::do({});
9c56d9ea
FC
867####
868# [perl #77096] functions that do not follow the llafr
869() = (return 1) + time;
870() = (return ($1 + $2) * $3) + time;
871() = (return ($a xor $b)) + time;
872() = (do 'file') + time;
873() = (do ($1 + $2) * $3) + time;
874() = (do ($1 xor $2)) + time;
41df74e3
FC
875() = (goto 1) + 3;
876() = (require 'foo') + 3;
877() = (require foo) + 3;
266da325 878() = (CORE::dump 1) + 3;
41df74e3
FC
879() = (last 1) + 3;
880() = (next 1) + 3;
881() = (redo 1) + 3;
5830412d
FC
882() = (-R $_) + 3;
883() = (-W $_) + 3;
884() = (-X $_) + 3;
885() = (-r $_) + 3;
886() = (-w $_) + 3;
887() = (-x $_) + 3;
2462c3cc 888####
1cabb3b3
FC
889# [perl #97476] not() *does* follow the llafr
890$_ = ($a xor not +($1 || 2) ** 2);
891####
4d8ac5c7
FC
892# Precedence conundrums with argument-less function calls
893() = (eof) + 1;
894() = (return) + 1;
895() = (return, 1);
7bc8c979
FC
896() = warn;
897() = warn() + 1;
4d8ac5c7
FC
898() = setpgrp() + 1;
899####
2462c3cc
FC
900# [perl #63558] open local(*FH)
901open local *FH;
564cd6cb 902pipe local *FH, local *FH;
843b15cc 903####
b89b7257
FC
904# [perl #91416] open "string"
905open 'open';
906open '####';
907open '^A';
908open "\ca";
909>>>>
910open *open;
911open '####';
912open '^A';
913open *^A;
914####
be6cf5cf
FC
915# "string"->[] ->{}
916no strict 'vars';
917() = 'open'->[0]; #aelemfast
918() = '####'->[0];
919() = '^A'->[0];
920() = "\ca"->[0];
b861b87f 921() = 'a::]b'->[0];
10e8e32b
FC
922() = 'open'->[$_]; #aelem
923() = '####'->[$_];
924() = '^A'->[$_];
925() = "\ca"->[$_];
b861b87f 926() = 'a::]b'->[$_];
10e8e32b
FC
927() = 'open'->{0}; #helem
928() = '####'->{0};
929() = '^A'->{0};
930() = "\ca"->{0};
b861b87f 931() = 'a::]b'->{0};
be6cf5cf
FC
932>>>>
933() = $open[0];
934() = '####'->[0];
935() = '^A'->[0];
936() = $^A[0];
b861b87f 937() = 'a::]b'->[0];
10e8e32b
FC
938() = $open[$_];
939() = '####'->[$_];
940() = '^A'->[$_];
941() = $^A[$_];
b861b87f 942() = 'a::]b'->[$_];
10e8e32b
FC
943() = $open{'0'};
944() = '####'->{'0'};
945() = '^A'->{'0'};
946() = $^A{'0'};
b861b87f 947() = 'a::]b'->{'0'};
be6cf5cf 948####
843b15cc
FC
949# [perl #74740] -(f()) vs -f()
950$_ = -(f());
c75b4828
FC
951####
952# require <binop>
953require 'a' . $1;