This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
move sub attributes before the signature
[perl5.git] / lib / B / Deparse.t
CommitLineData
87a42246
MS
1#!./perl
2
3BEGIN {
738f9dbf 4 splice @INC, 0, 0, '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 }
738f9dbf 10 require 'test.pl';
87a42246
MS
11}
12
87a42246
MS
13use warnings;
14use strict;
87a42246 15
7d9a919c 16my $tests = 52; # 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}) {
f9d3bdea 48 SKIP: { skip($meta{skip}) };
e9c69003
NC
49 next;
50 }
51
ad46c0be
RH
52 my ($input, $expected);
53 if (/(.*)\n>>>>\n(.*)/s) {
54 ($input, $expected) = ($1, $2);
55 }
56 else {
57 ($input, $expected) = ($_, $_);
58 }
87a42246 59
4da9a2ca
FC
60 # parse options if necessary
61 my $deparse = $meta{options}
62 ? $deparse{$meta{options}} ||=
63 new B::Deparse split /,/, $meta{options}
64 : $deparse;
65
27cbbc57 66 my $code = "$meta{context};\n" . <<'EOC' . "sub {$input\n}";
a6087f24
NC
67# Tell B::Deparse about our ambient pragmas
68my ($hint_bits, $warning_bits, $hinthash);
69BEGIN {
70 ($hint_bits, $warning_bits, $hinthash) = ($^H, ${^WARNING_BITS}, \%^H);
71}
72$deparse->ambient_pragmas (
73 hint_bits => $hint_bits,
74 warning_bits => $warning_bits,
75 '%^H' => $hinthash,
76);
77EOC
27cbbc57 78 my $coderef = eval $code;
87a42246 79
c9fa6ae9 80 local $::TODO = $meta{todo};
ad46c0be 81 if ($@) {
27cbbc57
DM
82 is($@, "", "compilation of $desc")
83 or diag "=============================================\n"
84 . "CODE:\n--------\n$code\n--------\n"
85 . "=============================================\n";
ad46c0be
RH
86 }
87 else {
88 my $deparsed = $deparse->coderef2text( $coderef );
31c6271a
RD
89 my $regex = $expected;
90 $regex =~ s/(\S+)/\Q$1/g;
91 $regex =~ s/\s+/\\s+/g;
92 $regex = '^\{\s*' . $regex . '\s*\}$';
b871937f 93
bc304ab2
DM
94 like($deparsed, qr/$regex/, $desc)
95 or diag "=============================================\n"
96 . "CODE:\n--------\n$input\n--------\n"
97 . "EXPECTED:\n--------\n{\n$expected\n}\n--------\n"
98 . "GOT:\n--------\n$deparsed\n--------\n"
99 . "=============================================\n";
87a42246 100 }
87a42246
MS
101}
102
9187b6e4
FC
103# Reset the ambient pragmas
104{
105 my ($b, $w, $h);
106 BEGIN {
107 ($b, $w, $h) = ($^H, ${^WARNING_BITS}, \%^H);
108 }
109 $deparse->ambient_pragmas (
110 hint_bits => $b,
111 warning_bits => $w,
112 '%^H' => $h,
113 );
114}
115
87a42246 116use constant 'c', 'stuff';
507a68aa
NC
117is((eval "sub ".$deparse->coderef2text(\&c))->(), 'stuff',
118 'the subroutine generated by use constant deparses');
87a42246 119
09d856fb 120my $a = 0;
507a68aa
NC
121is($deparse->coderef2text(sub{(-1) ** $a }), "{\n (-1) ** \$a;\n}",
122 'anon sub capturing an external lexical');
87a42246 123
d989cdac
SM
124use constant cr => ['hello'];
125my $string = "sub " . $deparse->coderef2text(\&cr);
0707d6cc 126my $val = (eval $string)->() or diag $string;
507a68aa
NC
127is(ref($val), 'ARRAY', 'constant array references deparse');
128is($val->[0], 'hello', 'and return the correct value');
87a42246 129
87a42246 130my $path = join " ", map { qq["-I$_"] } @INC;
87a42246 131
7cde0a5f 132$a = `$^X $path "-MO=Deparse" -anlwi.bak -e 1 2>&1`;
e69a2255 133$a =~ s/-e syntax OK\n//g;
d2bc402e 134$a =~ s/.*possible typo.*\n//; # Remove warning line
82f96200 135$a =~ s/.*-i used with no filenames.*\n//; # Remove warning line
c96cf1c0 136$b = quotemeta <<'EOF';
d2bc402e
RGS
137BEGIN { $^I = ".bak"; }
138BEGIN { $^W = 1; }
139BEGIN { $/ = "\n"; $\ = "\n"; }
18371617 140LINE: while (defined($_ = readline ARGV)) {
87a42246 141 chomp $_;
f86ea535 142 our(@F) = split(' ', $_, 0);
87a42246
MS
143 '???';
144}
87a42246 145EOF
c96cf1c0
FC
146$b =~ s/our\\\(\\\@F\\\)/our[( ]\@F\\)?/; # accept both our @F and our(@F)
147like($a, qr/$b/,
507a68aa 148 'command line flags deparse as BEGIN blocks setting control variables');
87a42246 149
5b4ee549
NC
150$a = `$^X $path "-MO=Deparse" -e "use constant PI => 4" 2>&1`;
151$a =~ s/-e syntax OK\n//g;
6436970c 152is($a, "use constant ('PI', 4);\n",
5b4ee549
NC
153 "Proxy Constant Subroutines must not show up as (incorrect) prototypes");
154
a9cafc78
FC
155$a = `$^X $path "-MO=Deparse" -e "sub foo(){1}" 2>&1`;
156$a =~ s/-e syntax OK\n//g;
157is($a, "sub foo () {\n 1;\n}\n",
158 "Main prog consisting of just a constant (via empty proto)");
159
160$a = readpipe qq|$^X $path "-MO=Deparse"|
161 .qq| -e "package F; sub f(){0} sub s{}"|
162 .qq| -e "#line 123 four-five-six"|
163 .qq| -e "package G; sub g(){0} sub s{}" 2>&1|;
164$a =~ s/-e syntax OK\n//g;
6fbf0c31 165like($a, qr/sub F::f \(\) \{\s*0;?\s*}/,
a9cafc78
FC
166 "Constant is dumped in package in which other subs are dumped");
167unlike($a, qr/sub g/,
168 "Constant is not dumped in package in which other subs are not dumped");
169
579a54dc 170#Re: perlbug #35857, patch #24505
b3980c39
YO
171#handle warnings::register-ed packages properly.
172package B::Deparse::Wrapper;
173use strict;
174use warnings;
175use warnings::register;
176sub getcode {
579a54dc 177 my $deparser = B::Deparse->new();
b3980c39
YO
178 return $deparser->coderef2text(shift);
179}
180
2990415a
FR
181package Moo;
182use overload '0+' => sub { 42 };
183
b3980c39
YO
184package main;
185use strict;
186use warnings;
71c4dbc3 187use constant GLIPP => 'glipp';
2990415a
FR
188use constant PI => 4;
189use constant OVERLOADED_NUMIFICATION => bless({}, 'Moo');
3779476a 190use Fcntl qw/O_TRUNC O_APPEND O_EXCL/;
aaf9c2b2 191BEGIN { delete $::Fcntl::{O_APPEND}; }
2990415a 192use POSIX qw/O_CREAT/;
b3980c39 193sub test {
579a54dc
RGS
194 my $val = shift;
195 my $res = B::Deparse::Wrapper::getcode($val);
507a68aa
NC
196 like($res, qr/use warnings/,
197 '[perl #35857] [PATCH] B::Deparse doesnt handle warnings register properly');
b3980c39
YO
198}
199my ($q,$p);
200my $x=sub { ++$q,++$p };
201test($x);
202eval <<EOFCODE and test($x);
203 package bar;
204 use strict;
205 use warnings;
206 use warnings::register;
207 package main;
208 1
209EOFCODE
210
d1dc589d
FC
211# Exotic sub declarations
212$a = `$^X $path "-MO=Deparse" -e "sub ::::{}sub ::::::{}" 2>&1`;
213$a =~ s/-e syntax OK\n//g;
214is($a, <<'EOCODG', "sub :::: and sub ::::::");
215sub :::: {
216
217}
218sub :::::: {
219
220}
221EOCODG
222
f2734596 223# [perl #117311]
224$a = `$^X $path "-MO=Deparse,-l" -e "map{ eval(0) }()" 2>&1`;
225$a =~ s/-e syntax OK\n//g;
226is($a, <<'EOCODH', "[perl #117311] [PATCH] -l option ('#line ...') does not emit ^Ls in the output");
227#line 1 "-e"
228map {
229#line 1 "-e"
230eval 0;} ();
231EOCODH
232
640d5d41
FC
233# [perl #33752]
234{
235 my $code = <<"EOCODE";
236{
237 our \$\x{1e1f}\x{14d}\x{14d};
238}
239EOCODE
240 my $deparsed
241 = $deparse->coderef2text(eval "sub { our \$\x{1e1f}\x{14d}\x{14d} }" );
242 s/$ \n//x for $deparsed, $code;
243 is $deparsed, $code, 'our $funny_Unicode_chars';
244}
245
bdabb2d5
FC
246# [perl #62500]
247$a =
248 `$^X $path "-MO=Deparse" -e "BEGIN{*CORE::GLOBAL::require=sub{1}}" 2>&1`;
249$a =~ s/-e syntax OK\n//g;
250is($a, <<'EOCODF', "CORE::GLOBAL::require override causing panick");
251sub BEGIN {
252 *CORE::GLOBAL::require = sub {
253 1;
254 }
255 ;
256}
257EOCODF
258
894e98ac
FC
259# [perl #91384]
260$a =
261 `$^X $path "-MO=Deparse" -e "BEGIN{*Acme::Acme:: = *Acme::}" 2>&1`;
262like($a, qr/-e syntax OK/,
263 "Deparse does not hang when traversing stash circularities");
264
bb8996b8 265# [perl #93990]
08412a26 266@] = ();
73f4c4fe 267is($deparse->coderef2text(sub{ print "foo@{]}" }),
bb8996b8 268q<{
73f4c4fe 269 print "foo@{]}";
08412a26 270}>, 'curly around to interpolate "@{]}"');
73f4c4fe 271is($deparse->coderef2text(sub{ print "foo@{-}" }),
bb8996b8 272q<{
73f4c4fe 273 print "foo@-";
bb8996b8
HY
274}>, 'no need to curly around to interpolate "@-"');
275
1c74777c
FC
276# Strict hints in %^H are mercilessly suppressed
277$a =
278 `$^X $path "-MO=Deparse" -e "use strict; print;" 2>&1`;
279unlike($a, qr/BEGIN/,
280 "Deparse does not emit strict hh hints");
281
3036b99c
FC
282# ambient_pragmas should not mess with strict settings.
283SKIP: {
284 skip "requires 5.11", 1 unless $] >= 5.011;
285 eval q`
3036b99c 286 BEGIN {
d1718a7c 287 # Clear out all hints
3036b99c 288 %^H = ();
d1718a7c 289 $^H = 0;
3036b99c
FC
290 new B::Deparse -> ambient_pragmas(strict => 'all');
291 }
292 use 5.011; # should enable strict
293 ok !eval '$do_noT_create_a_variable_with_this_name = 1',
294 'ambient_pragmas do not mess with compiling scope';
295 `;
296}
297
93a8ff62
FC
298# multiple statements on format lines
299$a = `$^X $path "-MO=Deparse" -e "format =" -e "\@" -e "x();z()" -e. 2>&1`;
300$a =~ s/-e syntax OK\n//g;
93a8ff62
FC
301is($a, <<'EOCODH', 'multiple statements on format lines');
302format STDOUT =
303@
304x(); z()
305.
306EOCODH
307
ddb55548
FC
308is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
309 prog => "format =\n\@\n\$;\n.\n"),
310 <<'EOCODM', '$; on format line';
311format STDOUT =
312@
313$;
314.
315EOCODM
316
e56a605e
FC
317is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse,-l', $path ],
318 prog => "format =\n\@\n\$foo\n.\n"),
319 <<'EOCODM', 'formats with -l';
320format STDOUT =
321@
322$foo
323.
324EOCODM
325
8b9fb2f9
FC
326is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
327 prog => "{ my \$x; format =\n\@\n\$x\n.\n}"),
328 <<'EOCODN', 'formats nested inside blocks';
329{
330 my $x;
331 format STDOUT =
332@
333$x
334.
335}
336EOCODN
337
7741ceed
FC
338# CORE::format
339$a = readpipe qq`$^X $path "-MO=Deparse" -e "use feature q|:all|;`
340 .qq` my sub format; CORE::format =" -e. 2>&1`;
341like($a, qr/CORE::format/, 'CORE::format when lex format sub is in scope');
342
fea7fb25
DM
343# literal big chars under 'use utf8'
344is($deparse->coderef2text(sub{ use utf8; /€/; }),
345'{
346 /\x{20ac}/;
347}',
348"qr/euro/");
349
e54915d6
FC
350# STDERR when deparsing sub calls
351# For a short while the output included 'While deparsing'
352$a = `$^X $path "-MO=Deparse" -e "foo()" 2>&1`;
353$a =~ s/-e syntax OK\n//g;
354is($a, <<'EOCODI', 'no extra output when deparsing foo()');
355foo();
356EOCODI
357
84ed3992
FC
358# Sub calls compiled before importation
359like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
360 prog => 'BEGIN {
361 require Test::More;
362 Test::More::->import;
363 is(*foo, *foo)
364 }'),
365 qr/&is\(/,
366 'sub calls compiled before importation of prototype subs';
367
a93cf6e2
FC
368# [perl #121050] Prototypes with whitespace
369is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
370 prog => <<'EOCODO'),
371sub _121050(\$ \$) { }
372_121050($a,$b);
373sub _121050empty( ) {}
374() = _121050empty() + 1;
375EOCODO
376 <<'EOCODP', '[perl #121050] prototypes with whitespace';
377sub _121050 (\$ \$) {
378
379}
380_121050 $a, $b;
381sub _121050empty ( ) {
382
383}
384() = _121050empty + 1;
385EOCODP
386
7741ceed
FC
387# CORE::no
388$a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
389 .qq`"use feature q|:all|; my sub no; CORE::no less" 2>&1`;
e276dec7 390like($a, qr/my sub no;\n.*CORE::no less;/s,
7741ceed
FC
391 'CORE::no after my sub no');
392
393# CORE::use
394$a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
395 .qq`"use feature q|:all|; my sub use; CORE::use less" 2>&1`;
e276dec7 396like($a, qr/my sub use;\n.*CORE::use less;/s,
7741ceed
FC
397 'CORE::use after my sub use');
398
399# CORE::__DATA__
400$a = readpipe qq`$^X $path "-MO=Deparse" -Xe `
401 .qq`"use feature q|:all|; my sub __DATA__; `
402 .qq`CORE::__DATA__" 2>&1`;
e276dec7 403like($a, qr/my sub __DATA__;\n.*CORE::__DATA__/s,
7741ceed
FC
404 'CORE::__DATA__ after my sub __DATA__');
405
fe8d6c18
FC
406# sub declarations
407$a = readpipe qq`$^X $path "-MO=Deparse" -e "sub foo{}" 2>&1`;
dd3f0a7a 408like($a, qr/sub foo\s*\{\s+\}/, 'sub declarations');
67359f08
FC
409like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
410 prog => 'sub f($); sub f($){}'),
411 qr/sub f\s*\(\$\)\s*\{\s*\}/,
412 'predeclared prototyped subs';
de001ba0
FC
413like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
414 prog => 'use Scalar::Util q-weaken-;
415 sub f($);
416 BEGIN { weaken($_=\$::{f}) }'),
417 qr/sub f\s*\(\$\)\s*;/,
418 'prototyped stub with weak reference to the stash entry';
03b8f76d
FC
419like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
420 prog => 'sub f () { 42 }'),
421 qr/sub f\s*\(\)\s*\{\s*42;\s*\}/,
422 'constant perl sub declaration';
fe8d6c18 423
8635e3c2
FC
424# BEGIN blocks
425SKIP : {
426 skip "BEGIN output is wrong on old perls", 1 if $] < 5.021006;
427 my $prog = '
428 BEGIN { pop }
429 {
430 BEGIN { pop }
431 {
432 no overloading;
433 {
434 BEGIN { pop }
435 die
436 }
437 }
438 }';
439 $prog =~ s/\n//g;
440 $a = readpipe qq`$^X $path "-MO=Deparse" -e "$prog" 2>&1`;
441 $a =~ s/-e syntax OK\n//g;
442 is($a, <<'EOCODJ', 'BEGIN blocks');
443sub BEGIN {
444 pop @ARGV;
445}
446{
447 sub BEGIN {
448 pop @ARGV;
449 }
450 {
451 no overloading;
452 {
453 sub BEGIN {
454 pop @ARGV;
455 }
456 die;
457 }
458 }
459}
460EOCODJ
461}
34b54951
FC
462is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ], prog => '
463 {
464 {
465 die;
466 BEGIN { pop }
467 }
468 BEGIN { pop }
469 }
470 BEGIN { pop }
471 '), <<'EOCODL', 'BEGIN blocks at the end of their enclosing blocks';
472{
473 {
474 die;
475 sub BEGIN {
476 pop @ARGV;
477 }
34b54951
FC
478 }
479 sub BEGIN {
480 pop @ARGV;
481 }
34b54951
FC
482}
483sub BEGIN {
484 pop @ARGV;
485}
34b54951 486EOCODL
93a8ff62 487
c310a5ab
FC
488# BEGIN blocks should not be called __ANON__
489like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
490 prog => 'sub BEGIN { } CHECK { delete $::{BEGIN} }'),
491 qr/sub BEGIN/, 'anonymised BEGIN';
492
1f9498d0 493# [perl #115066]
1f9498d0
FC
494my $prog = 'use constant FOO => do { 1 }; no overloading; die';
495$a = readpipe qq`$^X $path "-MO=-qq,Deparse" -e "$prog" 2>&1`;
496is($a, <<'EOCODK', '[perl #115066] use statements accidentally nested');
497use constant ('FOO', do {
d88d1fe0 498 1
1f9498d0
FC
499});
500no overloading;
501die;
502EOCODK
503
f1013307
FC
504# BEGIN blocks inside predeclared subs
505like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
506 prog => '
507 sub run_tests;
508 run_tests();
509 sub run_tests { BEGIN { } die }'),
510 qr/sub run_tests \{\s*sub BEGIN/,
511 'BEGIN block inside predeclared sub';
512
d49c3562 513like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
d98ae4a6
FC
514 prog => 'package foo; use overload qr=>sub{}'),
515 qr/package foo;\s*use overload/,
516 'package, then use';
517
518like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
d49c3562
FC
519 prog => 'use feature lexical_subs=>; my sub f;sub main::f{}'),
520 qr/^sub main::f \{/m,
521 'sub decl when lex sub is in scope';
522
f518ad75
FC
523like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
524 prog => 'sub foo{foo()}'),
525 qr/^sub foo \{\s+foo\(\)/m,
526 'recursive sub';
527
2c5ddcd3
FC
528like runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
529 prog => 'use feature lexical_subs=>state=>;
530 state sub sb5; sub { sub sb5 { } }'),
401e2e00 531 qr/sub \{\s*\(\);\s*sub sb5 \{/m,
2c5ddcd3
FC
532 'state sub in anon sub but declared outside';
533
5e965771
FC
534is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
535 prog => 'BEGIN { $::{f}=\!0 }'),
536 "sub BEGIN {\n \$main::{'f'} = \\1;\n}\n",
537 '&PL_sv_yes constant (used to croak)';
538
d02d1323
FC
539is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-T' ],
540 prog => '$x =~ (1?/$a/:0)'),
541 '$x =~ ($_ =~ /$a/);'."\n",
542 '$foo =~ <branch-folded match> under taint mode';
543
62ae7cfb
FC
544unlike runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path, '-w' ],
545 prog => 'BEGIN { undef &foo }'),
546 qr'Use of uninitialized value',
547 'no warnings for undefined sub';
548
7d9a919c
DM
549is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
550 prog => 'sub f { 1; } BEGIN { *g = \&f; }'),
551 "sub f {\n 1;\n}\nsub BEGIN {\n *g = \\&f;\n}\n",
552 "sub glob alias shouldn't impede emitting original sub";
553
554is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
555 prog => 'package Foo; sub f { 1; } BEGIN { *g = \&f; }'),
556 "package Foo;\nsub f {\n 1;\n}\nsub BEGIN {\n *g = \\&f;\n}\n",
557 "sub glob alias outside main shouldn't impede emitting original sub";
558
559is runperl(stderr => 1, switches => [ '-MO=-qq,Deparse', $path ],
560 prog => 'package Foo; sub f { 1; } BEGIN { *Bar::f = \&f; }'),
561 "package Foo;\nsub f {\n 1;\n}\nsub BEGIN {\n *Bar::f = \\&f;\n}\n",
562 "sub glob alias in separate package shouldn't impede emitting original sub";
563
564
d8cf01c3 565done_testing($tests);
507a68aa 566
ad46c0be 567__DATA__
b8346d05
KW
568# TODO [perl #120950] This succeeds when run a 2nd time
569# y/uni/code/
570tr/\x{345}/\x{370}/;
571####
572# y/uni/code/ [perl #120950] This 2nd instance succeeds
573tr/\x{345}/\x{370}/;
574####
507a68aa 575# A constant
ad46c0be
RH
5761;
577####
507a68aa 578# Constants in a block
f5b5c2a3 579# CONTEXT no warnings;
ad46c0be 580{
ad46c0be
RH
581 '???';
582 2;
583}
584####
40ced2f4
FC
585# List of constants in void context
586# CONTEXT no warnings;
587(1,2,3);
5880;
589>>>>
590'???', '???', '???';
5910;
592####
507a68aa 593# Lexical and simple arithmetic
ad46c0be
RH
594my $test;
595++$test and $test /= 2;
596>>>>
597my $test;
598$test /= 2 if ++$test;
599####
507a68aa 600# list x
ad46c0be
RH
601-((1, 2) x 2);
602####
6a861075
FC
603# Assignment to list x
604((undef) x 3) = undef;
605####
507a68aa 606# lvalue sub
ad46c0be
RH
607{
608 my $test = sub : lvalue {
609 my $x;
610 }
611 ;
612}
613####
507a68aa 614# method
ad46c0be
RH
615{
616 my $test = sub : method {
617 my $x;
618 }
619 ;
620}
621####
6b6b21da
FC
622# anonsub attrs at statement start
623my $x = do { +sub : lvalue { my $y; } };
624my $z = do { foo: +sub : method { my $a; } };
625####
507a68aa 626# block with continue
87a42246 627{
ad46c0be 628 234;
f99a63a2 629}
ad46c0be
RH
630continue {
631 123;
87a42246 632}
ce4e655d 633####
507a68aa 634# lexical and package scalars
ce4e655d
RH
635my $x;
636print $main::x;
637####
507a68aa 638# lexical and package arrays
ce4e655d
RH
639my @x;
640print $main::x[1];
0ed5b3c8 641print \my @a;
14a55f98 642####
507a68aa 643# lexical and package hashes
14a55f98
RH
644my %x;
645$x{warn()};
ad8caead 646####
66786896
FC
647# our (LIST)
648our($foo, $bar, $baz);
649####
56cd2ef8
FC
650# CONTEXT { package Dog } use feature "state";
651# variables with declared classes
652my Dog $spot;
653our Dog $spotty;
654state Dog $spotted;
655my Dog @spot;
656our Dog @spotty;
657state Dog @spotted;
658my Dog %spot;
659our Dog %spotty;
660state Dog %spotted;
661my Dog ($foo, @bar, %baz);
662our Dog ($phoo, @barr, %bazz);
663state Dog ($fough, @barre, %bazze);
664####
f3515641
FC
665# local our
666local our $rhubarb;
5f4d8496 667local our($rhu, $barb);
f3515641 668####
507a68aa 669# <>
ad8caead 670my $foo;
18371617
LM
671$_ .= <> . <ARGV> . <$foo>;
672<$foo>;
673<${foo}>;
674<$ foo>;
675>>>>
676my $foo;
677$_ .= readline(ARGV) . readline(ARGV) . readline($foo);
678readline $foo;
679glob $foo;
680glob $foo;
cef22867 681####
9cef6114
FC
682# readline
683readline 'FH';
684readline *$_;
18371617
LM
685readline *{$_};
686readline ${"a"};
687>>>>
688readline 'FH';
689readline *$_;
9cef6114 690readline *{$_;};
18371617 691readline ${'a';};
9cef6114 692####
2fcbb74a
FC
693# <<>>
694$_ = <<>>;
695####
507a68aa 696# \x{}
11454c59 697my $foo = "Ab\x{100}\200\x{200}\237Cd\000Ef\x{1000}\cA\x{2000}\cZ";
2a43599b 698my $bar = "\x{100}";
4ae52e81 699####
2d5b99ed
FC
700# Latin-1 chars
701# TODO ? ord("A") != 65 && "EBCDIC"
702my $baz = "B\366\x{100}";
703my $bba = qr/B\366\x{100}/;
704####
507a68aa 705# s///e
4ae52e81 706s/x/'y';/e;
ef90d20a
FC
707s/x/$a;/e;
708s/x/complex_expression();/e;
241416b8 709####
507a68aa 710# block
241416b8
DM
711{ my $x; }
712####
507a68aa 713# while 1
241416b8
DM
714while (1) { my $k; }
715####
507a68aa 716# trailing for
241416b8
DM
717my ($x,@a);
718$x=1 for @a;
719>>>>
720my($x, @a);
0bb5f065 721$x = 1 foreach (@a);
241416b8 722####
507a68aa 723# 2 arguments in a 3 argument for
241416b8
DM
724for (my $i = 0; $i < 2;) {
725 my $z = 1;
726}
727####
507a68aa 728# 3 argument for
241416b8
DM
729for (my $i = 0; $i < 2; ++$i) {
730 my $z = 1;
731}
732####
507a68aa 733# 3 argument for again
241416b8
DM
734for (my $i = 0; $i < 2; ++$i) {
735 my $z = 1;
736}
737####
22584011
FC
738# 3-argument for with inverted condition
739for (my $i; not $i;) {
740 die;
741}
742for (my $i; not $i; ++$i) {
743 die;
744}
88a758b5
FC
745for (my $a; not +($1 || 2) ** 2;) {
746 die;
747}
22584011
FC
748Something_to_put_the_loop_in_void_context();
749####
507a68aa 750# while/continue
241416b8
DM
751my $i;
752while ($i) { my $z = 1; } continue { $i = 99; }
753####
507a68aa 754# foreach with my
09d856fb 755foreach my $i (1, 2) {
241416b8
DM
756 my $z = 1;
757}
758####
4da9a2ca
FC
759# OPTIONS -p
760# foreach with my under -p
761foreach my $i (1) {
762 die;
763}
764####
507a68aa 765# foreach
241416b8
DM
766my $i;
767foreach $i (1, 2) {
768 my $z = 1;
769}
770####
507a68aa 771# foreach, 2 mys
241416b8
DM
772my $i;
773foreach my $i (1, 2) {
774 my $z = 1;
775}
776####
507a68aa 777# foreach with our
241416b8
DM
778foreach our $i (1, 2) {
779 my $z = 1;
780}
781####
507a68aa 782# foreach with my and our
241416b8
DM
783my $i;
784foreach our $i (1, 2) {
785 my $z = 1;
786}
3ac6e0f9 787####
bcff4148
FC
788# foreach with state
789# CONTEXT use feature "state";
790foreach state $i (1, 2) {
791 state $z = 1;
792}
793####
bba4f5ff
FC
794# foreach with sub call
795foreach $_ (hcaerof()) {
796 ();
797}
798####
507a68aa 799# reverse sort
3ac6e0f9
RGS
800my @x;
801print reverse sort(@x);
802####
507a68aa 803# sort with cmp
3ac6e0f9
RGS
804my @x;
805print((sort {$b cmp $a} @x));
806####
507a68aa 807# reverse sort with block
3ac6e0f9
RGS
808my @x;
809print((reverse sort {$b <=> $a} @x));
36d57d93 810####
507a68aa 811# foreach reverse
36d57d93
RGS
812our @a;
813print $_ foreach (reverse @a);
aae53c41 814####
507a68aa 815# foreach reverse (not inplace)
aae53c41
RGS
816our @a;
817print $_ foreach (reverse 1, 2..5);
f86ea535 818####
507a68aa 819# bug #38684
f86ea535
SM
820our @ary;
821@ary = split(' ', 'foo', 0);
31c6271a 822####
5012eebe
DM
823my @ary;
824@ary = split(' ', 'foo', 0);
825####
de183bbb
FC
826# Split to our array
827our @array = split(//, 'foo', 0);
828####
ef7999f1
FC
829# Split to my array
830my @array = split(//, 'foo', 0);
831####
5012eebe
DM
832our @array;
833my $c;
834@array = split(/x(?{ $c++; })y/, 'foo', 0);
835####
836my($x, $y, $p);
837our $c;
838($x, $y) = split(/$p(?{ $c++; })y/, 'foo', 2);
839####
840our @ary;
841my $pat;
842@ary = split(/$pat/, 'foo', 0);
843####
844my @ary;
845our $pat;
846@ary = split(/$pat/, 'foo', 0);
847####
848our @array;
849my $pat;
850local @array = split(/$pat/, 'foo', 0);
851####
852our $pat;
853my @array = split(/$pat/, 'foo', 0);
854####
507a68aa 855# bug #40055
31c6271a
RD
856do { () };
857####
507a68aa 858# bug #40055
31c6271a 859do { my $x = 1; $x };
d9002312 860####
507a68aa 861# <20061012113037.GJ25805@c4.convolution.nl>
d9002312
SM
862my $f = sub {
863 +{[]};
864} ;
8b2d6640 865####
507a68aa 866# bug #43010
8b2d6640
FC
867'!@$%'->();
868####
507a68aa 869# bug #43010
8b2d6640
FC
870::();
871####
507a68aa 872# bug #43010
8b2d6640
FC
873'::::'->();
874####
507a68aa 875# bug #43010
8b2d6640 876&::::;
09d856fb 877####
1b38d782
FC
878# [perl #77172]
879package rt77172;
880sub foo {} foo & & & foo;
881>>>>
882package rt77172;
883foo(&{&} & foo());
884####
507a68aa 885# variables as method names
09d856fb
CK
886my $bar;
887'Foo'->$bar('orz');
35a99a08 888'Foo'->$bar('orz') = 'a stranger stranger than before';
09d856fb 889####
507a68aa 890# constants as method names
09d856fb
CK
891'Foo'->bar('orz');
892####
507a68aa 893# constants as method names without ()
09d856fb 894'Foo'->bar;
0ced6c29 895####
28bfcb02 896# [perl #47359] "indirect" method call notation
1bf8bbb0
FC
897our @bar;
898foo{@bar}+1,->foo;
899(foo{@bar}+1),foo();
900foo{@bar}1 xor foo();
901>>>>
902our @bar;
903(foo { @bar } 1)->foo;
904(foo { @bar } 1), foo();
905foo { @bar } 1 xor foo();
906####
9d52f6f3
FC
907# indirops with blocks
908# CONTEXT use 5.01;
909print {*STDOUT;} 'foo';
910printf {*STDOUT;} 'foo';
911say {*STDOUT;} 'foo';
912system {'foo';} '-foo';
913exec {'foo';} '-foo';
914####
e9c69003 915# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
205fef88 916# CONTEXT use feature ':5.10';
507a68aa 917# say
7ddd1a01
NC
918say 'foo';
919####
8f57bb34 920# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
8f57bb34
NC
921# CONTEXT use 5.10.0;
922# say in the context of use 5.10.0
923say 'foo';
924####
925# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
8f57bb34
NC
926# say with use 5.10.0
927use 5.10.0;
928say 'foo';
929>>>>
127ce1cd 930no feature ':all';
8f57bb34
NC
931use feature ':5.10';
932say 'foo';
933####
934# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
935# say with use feature ':5.10';
936use feature ':5.10';
937say 'foo';
938>>>>
939use feature 'say', 'state', 'switch';
940say 'foo';
941####
942# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
8f57bb34
NC
943# CONTEXT use feature ':5.10';
944# say with use 5.10.0 in the context of use feature
945use 5.10.0;
946say 'foo';
947>>>>
127ce1cd 948no feature ':all';
8f57bb34
NC
949use feature ':5.10';
950say 'foo';
951####
952# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
953# CONTEXT use 5.10.0;
954# say with use feature ':5.10' in the context of use 5.10.0
955use feature ':5.10';
956say 'foo';
957>>>>
958say 'foo';
959####
960# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
961# CONTEXT use feature ':5.15';
962# __SUB__
963__SUB__;
964####
965# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
8f57bb34
NC
966# CONTEXT use 5.15.0;
967# __SUB__ in the context of use 5.15.0
968__SUB__;
969####
970# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
8f57bb34
NC
971# __SUB__ with use 5.15.0
972use 5.15.0;
973__SUB__;
974>>>>
127ce1cd 975no feature ':all';
8f57bb34
NC
976use feature ':5.16';
977__SUB__;
978####
979# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
980# __SUB__ with use feature ':5.15';
981use feature ':5.15';
982__SUB__;
983>>>>
984use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
985__SUB__;
986####
987# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
8f57bb34
NC
988# CONTEXT use feature ':5.15';
989# __SUB__ with use 5.15.0 in the context of use feature
990use 5.15.0;
991__SUB__;
992>>>>
127ce1cd 993no feature ':all';
8f57bb34
NC
994use feature ':5.16';
995__SUB__;
996####
997# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
998# CONTEXT use 5.15.0;
999# __SUB__ with use feature ':5.15' in the context of use 5.15.0
1000use feature ':5.15';
1001__SUB__;
1002>>>>
1003__SUB__;
1004####
e9c69003 1005# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
205fef88 1006# CONTEXT use feature ':5.10';
507a68aa 1007# state vars
0ced6c29
RGS
1008state $x = 42;
1009####
e9c69003 1010# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
205fef88 1011# CONTEXT use feature ':5.10';
507a68aa 1012# state var assignment
7ddd1a01
NC
1013{
1014 my $y = (state $x = 42);
1015}
1016####
e9c69003 1017# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
205fef88 1018# CONTEXT use feature ':5.10';
c4a6f826 1019# state vars in anonymous subroutines
7ddd1a01
NC
1020$a = sub {
1021 state $x;
1022 return $x++;
1023}
1024;
644741fd
NC
1025####
1026# SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
507a68aa 1027# each @array;
644741fd
NC
1028each @ARGV;
1029each @$a;
1030####
1031# SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
507a68aa 1032# keys @array; values @array
644741fd
NC
1033keys @$a if keys @ARGV;
1034values @ARGV if values @$a;
35925e80 1035####
507a68aa 1036# Anonymous arrays and hashes, and references to them
35925e80
RGS
1037my $a = {};
1038my $b = \{};
1039my $c = [];
1040my $d = \[];
9210de83 1041####
7896dde7 1042# SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
0f539b13 1043# CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
7896dde7 1044# implicit smartmatch in given/when
9210de83 1045given ('foo') {
7896dde7
Z
1046 when ('bar') { continue; }
1047 when ($_ ~~ 'quux') { continue; }
1048 default { 0; }
9210de83 1049}
7ecdd211 1050####
507a68aa 1051# conditions in elsifs (regression in change #33710 which fixed bug #37302)
7ecdd211
PJ
1052if ($a) { x(); }
1053elsif ($b) { x(); }
1054elsif ($a and $b) { x(); }
1055elsif ($a or $b) { x(); }
1056else { x(); }
03b22f1b 1057####
507a68aa 1058# interpolation in regexps
03b22f1b
RGS
1059my($y, $t);
1060/x${y}z$t/;
227375e1 1061####
4a4b8592 1062# TODO new undocumented cpan-bug #33708
507a68aa 1063# cpan-bug #33708
227375e1
RU
1064%{$_ || {}}
1065####
4a4b8592 1066# TODO hash constants not yet fixed
507a68aa 1067# cpan-bug #33708
227375e1
RU
1068use constant H => { "#" => 1 }; H->{"#"}
1069####
4a4b8592 1070# TODO optimized away 0 not yet fixed
507a68aa 1071# cpan-bug #33708
227375e1 1072foreach my $i (@_) { 0 }
edbe35ea 1073####
507a68aa 1074# tests with not, not optimized
07f3cdf5 1075my $c;
edbe35ea
VP
1076x() unless $a;
1077x() if not $a and $b;
1078x() if $a and not $b;
1079x() unless not $a and $b;
1080x() unless $a and not $b;
1081x() if not $a or $b;
1082x() if $a or not $b;
1083x() unless not $a or $b;
1084x() unless $a or not $b;
07f3cdf5
VP
1085x() if $a and not $b and $c;
1086x() if not $a and $b and not $c;
1087x() unless $a and not $b and $c;
1088x() unless not $a and $b and not $c;
1089x() if $a or not $b or $c;
1090x() if not $a or $b or not $c;
1091x() unless $a or not $b or $c;
1092x() unless not $a or $b or not $c;
edbe35ea 1093####
507a68aa 1094# tests with not, optimized
07f3cdf5 1095my $c;
edbe35ea
VP
1096x() if not $a;
1097x() unless not $a;
1098x() if not $a and not $b;
1099x() unless not $a and not $b;
1100x() if not $a or not $b;
1101x() unless not $a or not $b;
07f3cdf5
VP
1102x() if not $a and not $b and $c;
1103x() unless not $a and not $b and $c;
1104x() if not $a or not $b or $c;
1105x() unless not $a or not $b or $c;
1106x() if not $a and not $b and not $c;
1107x() unless not $a and not $b and not $c;
1108x() if not $a or not $b or not $c;
1109x() unless not $a or not $b or not $c;
1110x() unless not $a or not $b or not $c;
edbe35ea 1111>>>>
07f3cdf5 1112my $c;
edbe35ea
VP
1113x() unless $a;
1114x() if $a;
1115x() unless $a or $b;
1116x() if $a or $b;
1117x() unless $a and $b;
07f3cdf5
VP
1118x() if $a and $b;
1119x() if not $a || $b and $c;
1120x() unless not $a || $b and $c;
1121x() if not $a && $b or $c;
1122x() unless not $a && $b or $c;
1123x() unless $a or $b or $c;
1124x() if $a or $b or $c;
1125x() unless $a and $b and $c;
1126x() if $a and $b and $c;
1127x() unless not $a && $b && $c;
71c4dbc3 1128####
507a68aa 1129# tests that should be constant folded
71c4dbc3
VP
1130x() if 1;
1131x() if GLIPP;
1132x() if !GLIPP;
1133x() if GLIPP && GLIPP;
1134x() if !GLIPP || GLIPP;
1135x() if do { GLIPP };
1136x() if do { no warnings 'void'; 5; GLIPP };
1137x() if do { !GLIPP };
1138if (GLIPP) { x() } else { z() }
1139if (!GLIPP) { x() } else { z() }
1140if (GLIPP) { x() } elsif (GLIPP) { z() }
1141if (!GLIPP) { x() } elsif (GLIPP) { z() }
1142if (GLIPP) { x() } elsif (!GLIPP) { z() }
1143if (!GLIPP) { x() } elsif (!GLIPP) { z() }
1144if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
1145if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
1146if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
1147>>>>
1148x();
1149x();
1150'???';
1151x();
1152x();
1153x();
1154x();
1155do {
1156 '???'
1157};
1158do {
1159 x()
1160};
1161do {
1162 z()
1163};
1164do {
1165 x()
1166};
1167do {
1168 z()
1169};
1170do {
1171 x()
1172};
1173'???';
1174do {
1175 t()
1176};
1177'???';
1178!1;
1179####
719c50dc
RGS
1180# TODO constant deparsing has been backed out for 5.12
1181# XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
507a68aa 1182# tests that shouldn't be constant folded
ac0f1413
NC
1183# It might be fundamentally impossible to make this work on ithreads, in which
1184# case the TODO should become a SKIP
71c4dbc3
VP
1185x() if $a;
1186if ($a == 1) { x() } elsif ($b == 2) { z() }
1187if (do { foo(); GLIPP }) { x() }
1188if (do { $a++; GLIPP }) { x() }
1189>>>>
1190x() if $a;
1191if ($a == 1) { x(); } elsif ($b == 2) { z(); }
2990415a
FR
1192if (do { foo(); GLIPP }) { x(); }
1193if (do { ++$a; GLIPP }) { x(); }
1194####
0fa4a265 1195# TODO constant deparsing has been backed out for 5.12
507a68aa 1196# tests for deparsing constants
2990415a
FR
1197warn PI;
1198####
0fa4a265 1199# TODO constant deparsing has been backed out for 5.12
507a68aa 1200# tests for deparsing imported constants
3779476a 1201warn O_TRUNC;
2990415a 1202####
0fa4a265 1203# TODO constant deparsing has been backed out for 5.12
507a68aa 1204# tests for deparsing re-exported constants
2990415a
FR
1205warn O_CREAT;
1206####
0fa4a265 1207# TODO constant deparsing has been backed out for 5.12
507a68aa 1208# tests for deparsing imported constants that got deleted from the original namespace
aaf9c2b2 1209warn O_APPEND;
2990415a 1210####
0fa4a265
DM
1211# TODO constant deparsing has been backed out for 5.12
1212# XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
507a68aa 1213# tests for deparsing constants which got turned into full typeglobs
ac0f1413
NC
1214# It might be fundamentally impossible to make this work on ithreads, in which
1215# case the TODO should become a SKIP
2990415a
FR
1216warn O_EXCL;
1217eval '@Fcntl::O_EXCL = qw/affe tiger/;';
1218warn O_EXCL;
1219####
0fa4a265 1220# TODO constant deparsing has been backed out for 5.12
507a68aa 1221# tests for deparsing of blessed constant with overloaded numification
2990415a 1222warn OVERLOADED_NUMIFICATION;
79289e05 1223####
507a68aa 1224# strict
79289e05 1225no strict;
415d4c68
FC
1226print $x;
1227use strict 'vars';
1228print $main::x;
1229use strict 'subs';
1230print $main::x;
1231use strict 'refs';
1232print $main::x;
1233no strict 'vars';
79289e05
NC
1234$x;
1235####
1236# TODO Subsets of warnings could be encoded textually, rather than as bitflips.
507a68aa 1237# subsets of warnings
79289e05
NC
1238no warnings 'deprecated';
1239my $x;
1240####
1241# TODO Better test for CPAN #33708 - the deparsed code has different behaviour
507a68aa 1242# CPAN #33708
79289e05
NC
1243use strict;
1244no warnings;
1245
1246foreach (0..3) {
1247 my $x = 2;
1248 {
1249 my $x if 0;
1250 print ++$x, "\n";
1251 }
1252}
d83f38d8 1253####
507a68aa 1254# no attribute list
d83f38d8
NC
1255my $pi = 4;
1256####
2dc78664
NC
1257# SKIP ?$] > 5.013006 && ":= is now a syntax error"
1258# := treated as an empty attribute list
d83f38d8
NC
1259no warnings;
1260my $pi := 4;
1261>>>>
1262no warnings;
1263my $pi = 4;
1264####
507a68aa 1265# : = empty attribute list
d83f38d8
NC
1266my $pi : = 4;
1267>>>>
1268my $pi = 4;
689e417f 1269####
507a68aa 1270# in place sort
689e417f
VP
1271our @a;
1272my @b;
1273@a = sort @a;
1274@b = sort @b;
1275();
1276####
507a68aa 1277# in place reverse
689e417f
VP
1278our @a;
1279my @b;
1280@a = reverse @a;
1281@b = reverse @b;
1282();
06fc6867 1283####
507a68aa 1284# #71870 Use of uninitialized value in bitwise and B::Deparse
06fc6867
VP
1285my($r, $s, @a);
1286@a = split(/foo/, $s, 0);
1287$r = qr/foo/;
1288@a = split(/$r/, $s, 0);
1289();
98a1a137 1290####
507a68aa 1291# package declaration before label
98a1a137
Z
1292{
1293 package Foo;
1294 label: print 123;
1295}
538f5756 1296####
507a68aa 1297# shift optimisation
538f5756
RZ
1298shift;
1299>>>>
1300shift();
1301####
507a68aa 1302# shift optimisation
538f5756
RZ
1303shift @_;
1304####
507a68aa 1305# shift optimisation
538f5756
RZ
1306pop;
1307>>>>
1308pop();
1309####
507a68aa 1310# shift optimisation
538f5756 1311pop @_;
a539498a 1312####
507a68aa 1313#[perl #20444]
a539498a
FC
1314"foo" =~ (1 ? /foo/ : /bar/);
1315"foo" =~ (1 ? y/foo// : /bar/);
5e5a1632 1316"foo" =~ (1 ? y/foo//r : /bar/);
a539498a
FC
1317"foo" =~ (1 ? s/foo// : /bar/);
1318>>>>
1319'foo' =~ ($_ =~ /foo/);
1320'foo' =~ ($_ =~ tr/fo//);
5e5a1632 1321'foo' =~ ($_ =~ tr/fo//r);
a539498a 1322'foo' =~ ($_ =~ s/foo//);
e0ab66ad 1323####
5e5a1632
FC
1324# The fix for [perl #20444] broke this.
1325'foo' =~ do { () };
1326####
4b58603b
FC
1327# [perl #81424] match against aelemfast_lex
1328my @s;
1329print /$s[1]/;
1330####
36727b53
FC
1331# /$#a/
1332print /$#main::a/;
1333####
bae5b54e
FC
1334# /@array/
1335our @a;
1336my @b;
1337print /@a/;
1338print /@b/;
1339print qr/@a/;
1340print qr/@b/;
1341####
3b91d897
FC
1342# =~ QR_CONSTANT
1343use constant QR_CONSTANT => qr/a/soupmix;
1344'' =~ QR_CONSTANT;
1345>>>>
1346'' =~ /a/impsux;
1347####
9e32885a
FC
1348# $lexical =~ //
1349my $x;
1350$x =~ //;
1351####
b9bc576f 1352# [perl #91318] /regexp/applaud
09622ee2
FC
1353print /a/a, s/b/c/a;
1354print /a/aa, s/b/c/aa;
1355print /a/p, s/b/c/p;
1356print /a/l, s/b/c/l;
1357print /a/u, s/b/c/u;
b9bc576f
FC
1358{
1359 use feature "unicode_strings";
09622ee2 1360 print /a/d, s/b/c/d;
b9bc576f
FC
1361}
1362{
1363 use re "/u";
09622ee2 1364 print /a/d, s/b/c/d;
b9bc576f 1365}
dff5ffe4
FC
1366{
1367 use 5.012;
1368 print /a/d, s/b/c/d;
1369}
b9bc576f 1370>>>>
09622ee2
FC
1371print /a/a, s/b/c/a;
1372print /a/aa, s/b/c/aa;
1373print /a/p, s/b/c/p;
1374print /a/l, s/b/c/l;
1375print /a/u, s/b/c/u;
b9bc576f 1376{
a8095af7 1377 use feature 'unicode_strings';
09622ee2 1378 print /a/d, s/b/c/d;
b9bc576f
FC
1379}
1380{
0bb01b05
FC
1381 BEGIN { $^H{'reflags'} = '0';
1382 $^H{'reflags_charset'} = '2'; }
09622ee2 1383 print /a/d, s/b/c/d;
b9bc576f 1384}
dff5ffe4 1385{
127ce1cd 1386 no feature ':all';
dff5ffe4
FC
1387 use feature ':5.12';
1388 print /a/d, s/b/c/d;
1389}
b9bc576f 1390####
dc6dfd62
LM
1391# all the flags (qr//)
1392$_ = qr/X/m;
1393$_ = qr/X/s;
1394$_ = qr/X/i;
1395$_ = qr/X/x;
1396$_ = qr/X/p;
1397$_ = qr/X/o;
1398$_ = qr/X/u;
1399$_ = qr/X/a;
1400$_ = qr/X/l;
1401$_ = qr/X/n;
1402####
1403use feature 'unicode_strings';
1404$_ = qr/X/d;
1405####
1406# all the flags (m//)
1407/X/m;
1408/X/s;
1409/X/i;
1410/X/x;
1411/X/p;
1412/X/o;
1413/X/u;
1414/X/a;
1415/X/l;
1416/X/n;
1417/X/g;
1418/X/cg;
1419####
1420use feature 'unicode_strings';
1421/X/d;
1422####
1423# all the flags (s///)
1424s/X//m;
1425s/X//s;
1426s/X//i;
1427s/X//x;
1428s/X//p;
1429s/X//o;
1430s/X//u;
1431s/X//a;
1432s/X//l;
1433s/X//n;
1434s/X//g;
1435s/X/'';/e;
1436s/X//r;
1437####
1438use feature 'unicode_strings';
1439s/X//d;
1440####
1441# all the flags (tr///)
1442tr/X/Y/c;
1443tr/X//d;
1444tr/X//s;
1445tr/X//r;
1446####
c923a699
DM
1447# tr with extended table (/c)
1448tr/\000-\375/AB/c;
1449tr/\000-\375/A-C/c;
1450tr/\000-\375/A-D/c;
1451tr/\000-\375/A-Z/c;
1452tr/\000-\375/AB/cd;
1453tr/\000-\375/A-C/cd;
1454tr/\000-\375/A-D/cd;
1455tr/\000-\375/A-Z/cd;
1456tr/\000-\375/AB/cds;
1457tr/\000-\375/A-C/cds;
1458tr/\000-\375/A-D/cds;
1459tr/\000-\375/A-Z/cds;
1460####
9f125c4a
FC
1461# [perl #119807] s//\(3)/ge should not warn when deparsed (\3 warns)
1462s/foo/\(3);/eg;
1463####
c9fa6ae9 1464# [perl #115256]
c9fa6ae9
FC
1465"" =~ /a(?{ print q|
1466|})/;
1467>>>>
f6b6ee63 1468'' =~ /a(?{ print "\n"; })/;
c9fa6ae9
FC
1469####
1470# [perl #123217]
c9fa6ae9
FC
1471$_ = qr/(??{<<END})/
1472f.o
1473b.r
1474END
1475>>>>
1476$_ = qr/(??{ "f.o\nb.r\n"; })/;
1477####
1478# More regexp code block madness
c9fa6ae9
FC
1479my($b, @a);
1480/(?{ die $b; })/;
1481/a(?{ die $b; })a/;
1482/$a(?{ die $b; })/;
1483/@a(?{ die $b; })/;
1484/(??{ die $b; })/;
1485/a(??{ die $b; })a/;
1486/$a(??{ die $b; })/;
1487/@a(??{ die $b; })/;
1488qr/(?{ die $b; })/;
1489qr/a(?{ die $b; })a/;
1490qr/$a(?{ die $b; })/;
1491qr/@a(?{ die $b; })/;
1492qr/(??{ die $b; })/;
1493qr/a(??{ die $b; })a/;
1494qr/$a(??{ die $b; })/;
1495qr/@a(??{ die $b; })/;
1496s/(?{ die $b; })//;
1497s/a(?{ die $b; })a//;
1498s/$a(?{ die $b; })//;
1499s/@a(?{ die $b; })//;
1500s/(??{ die $b; })//;
1501s/a(??{ die $b; })a//;
1502s/$a(??{ die $b; })//;
1503s/@a(??{ die $b; })//;
1504####
ba0372a0
FC
1505# /(?x)<newline><tab>/
1506/(?x)
1507 /;
1508####
e7afc405 1509# y///r
d52196e1 1510tr/a/b/r + $a =~ tr/p/q/r;
cb8157e3 1511####
12cea2fa
FC
1512# y///d in list [perl #119815]
1513() = tr/a//d;
1514####
cb8578ff 1515# [perl #90898]
f4002a4b 1516<a,>;
18371617
LM
1517glob 'a,';
1518>>>>
1519glob 'a,';
1520glob 'a,';
09dcfa7d
FC
1521####
1522# [perl #91008]
26230909 1523# SKIP ?$] >= 5.023 && "autoderef deleted in this Perl version"
d401967c 1524# CONTEXT no warnings 'experimental::autoderef';
09dcfa7d
FC
1525each $@;
1526keys $~;
1527values $!;
5d8c42c2
FC
1528####
1529# readpipe with complex expression
1530readpipe $a + $b;
93bad3fd
NC
1531####
1532# aelemfast
1533$b::a[0] = 1;
1534####
1535# aelemfast for a lexical
1536my @a;
1537$a[0] = 1;
80e3f4ad
FC
1538####
1539# feature features without feature
0f539b13 1540# CONTEXT no warnings 'experimental::smartmatch';
80e3f4ad 1541CORE::state $x;
223b1722
FC
1542CORE::say $x;
1543CORE::given ($x) {
7896dde7 1544 CORE::when (3) {
223b1722
FC
1545 continue;
1546 }
7896dde7
Z
1547 CORE::default {
1548 CORE::break;
223b1722
FC
1549 }
1550}
1551CORE::evalbytes '';
1552() = CORE::__SUB__;
838f2281 1553() = CORE::fc $x;
223b1722
FC
1554####
1555# feature features when feature has been disabled by use VERSION
0f539b13 1556# CONTEXT no warnings 'experimental::smartmatch';
223b1722
FC
1557use feature (sprintf(":%vd", $^V));
1558use 1;
412989c2 1559CORE::say $_;
223b1722 1560CORE::state $x;
223b1722 1561CORE::given ($x) {
7896dde7 1562 CORE::when (3) {
223b1722
FC
1563 continue;
1564 }
7896dde7
Z
1565 CORE::default {
1566 CORE::break;
223b1722
FC
1567 }
1568}
1569CORE::evalbytes '';
1570() = CORE::__SUB__;
1571>>>>
412989c2 1572CORE::say $_;
205fef88 1573CORE::state $x;
205fef88 1574CORE::given ($x) {
7896dde7 1575 CORE::when (3) {
205fef88
NC
1576 continue;
1577 }
7896dde7
Z
1578 CORE::default {
1579 CORE::break;
205fef88
NC
1580 }
1581}
1582CORE::evalbytes '';
1583() = CORE::__SUB__;
1584####
1585# (the above test with CONTEXT, and the output is equivalent but different)
0f539b13 1586# CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
205fef88
NC
1587# feature features when feature has been disabled by use VERSION
1588use feature (sprintf(":%vd", $^V));
1589use 1;
412989c2 1590CORE::say $_;
205fef88 1591CORE::state $x;
205fef88 1592CORE::given ($x) {
7896dde7 1593 CORE::when (3) {
205fef88
NC
1594 continue;
1595 }
7896dde7
Z
1596 CORE::default {
1597 CORE::break;
205fef88
NC
1598 }
1599}
1600CORE::evalbytes '';
1601() = CORE::__SUB__;
1602>>>>
127ce1cd 1603no feature ':all';
0bb01b05 1604use feature ':default';
412989c2 1605CORE::say $_;
223b1722 1606CORE::state $x;
80e3f4ad 1607CORE::given ($x) {
7896dde7 1608 CORE::when (3) {
80e3f4ad
FC
1609 continue;
1610 }
7896dde7
Z
1611 CORE::default {
1612 CORE::break;
80e3f4ad
FC
1613 }
1614}
7d789282 1615CORE::evalbytes '';
84ed0108 1616() = CORE::__SUB__;
6ec73527 1617####
7741ceed
FC
1618# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1619# lexical subroutines and keywords of the same name
1620# CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental';
7896dde7 1621my sub default;
7741ceed
FC
1622my sub else;
1623my sub elsif;
1624my sub for;
1625my sub foreach;
1626my sub given;
1627my sub if;
1628my sub m;
1629my sub no;
1630my sub package;
1631my sub q;
1632my sub qq;
1633my sub qr;
1634my sub qx;
1635my sub require;
1636my sub s;
1637my sub sub;
1638my sub tr;
1639my sub unless;
1640my sub until;
1641my sub use;
7896dde7 1642my sub when;
7741ceed 1643my sub while;
7896dde7 1644CORE::default { die; }
7741ceed
FC
1645CORE::if ($1) { die; }
1646CORE::if ($1) { die; }
1647CORE::elsif ($1) { die; }
1648CORE::else { die; }
1649CORE::for (die; $1; die) { die; }
1650CORE::foreach $_ (1 .. 10) { die; }
1651die CORE::foreach (1);
1652CORE::given ($1) { die; }
1653CORE::m[/];
1654CORE::m?/?;
1655CORE::package foo;
1656CORE::no strict;
1657() = (CORE::q['], CORE::qq["$_], CORE::qr//, CORE::qx[`]);
1658CORE::require 1;
1659CORE::s///;
1660() = CORE::sub { die; } ;
1661CORE::tr///;
1662CORE::unless ($1) { die; }
1663CORE::until ($1) { die; }
1664die CORE::until $1;
1665CORE::use strict;
7896dde7 1666CORE::when ($1 ~~ $2) { die; }
7741ceed
FC
1667CORE::while ($1) { die; }
1668die CORE::while $1;
1669####
0bb01b05
FC
1670# Feature hints
1671use feature 'current_sub', 'evalbytes';
1672print;
1673use 1;
1674print;
1675use 5.014;
1676print;
1677no feature 'unicode_strings';
1678print;
1679>>>>
a8095af7 1680use feature 'current_sub', 'evalbytes';
0bb01b05 1681print $_;
127ce1cd 1682no feature ':all';
0bb01b05
FC
1683use feature ':default';
1684print $_;
127ce1cd 1685no feature ':all';
0bb01b05
FC
1686use feature ':5.12';
1687print $_;
a8095af7 1688no feature 'unicode_strings';
0bb01b05
FC
1689print $_;
1690####
6ec73527
FC
1691# $#- $#+ $#{%} etc.
1692my @x;
5b6da579 1693@x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
6ec73527
FC
1694@x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
1695@x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
b6bba886 1696@x = ($#{;}, $#{:}, $#{1}), $#_;
61154ac0 1697####
ff683671
NC
1698# ${#} interpolated
1699# It's a known TODO that warnings are deparsed as bits, not textually.
1700no warnings;
61154ac0 1701() = "${#}a";
958ed56b 1702####
337d7381
FC
1703# [perl #86060] $( $| $) in regexps need braces
1704/${(}/;
1705/${|}/;
1706/${)}/;
1707/${(}${|}${)}/;
3f193e55 1708/@{+}@{-}/;
337d7381 1709####
958ed56b
FC
1710# ()[...]
1711my(@a) = ()[()];
521795fe
FC
1712####
1713# sort(foo(bar))
1714# sort(foo(bar)) is interpreted as sort &foo(bar)
1715# sort foo(bar) is interpreted as sort foo bar
1716# parentheses are not optional in this case
1717print sort(foo('bar'));
1718>>>>
1719print sort(foo('bar'));
24fcb59f
FC
1720####
1721# substr assignment
1722substr(my $a, 0, 0) = (foo(), bar());
1723$a++;
04be0204 1724####
d1718a7c
FC
1725# This following line works around an unfixed bug that we are not trying to
1726# test for here:
1727# CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
04be0204
FC
1728# hint hash
1729BEGIN { $^H{'foo'} = undef; }
1730{
1731 BEGIN { $^H{'bar'} = undef; }
1732 {
1733 BEGIN { $^H{'baz'} = undef; }
1734 {
1735 print $_;
1736 }
1737 print $_;
1738 }
1739 print $_;
1740}
035146a3
FC
1741BEGIN { $^H{q[']} = '('; }
1742print $_;
c306e834 1743####
d1718a7c
FC
1744# This following line works around an unfixed bug that we are not trying to
1745# test for here:
1746# CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
c306e834
FC
1747# hint hash changes that serialise the same way with sort %hh
1748BEGIN { $^H{'a'} = 'b'; }
1749{
1750 BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
1751 print $_;
1752}
1753print $_;
94bb57f9
FC
1754####
1755# [perl #47361] do({}) and do +{} (variants of do-file)
1756do({});
1757do +{};
8b46c09b
FC
1758sub foo::do {}
1759package foo;
1760CORE::do({});
1761CORE::do +{};
94bb57f9
FC
1762>>>>
1763do({});
1764do({});
8b46c09b
FC
1765package foo;
1766CORE::do({});
1767CORE::do({});
9c56d9ea
FC
1768####
1769# [perl #77096] functions that do not follow the llafr
1770() = (return 1) + time;
1771() = (return ($1 + $2) * $3) + time;
1772() = (return ($a xor $b)) + time;
1773() = (do 'file') + time;
1774() = (do ($1 + $2) * $3) + time;
1775() = (do ($1 xor $2)) + time;
41df74e3
FC
1776() = (goto 1) + 3;
1777() = (require 'foo') + 3;
1778() = (require foo) + 3;
266da325 1779() = (CORE::dump 1) + 3;
41df74e3
FC
1780() = (last 1) + 3;
1781() = (next 1) + 3;
1782() = (redo 1) + 3;
5830412d
FC
1783() = (-R $_) + 3;
1784() = (-W $_) + 3;
1785() = (-X $_) + 3;
1786() = (-r $_) + 3;
1787() = (-w $_) + 3;
1788() = (-x $_) + 3;
2462c3cc 1789####
917a8f4f
FC
1790# require(foo()) and do(foo())
1791require (foo());
1792do (foo());
df465735
FC
1793goto (foo());
1794CORE::dump (foo());
1795last (foo());
1796next (foo());
1797redo (foo());
917a8f4f 1798####
5e7acd25
FC
1799# require vstring
1800require v5.16;
1801####
1cabb3b3
FC
1802# [perl #97476] not() *does* follow the llafr
1803$_ = ($a xor not +($1 || 2) ** 2);
1804####
4d8ac5c7
FC
1805# Precedence conundrums with argument-less function calls
1806() = (eof) + 1;
1807() = (return) + 1;
1808() = (return, 1);
7bc8c979
FC
1809() = warn;
1810() = warn() + 1;
4d8ac5c7
FC
1811() = setpgrp() + 1;
1812####
1eb0b7be
FC
1813# loopexes have assignment prec
1814() = (CORE::dump a) | 'b';
1815() = (goto a) | 'b';
1816() = (last a) | 'b';
1817() = (next a) | 'b';
1818() = (redo a) | 'b';
1819####
2462c3cc
FC
1820# [perl #63558] open local(*FH)
1821open local *FH;
564cd6cb 1822pipe local *FH, local *FH;
843b15cc 1823####
b89b7257
FC
1824# [perl #91416] open "string"
1825open 'open';
1826open '####';
1827open '^A';
1828open "\ca";
1829>>>>
1830open *open;
1831open '####';
1832open '^A';
1833open *^A;
1834####
be6cf5cf
FC
1835# "string"->[] ->{}
1836no strict 'vars';
1837() = 'open'->[0]; #aelemfast
1838() = '####'->[0];
1839() = '^A'->[0];
1840() = "\ca"->[0];
b861b87f 1841() = 'a::]b'->[0];
10e8e32b
FC
1842() = 'open'->[$_]; #aelem
1843() = '####'->[$_];
1844() = '^A'->[$_];
1845() = "\ca"->[$_];
b861b87f 1846() = 'a::]b'->[$_];
10e8e32b
FC
1847() = 'open'->{0}; #helem
1848() = '####'->{0};
1849() = '^A'->{0};
1850() = "\ca"->{0};
b861b87f 1851() = 'a::]b'->{0};
be6cf5cf 1852>>>>
415d4c68 1853no strict 'vars';
be6cf5cf
FC
1854() = $open[0];
1855() = '####'->[0];
1856() = '^A'->[0];
1857() = $^A[0];
b861b87f 1858() = 'a::]b'->[0];
10e8e32b
FC
1859() = $open[$_];
1860() = '####'->[$_];
1861() = '^A'->[$_];
1862() = $^A[$_];
b861b87f 1863() = 'a::]b'->[$_];
10e8e32b
FC
1864() = $open{'0'};
1865() = '####'->{'0'};
1866() = '^A'->{'0'};
1867() = $^A{'0'};
b861b87f 1868() = 'a::]b'->{'0'};
be6cf5cf 1869####
843b15cc
FC
1870# [perl #74740] -(f()) vs -f()
1871$_ = -(f());
c75b4828
FC
1872####
1873# require <binop>
1874require 'a' . $1;
afb60448
HY
1875####
1876#[perl #30504] foreach-my postfix/prefix difference
1877$_ = 'foo' foreach my ($foo1, $bar1, $baz1);
1878foreach (my ($foo2, $bar2, $baz2)) { $_ = 'foo' }
1879foreach my $i (my ($foo3, $bar3, $baz3)) { $i = 'foo' }
1880>>>>
1881$_ = 'foo' foreach (my($foo1, $bar1, $baz1));
1882foreach $_ (my($foo2, $bar2, $baz2)) {
1883 $_ = 'foo';
1884}
1885foreach my $i (my($foo3, $bar3, $baz3)) {
1886 $i = 'foo';
1887}
1888####
1889#[perl #108224] foreach with continue block
1890foreach (1 .. 3) { print } continue { print "\n" }
1891foreach (1 .. 3) { } continue { }
1892foreach my $i (1 .. 3) { print $i } continue { print "\n" }
1893foreach my $i (1 .. 3) { } continue { }
1894>>>>
1895foreach $_ (1 .. 3) {
1896 print $_;
1897}
1898continue {
1899 print "\n";
1900}
1901foreach $_ (1 .. 3) {
1902 ();
1903}
1904continue {
1905 ();
1906}
1907foreach my $i (1 .. 3) {
1908 print $i;
1909}
1910continue {
1911 print "\n";
1912}
1913foreach my $i (1 .. 3) {
1914 ();
1915}
1916continue {
1917 ();
1918}
bc1cc2c3
DM
1919####
1920# file handles
1921no strict;
1922my $mfh;
1923open F;
1924open *F;
1925open $fh;
1926open $mfh;
1927open 'a+b';
1928select *F;
1929select F;
1930select $f;
1931select $mfh;
1932select 'a+b';
a7fd8ef6
DM
1933####
1934# 'my' works with padrange op
1935my($z, @z);
1936my $m1;
1937$m1 = 1;
1938$z = $m1;
1939my $m2 = 2;
1940my($m3, $m4);
1941($m3, $m4) = (1, 2);
1942@z = ($m3, $m4);
1943my($m5, $m6) = (1, 2);
1944my($m7, undef, $m8) = (1, 2, 3);
1945@z = ($m7, undef, $m8);
1946($m7, undef, $m8) = (1, 2, 3);
1947####
1948# 'our/local' works with padrange op
a7fd8ef6
DM
1949our($z, @z);
1950our $o1;
0298c760 1951no strict;
a7fd8ef6
DM
1952local $o11;
1953$o1 = 1;
1954local $o1 = 1;
1955$z = $o1;
1956$z = local $o1;
1957our $o2 = 2;
1958our($o3, $o4);
1959($o3, $o4) = (1, 2);
1960local($o3, $o4) = (1, 2);
1961@z = ($o3, $o4);
1962@z = local($o3, $o4);
1963our($o5, $o6) = (1, 2);
1964our($o7, undef, $o8) = (1, 2, 3);
1965@z = ($o7, undef, $o8);
1966@z = local($o7, undef, $o8);
1967($o7, undef, $o8) = (1, 2, 3);
1968local($o7, undef, $o8) = (1, 2, 3);
1969####
1970# 'state' works with padrange op
412989c2 1971# CONTEXT no strict; use feature 'state';
a7fd8ef6
DM
1972state($z, @z);
1973state $s1;
1974$s1 = 1;
1975$z = $s1;
1976state $s2 = 2;
1977state($s3, $s4);
1978($s3, $s4) = (1, 2);
1979@z = ($s3, $s4);
1980# assignment of state lists isn't implemented yet
1981#state($s5, $s6) = (1, 2);
1982#state($s7, undef, $s8) = (1, 2, 3);
1983#@z = ($s7, undef, $s8);
1984($s7, undef, $s8) = (1, 2, 3);
1985####
df2b00e8 1986# anon arrays with padrange
a7fd8ef6
DM
1987my($a, $b);
1988my $c = [$a, $b];
1989my $d = {$a, $b};
1990####
1991# slices with padrange
1992my($a, $b);
1993my(@x, %y);
1994@x = @x[$a, $b];
1995@x = @y{$a, $b};
1996####
1997# binops with padrange
1998my($a, $b, $c);
1999$c = $a cmp $b;
2000$c = $a + $b;
2001$a += $b;
2002$c = $a - $b;
2003$a -= $b;
2004$c = my $a1 cmp $b;
2005$c = my $a2 + $b;
2006$a += my $b1;
2007$c = my $a3 - $b;
2008$a -= my $b2;
2009####
2010# 'x' with padrange
2011my($a, $b, $c, $d, @e);
2012$c = $a x $b;
2013$a x= $b;
2014@e = ($a) x $d;
2015@e = ($a, $b) x $d;
2016@e = ($a, $b, $c) x $d;
2017@e = ($a, 1) x $d;
d5524600
DM
2018####
2019# @_ with padrange
2020my($a, $b, $c) = @_;
ce4062e7
AC
2021####
2022# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
ce4062e7 2023# lexical subroutine
db629560 2024# CONTEXT use feature 'lexical_subs';
601448c3 2025no warnings "experimental::lexical_subs";
ce4062e7
AC
2026my sub f {}
2027print f();
d4f1bfe7 2028>>>>
0d76344b 2029BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"}
d4f1bfe7 2030my sub f {
d4f1bfe7
FC
2031
2032}
d4f1bfe7 2033print f();
f0cf3754
AC
2034####
2035# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
f0cf3754 2036# lexical "state" subroutine
db629560 2037# CONTEXT use feature 'state', 'lexical_subs';
f0cf3754
AC
2038no warnings 'experimental::lexical_subs';
2039state sub f {}
2040print f();
d4f1bfe7 2041>>>>
0d76344b 2042BEGIN {${^WARNING_BITS} = "\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55\x55"}
db629560 2043state sub f {
d4f1bfe7
FC
2044
2045}
d4f1bfe7 2046print f();
bcbe2b27 2047####
8443930e 2048# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
8443930e
FC
2049# lexical subroutine scoping
2050# CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
2051{
2052 {
2053 my sub a { die; }
2054 {
2055 foo();
2056 my sub b;
bb9bfaa4 2057 b ;
8443930e 2058 main::b();
d49c3562
FC
2059 &main::b;
2060 &main::b();
2061 my $b = \&main::b;
2062 sub b { $b; }
8443930e
FC
2063 }
2064 }
2065 b();
2066}
2067####
bb9bfaa4
FC
2068# self-referential lexical subroutine
2069# CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
2070();
2071state sub sb2;
2072sub sb2 {
2073 sb2 ;
2074}
2075####
494a4b9c
FC
2076# lexical subroutine with outer declaration and inner definition
2077# CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
2078();
2079my sub f;
2080my sub g {
2081 ();
2082 sub f { }
2083}
2084####
2c5ddcd3
FC
2085# TODO only partially fixed
2086# lexical state subroutine with outer declaration and inner definition
2087# CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
2088();
2089state sub sb4;
2090state sub a {
2091 ();
2092 sub sb4 { }
2093}
2094state sub sb5;
2095sub {
2096 ();
2097 sub sb5 { }
2098} ;
2099####
bcbe2b27
FC
2100# Elements of %# should not be confused with $#{ array }
2101() = ${#}{'foo'};
c4cf781e 2102####
cfd916dd 2103# $; [perl #123357]
ddb55548
FC
2104$_ = $;;
2105do {
2106 $;
2107};
2108####
c65b7c4d
FC
2109# Ampersand calls and scalar context
2110# OPTIONS -P
2111package prototest;
2112sub foo($$);
2113foo(bar(),baz());
2114>>>>
2115package prototest;
2116&foo(scalar bar(), scalar baz());
2117####
de4fa237
FC
2118# coderef2text and prototyped sub calls [perl #123435]
2119is 'foo', 'oo';
2120####
fd8be4a1
FC
2121# prototypes with unary precedence
2122package prototest;
2123sub dollar($) {}
2124sub optdollar(;$) {}
2125sub optoptdollar(;;$) {}
2126sub splat(*) {}
2127sub optsplat(;*) {}
2128sub optoptsplat(;;*) {}
2129sub bar(_) {}
2130sub optbar(;_) {}
2131sub optoptbar(;;_) {}
2132sub plus(+) {}
2133sub optplus(;+) {}
2134sub optoptplus(;;+) {}
2135sub wack(\$) {}
2136sub optwack(;\$) {}
2137sub optoptwack(;;\$) {}
2138sub wackbrack(\[$]) {}
2139sub optwackbrack(;\[$]) {}
2140sub optoptwackbrack(;;\[$]) {}
2141dollar($a < $b);
2142optdollar($a < $b);
2143optoptdollar($a < $b);
2144splat($a < $b); # Some of these deparse with ‘&’; if that changes, just
2145optsplat($a < $b); # change the tests.
2146optoptsplat($a < $b);
2147bar($a < $b);
2148optbar($a < $b);
2149optoptbar($a < $b);
2150plus($a < $b);
2151optplus($a < $b);
2152optoptplus($a < $b);
2153wack($a = $b);
2154optwack($a = $b);
2155optoptwack($a = $b);
2156wackbrack($a = $b);
2157optwackbrack($a = $b);
2158optoptwackbrack($a = $b);
2159>>>>
2160package prototest;
2161dollar($a < $b);
2162optdollar($a < $b);
2163optoptdollar($a < $b);
2164&splat($a < $b);
2165&optsplat($a < $b);
2166&optoptsplat($a < $b);
2167bar($a < $b);
2168optbar($a < $b);
2169optoptbar($a < $b);
2170&plus($a < $b);
2171&optplus($a < $b);
2172&optoptplus($a < $b);
2173&wack(\($a = $b));
2174&optwack(\($a = $b));
2175&optoptwack(\($a = $b));
2176&wackbrack(\($a = $b));
2177&optwackbrack(\($a = $b));
2178&optoptwackbrack(\($a = $b));
2179####
b024352e
DM
2180# ensure aelemfast works in the range -128..127 and that there's no
2181# funky edge cases
2182my $x;
2183no strict 'vars';
2184$x = $a[-256] + $a[-255] + $a[-129] + $a[-128] + $a[-127] + $a[-1] + $a[0];
2185$x = $a[1] + $a[126] + $a[127] + $a[128] + $a[255] + $a[256];
2186my @b;
2187$x = $b[-256] + $b[-255] + $b[-129] + $b[-128] + $b[-127] + $b[-1] + $b[0];
2188$x = $b[1] + $b[126] + $b[127] + $b[128] + $b[255] + $b[256];
e09d73a6
DIM
2189####
2190# 'm' must be preserved in m??
2191m??;
c8ec376c
FC
2192####
2193# \(@array) and \(..., (@array), ...)
2194my(@array, %hash, @a, @b, %c, %d);
2195() = \(@array);
2196() = \(%hash);
2197() = \(@a, (@b), (%c), %d);
2198() = \(@Foo::array);
2199() = \(%Foo::hash);
2200() = \(@Foo::a, (@Foo::b), (%Foo::c), %Foo::d);
a958cfbb
FC
2201####
2202# subs synonymous with keywords
2203main::our();
2204main::pop();
2205state();
2206use feature 'state';
2207main::state();
9187b6e4
FC
2208####
2209# lvalue references
baabe3fb 2210# CONTEXT use feature "state", 'refaliasing', 'lexical_subs'; no warnings 'experimental';
9187b6e4
FC
2211our $x;
2212\$x = \$x;
2213my $m;
2214\$m = \$x;
2215\my $n = \$x;
2216(\$x) = @_;
2217\($x) = @_;
2218\($m) = @_;
2219(\$m) = @_;
2220\my($p) = @_;
2221(\my $r) = @_;
2222\($x, my $a) = @{[\$x, \$x]};
2223(\$x, \my $b) = @{[\$x, \$x]};
2224\local $x = \3;
2225\local($x) = \3;
2226\state $c = \3;
2227\state($d) = \3;
2228\our $e = \3;
2229\our($f) = \3;
2230\$_[0] = foo();
2231\($_[1]) = foo();
2232my @a;
2233\$a[0] = foo();
2234\($a[1]) = foo();
2235\local($a[1]) = foo();
2236\@a[0,1] = foo();
2237\(@a[2,3]) = foo();
2238\local @a[0,1] = (\$a)x2;
2239\$_{a} = foo();
2240\($_{b}) = foo();
2241my %h;
2242\$h{a} = foo();
2243\($h{b}) = foo();
2244\local $h{a} = \$x;
2245\local($h{b}) = \$x;
2246\@h{'a','b'} = foo();
2247\(@h{2,3}) = foo();
2248\local @h{'a','b'} = (\$x)x2;
2249\@_ = foo();
2250\@a = foo();
2251(\@_) = foo();
2252(\@a) = foo();
2253\my @c = foo();
2254(\my @d) = foo();
2255\(@_) = foo();
2256\(@a) = foo();
2257\my(@g) = foo();
2258\local @_ = \@_;
2259(\local @_) = \@_;
2260\state @e = [1..3];
2261\state(@f) = \3;
2262\our @i = [1..3];
2263\our(@h) = \3;
2264\%_ = foo();
2265\%h = foo();
2266(\%_) = foo();
2267(\%h) = foo();
2268\my %c = foo();
2269(\my %d) = foo();
2270\local %_ = \%h;
2271(\local %_) = \%h;
2272\state %y = {1,2};
2273\our %z = {1,2};
2274(\our %zz) = {1,2};
2275\&a = foo();
2276(\&a) = foo();
2277\(&a) = foo();
2278{
2279 my sub a;
2280 \&a = foo();
2281 (\&a) = foo();
2282 \(&a) = foo();
2283}
2284(\$_, $_) = \(1, 2);
2285$_ == 3 ? \$_ : $_ = \3;
2286$_ == 3 ? \$_ : \$x = \3;
2287\($_ == 3 ? $_ : $x) = \3;
2288for \my $topic (\$1, \$2) {
2289 die;
2290}
2291for \state $topic (\$1, \$2) {
2292 die;
2293}
2294for \our $topic (\$1, \$2) {
2295 die;
2296}
2297for \$_ (\$1, \$2) {
2298 die;
2299}
2300for \my @a ([1,2], [3,4]) {
2301 die;
2302}
2303for \state @a ([1,2], [3,4]) {
2304 die;
2305}
2306for \our @a ([1,2], [3,4]) {
2307 die;
2308}
2309for \@_ ([1,2], [3,4]) {
2310 die;
2311}
2312for \my %a ({5,6}, {7,8}) {
2313 die;
2314}
2315for \our %a ({5,6}, {7,8}) {
2316 die;
2317}
2318for \state %a ({5,6}, {7,8}) {
2319 die;
2320}
2321for \%_ ({5,6}, {7,8}) {
2322 die;
2323}
2324{
2325 my sub a;
2326 for \&a (sub { 9; }, sub { 10; }) {
2327 die;
2328 }
2329}
2330for \&a (sub { 9; }, sub { 10; }) {
2331 die;
2332}
2333>>>>
2334our $x;
2335\$x = \$x;
2336my $m;
2337\$m = \$x;
2338\my $n = \$x;
2339(\$x) = @_;
2340(\$x) = @_;
2341(\$m) = @_;
2342(\$m) = @_;
2343(\my $p) = @_;
2344(\my $r) = @_;
2345(\$x, \my $a) = @{[\$x, \$x];};
2346(\$x, \my $b) = @{[\$x, \$x];};
2347\local $x = \3;
2348(\local $x) = \3;
2349\state $c = \3;
2350(\state $d) = \3;
2351\our $e = \3;
2352(\our $f) = \3;
2353\$_[0] = foo();
2354(\$_[1]) = foo();
2355my @a;
2356\$a[0] = foo();
2357(\$a[1]) = foo();
2358(\local $a[1]) = foo();
2359(\@a[0, 1]) = foo();
2360(\@a[2, 3]) = foo();
2361(\local @a[0, 1]) = (\$a) x 2;
2362\$_{'a'} = foo();
2363(\$_{'b'}) = foo();
2364my %h;
2365\$h{'a'} = foo();
2366(\$h{'b'}) = foo();
2367\local $h{'a'} = \$x;
2368(\local $h{'b'}) = \$x;
2369(\@h{'a', 'b'}) = foo();
2370(\@h{2, 3}) = foo();
2371(\local @h{'a', 'b'}) = (\$x) x 2;
2372\@_ = foo();
2373\@a = foo();
2374(\@_) = foo();
2375(\@a) = foo();
2376\my @c = foo();
2377(\my @d) = foo();
2378(\(@_)) = foo();
2379(\(@a)) = foo();
2380(\(my @g)) = foo();
2381\local @_ = \@_;
2382(\local @_) = \@_;
2383\state @e = [1..3];
2384(\(state @f)) = \3;
2385\our @i = [1..3];
2386(\(our @h)) = \3;
2387\%_ = foo();
2388\%h = foo();
2389(\%_) = foo();
2390(\%h) = foo();
2391\my %c = foo();
2392(\my %d) = foo();
2393\local %_ = \%h;
2394(\local %_) = \%h;
2395\state %y = {1, 2};
2396\our %z = {1, 2};
2397(\our %zz) = {1, 2};
2398\&a = foo();
2399(\&a) = foo();
2400(\&a) = foo();
2401{
2402 my sub a;
2403 \&a = foo();
2404 (\&a) = foo();
2405 (\&a) = foo();
2406}
2407(\$_, $_) = \(1, 2);
2408$_ == 3 ? \$_ : $_ = \3;
2409$_ == 3 ? \$_ : \$x = \3;
2410($_ == 3 ? \$_ : \$x) = \3;
2411foreach \my $topic (\$1, \$2) {
2412 die;
2413}
2414foreach \state $topic (\$1, \$2) {
2415 die;
2416}
2417foreach \our $topic (\$1, \$2) {
2418 die;
2419}
2420foreach \$_ (\$1, \$2) {
2421 die;
2422}
2423foreach \my @a ([1, 2], [3, 4]) {
2424 die;
2425}
2426foreach \state @a ([1, 2], [3, 4]) {
2427 die;
2428}
2429foreach \our @a ([1, 2], [3, 4]) {
2430 die;
2431}
2432foreach \@_ ([1, 2], [3, 4]) {
2433 die;
2434}
2435foreach \my %a ({5, 6}, {7, 8}) {
2436 die;
2437}
2438foreach \our %a ({5, 6}, {7, 8}) {
2439 die;
2440}
2441foreach \state %a ({5, 6}, {7, 8}) {
2442 die;
2443}
2444foreach \%_ ({5, 6}, {7, 8}) {
2445 die;
2446}
2447{
2448 my sub a;
2449 foreach \&a (sub { 9; } , sub { 10; } ) {
2450 die;
2451 }
2452}
2453foreach \&a (sub { 9; } , sub { 10; } ) {
2454 die;
2455}
3b4e2a4d
FC
2456####
2457# join $foo, pos
2458my $foo;
2459$_ = join $foo, pos
2460>>>>
2461my $foo;
2462$_ = join('???', pos $_);
fedf30e1
DM
2463####
2464# exists $a[0]
2465our @a;
2466exists $a[0];
2467####
2468# my @a; exists $a[0]
2469my @a;
2470exists $a[0];
2471####
2472# delete $a[0]
2473our @a;
2474delete $a[0];
2475####
2476# my @a; delete $a[0]
2477my @a;
2478delete $a[0];
2479####
2480# $_[0][$_[1]]
2481$_[0][$_[1]];
2482####
2483# f($a[0]);
2484my @a;
2485f($a[0]);
2486####
2487#qr/\Q$h{'key'}\E/;
2488my %h;
2489qr/\Q$h{'key'}\E/;
2490####
2491# my $x = "$h{foo}";
2492my %h;
2493my $x = "$h{'foo'}";
2494####
2495# weird constant hash key
2496my %h;
2497my $x = $h{"\000\t\x{100}"};
2498####
2499# multideref and packages
2500package foo;
2501my(%bar) = ('a', 'b');
2502our(@bar) = (1, 2);
2503$bar{'k'} = $bar[200];
2504$main::bar{'k'} = $main::bar[200];
2505$foo::bar{'k'} = $foo::bar[200];
2506package foo2;
2507$bar{'k'} = $bar[200];
2508$main::bar{'k'} = $main::bar[200];
2509$foo::bar{'k'} = $foo::bar[200];
2510>>>>
2511package foo;
2512my(%bar) = ('a', 'b');
2513our(@bar) = (1, 2);
2514$bar{'k'} = $bar[200];
2515$main::bar{'k'} = $main::bar[200];
2516$foo::bar{'k'} = $bar[200];
2517package foo2;
2518$bar{'k'} = $foo::bar[200];
2519$main::bar{'k'} = $main::bar[200];
2520$foo::bar{'k'} = $foo::bar[200];
2521####
2522# multideref and local
2523my %h;
2524local $h{'foo'}[0] = 1;
2525####
2526# multideref and exists
2527my(%h, $i);
2528my $e = exists $h{'foo'}[$i];
2529####
2530# multideref and delete
2531my(%h, $i);
2532my $e = delete $h{'foo'}[$i];
2533####
2534# multideref with leading expression
2535my $r;
9527dbdd 2536my $x = +($r // [])->{'foo'}[0];
fedf30e1
DM
2537####
2538# multideref with complex middle index
2539my(%h, $i, $j, $k);
2540my $x = $h{'foo'}[$i + $j]{$k};
0175f038 2541####
9527dbdd
DM
2542# multideref with trailing non-simple index that initially looks simple
2543# (i.e. the constant "3")
2544my($r, $i, $j, $k);
2545my $x = +($r || {})->{'foo'}[$i + $j]{3 + $k};
2546####
3c4a43a5
FC
2547# chdir
2548chdir 'file';
0175f038 2549chdir FH;
3c4a43a5 2550chdir;
27f31adf
FC
2551####
2552# 5.22 bitops
2553# CONTEXT use feature "bitwise"; no warnings "experimental::bitwise";
2554$_ = $_ | $_;
2555$_ = $_ & $_;
2556$_ = $_ ^ $_;
2557$_ = ~$_;
2558$_ = $_ |. $_;
2559$_ = $_ &. $_;
2560$_ = $_ ^. $_;
2561$_ = ~.$_;
2562$_ |= $_;
2563$_ &= $_;
2564$_ ^= $_;
2565$_ |.= $_;
2566$_ &.= $_;
2567$_ ^.= $_;
60f638af
DM
2568####
2569####
2570# Should really use 'no warnings "experimental::signatures"',
2571# but it doesn't yet deparse correctly.
2572# anon subs used because this test framework doesn't deparse named subs
2573# in the DATA code snippets.
2574#
2575# general signature
2576no warnings;
2577use feature 'signatures';
2578my $x;
2579sub ($a, $, $b = $glo::bal, $c = $a, $d = 'foo', $e = -37, $f = 0, $g = 1, $h = undef, $i = $a + 1, $j = /foo/, @) {
2580 $x++;
2581}
2582;
2583$x++;
2584####
2585# Signature and prototype
2586no warnings;
2587use feature 'signatures';
2588my $x;
894f226e 2589my $f = sub : prototype($$) ($a, $b) {
60f638af
DM
2590 $x++;
2591}
2592;
2593$x++;
2594####
2595# Signature and prototype and attrs
2596no warnings;
2597use feature 'signatures';
2598my $x;
894f226e 2599my $f = sub : prototype($$) lvalue ($a, $b) {
60f638af
DM
2600 $x++;
2601}
2602;
2603$x++;
2604####
2605# Signature and attrs
2606no warnings;
2607use feature 'signatures';
2608my $x;
894f226e 2609my $f = sub : lvalue method ($a, $b) {
60f638af
DM
2610 $x++;
2611}
2612;
2613$x++;
2614####
2615# named array slurp, null body
2616no warnings;
2617use feature 'signatures';
2618sub (@a) {
2619 ;
2620}
2621;
2622####
2623# named hash slurp
2624no warnings;
2625use feature 'signatures';
2626sub ($key, %h) {
2627 $h{$key};
2628}
2629;
2630####
2631# anon hash slurp
2632no warnings;
2633use feature 'signatures';
2634sub ($a, %) {
2635 $a;
2636}
2637;
2638####
2639# parenthesised default arg
2640no warnings;
2641use feature 'signatures';
2642sub ($a, $b = (/foo/), $c = 1) {
2643 $a + $b + $c;
2644}
2645;
2646####
2647# parenthesised default arg with TARGMY
2648no warnings;
2649use feature 'signatures';
2650sub ($a, $b = ($a + 1), $c = 1) {
2651 $a + $b + $c;
2652}
2653;
2654####
2655# empty default
2656no warnings;
2657use feature 'signatures';
2658sub ($a, $=) {
2659 $a;
2660}
2661;
b814db67
DM
2662####
2663# padrange op within pattern code blocks
2664/(?{ my($x, $y) = (); })/;
2665my $a;
2666/$a(?{ my($x, $y) = (); })/;
2667my $r1 = qr/(?{ my($x, $y) = (); })/;
2668my $r2 = qr/$a(?{ my($x, $y) = (); })/;
4d7ac81a
DM
2669####
2670# don't remove pattern whitespace escapes
2671/a\ b/;
2672/a\ b/x;
2673/a\ b/;
2674/a\ b/x;
82ab48fa
DM
2675####
2676# my attributes
2677my $s1 :foo(f1, f2) bar(b1, b2);
2678my @a1 :foo(f1, f2) bar(b1, b2);
2679my %h1 :foo(f1, f2) bar(b1, b2);
2680my($s2, @a2, %h2) :foo(f1, f2) bar(b1, b2);
2681####
2682# my class attributes
2683package Foo::Bar;
2684my Foo::Bar $s1 :foo(f1, f2) bar(b1, b2);
2685my Foo::Bar @a1 :foo(f1, f2) bar(b1, b2);
2686my Foo::Bar %h1 :foo(f1, f2) bar(b1, b2);
2687my Foo::Bar ($s2, @a2, %h2) :foo(f1, f2) bar(b1, b2);
2688package main;
2689my Foo::Bar $s3 :foo(f1, f2) bar(b1, b2);
2690my Foo::Bar @a3 :foo(f1, f2) bar(b1, b2);
2691my Foo::Bar %h3 :foo(f1, f2) bar(b1, b2);
2692my Foo::Bar ($s4, @a4, %h4) :foo(f1, f2) bar(b1, b2);
2693####
2694# avoid false positives in my $x :attribute
2695'attributes'->import('main', \my $x1, 'foo(bar)'), my $y1;
2696'attributes'->import('Fooo', \my $x2, 'foo(bar)'), my $y2;
ac1e5644
DM
2697####
2698# hash slices and hash key/value slices
2699my(@a, %h);
2700our(@oa, %oh);
2701@a = @h{'foo', 'bar'};
2702@a = %h{'foo', 'bar'};
2703@a = delete @h{'foo', 'bar'};
2704@a = delete %h{'foo', 'bar'};
2705@oa = @oh{'foo', 'bar'};
2706@oa = %oh{'foo', 'bar'};
2707@oa = delete @oh{'foo', 'bar'};
2708@oa = delete %oh{'foo', 'bar'};
748f2c65
DM
2709####
2710# keys optimised away in void and scalar context
2711no warnings;
2712;
2713our %h1;
2714my($x, %h2);
2715%h1;
2716keys %h1;
2717$x = %h1;
2718$x = keys %h1;
2719%h2;
2720keys %h2;
2721$x = %h2;
2722$x = keys %h2;
7e8d786b
DM
2723####
2724# eq,const optimised away for (index() == -1)
2725my($a, $b);
2726our $c;
2727$c = index($a, $b) == 2;
2728$c = rindex($a, $b) == 2;
2729$c = index($a, $b) == -1;
2730$c = rindex($a, $b) == -1;
2731$c = index($a, $b) != -1;
2732$c = rindex($a, $b) != -1;
2733$c = (index($a, $b) == -1);
2734$c = (rindex($a, $b) == -1);
2735$c = (index($a, $b) != -1);
2736$c = (rindex($a, $b) != -1);
2737####
2738# eq,const,sassign,madmy optimised away for (index() == -1)
2739my($a, $b);
2740my $c;
2741$c = index($a, $b) == 2;
2742$c = rindex($a, $b) == 2;
2743$c = index($a, $b) == -1;
2744$c = rindex($a, $b) == -1;
2745$c = index($a, $b) != -1;
2746$c = rindex($a, $b) != -1;
2747$c = (index($a, $b) == -1);
2748$c = (rindex($a, $b) == -1);
2749$c = (index($a, $b) != -1);
2750$c = (rindex($a, $b) != -1);
e839e6ed
DM
2751####
2752# plain multiconcat
2753my($a, $b, $c, $d, @a);
2754$d = length $a . $b . $c;
2755$d = length($a) . $b . $c;
2756print '' . $a;
2757push @a, ($a . '') * $b;
2758unshift @a, "$a" * ($b . '');
2759print $a . 'x' . $b . $c;
2760print $a . 'x' . $b . $c, $d;
2761print $b . $c . ($a . $b);
2762print $b . $c . ($a . $b);
2763print $b . $c . @a;
2764print $a . "\x{100}";
2765####
2766# double-quoted multiconcat
2767my($a, $b, $c, $d, @a);
2768print "${a}x\x{100}$b$c";
2769print "$a\Q$b\E$c\Ua$a\E\Lb$b\uc$c\E$a${b}c$c";
2770print "A=$a[length 'b' . $c . 'd'] b=$b";
2771print "A=@a B=$b";
2772print "\x{101}$a\x{100}";
2773$a = qr/\Q
2774$b $c
2775\x80
2776\x{100}
2777\E$c
2778/;
2779####
2780# sprintf multiconcat
2781my($a, $b, $c, $d, @a);
2782print sprintf("%s%s%%%sx%s\x{100}%s", $a, $b, $c, scalar @a, $d);
2783####
2784# multiconcat with lexical assign
2785my($a, $b, $c, $d, $e, @a);
2786$d = 'foo' . $a;
2787$d = "foo$a";
2788$d = $a . '';
2789$d = 'foo' . $a . 'bar';
2790$d = $a . $b;
2791$d = $a . $b . $c;
2792$d = $a . $b . $c . @a;
2793$e = ($d = $a . $b . $c);
2794$d = !$a . $b . $c;
2795$a = $b . $c . ($a . $b);
2796$e = f($d = !$a . $b) . $c;
2797$d = "${a}x\x{100}$b$c";
2798f($d = !$a . $b . $c);
2799####
2800# multiconcat with lexical my
2801my($a, $b, $c, $d, $e, @a);
2802my $d1 = 'foo' . $a;
2803my $d2 = "foo$a";
2804my $d3 = $a . '';
2805my $d4 = 'foo' . $a . 'bar';
2806my $d5 = $a . $b;
2807my $d6 = $a . $b . $c;
2808my $e7 = ($d = $a . $b . $c);
2809my $d8 = !$a . $b . $c;
2810my $d9 = $b . $c . ($a . $b);
2811my $da = f($d = !$a . $b) . $c;
2812my $dc = "${a}x\x{100}$b$c";
2813f(my $db = !$a . $b . $c);
2814my $dd = $a . $b . $c . @a;
2815####
2816# multiconcat with lexical append
2817my($a, $b, $c, $d, $e, @a);
2818$d .= '';
2819$d .= $a;
2820$d .= "$a";
2821$d .= 'foo' . $a;
2822$d .= "foo$a";
2823$d .= $a . '';
2824$d .= 'foo' . $a . 'bar';
2825$d .= $a . $b;
2826$d .= $a . $b . $c;
2827$d .= $a . $b . @a;
2828$e .= ($d = $a . $b . $c);
2829$d .= !$a . $b . $c;
2830$a .= $b . $c . ($a . $b);
2831$e .= f($d .= !$a . $b) . $c;
2832f($d .= !$a . $b . $c);
2833$d .= "${a}x\x{100}$b$c";
2834####
2835# multiconcat with expression assign
2836my($a, $b, $c, @a);
2837our($d, $e);
2838$d = 'foo' . $a;
2839$d = "foo$a";
2840$d = $a . '';
2841$d = 'foo' . $a . 'bar';
2842$d = $a . $b;
2843$d = $a . $b . $c;
2844$d = $a . $b . @a;
2845$e = ($d = $a . $b . $c);
2846$a["-$b-"] = !$a . $b . $c;
2847$a[$b]{$c}{$d ? $a : $b . $c} = !$a . $b . $c;
2848$a = $b . $c . ($a . $b);
2849$e = f($d = !$a . $b) . $c;
2850$d = "${a}x\x{100}$b$c";
2851f($d = !$a . $b . $c);
2852####
2853# multiconcat with expression concat
2854my($a, $b, $c, @a);
2855our($d, $e);
2856$d .= 'foo' . $a;
2857$d .= "foo$a";
2858$d .= $a . '';
2859$d .= 'foo' . $a . 'bar';
2860$d .= $a . $b;
2861$d .= $a . $b . $c;
2862$d .= $a . $b . @a;
2863$e .= ($d .= $a . $b . $c);
2864$a["-$b-"] .= !$a . $b . $c;
2865$a[$b]{$c}{$d ? $a : $b . $c} .= !$a . $b . $c;
2866$a .= $b . $c . ($a . $b);
2867$e .= f($d .= !$a . $b) . $c;
2868$d .= "${a}x\x{100}$b$c";
2869f($d .= !$a . $b . $c);
2870####
2871# multiconcat with CORE::sprintf
2872# CONTEXT sub sprintf {}
2873my($a, $b);
2874my $x = CORE::sprintf('%s%s', $a, $b);
2875####
2876# multiconcat with backticks
2877my($a, $b);
2878our $x;
2879$x = `$a-$b`;
2880####
2881# multiconcat within qr//
2882my($r, $a, $b);
2883$r = qr/abc\Q$a-$b\Exyz/;
b4fb15a6
JL
2884####
2885# tr with unprintable characters
2886my $str;
2887$str = 'foo';
2888$str =~ tr/\cA//;
e923f3dc
Z
2889####
2890# CORE::foo special case in bareword parsing
dd666160
Z
2891print $CORE::foo, $CORE::foo::bar;
2892print @CORE::foo, @CORE::foo::bar;
2893print %CORE::foo, %CORE::foo::bar;
2894print $CORE::foo{'a'}, $CORE::foo::bar{'a'};
2895print &CORE::foo, &CORE::foo::bar;
2896print &CORE::foo(), &CORE::foo::bar();
257296eb 2897print \&CORE::foo, \&CORE::foo::bar;
dd666160
Z
2898print *CORE::foo, *CORE::foo::bar;
2899print stat CORE::foo::, stat CORE::foo::bar;
2900print CORE::foo:: 1;
2901print CORE::foo::bar 2;
2902####
2903# trailing colons on glob names
2904no strict 'vars';
2905$Foo::::baz = 1;
2906print $foo, $foo::, $foo::::;
2907print @foo, @foo::, @foo::::;
2908print %foo, %foo::, %foo::::;
2909print $foo{'a'}, $foo::{'a'}, $foo::::{'a'};
2910print &foo, &foo::, &foo::::;
2911print &foo(), &foo::(), &foo::::();
257296eb 2912print \&foo, \&foo::, \&foo::::;
dd666160
Z
2913print *foo, *foo::, *foo::::;
2914print stat Foo, stat Foo::::;
2915print Foo 1;
2916print Foo:::: 2;
2917####
2918# trailing colons mixed with CORE
2919no strict 'vars';
2920print $CORE, $CORE::, $CORE::::;
2921print @CORE, @CORE::, @CORE::::;
2922print %CORE, %CORE::, %CORE::::;
2923print $CORE{'a'}, $CORE::{'a'}, $CORE::::{'a'};
2924print &CORE, &CORE::, &CORE::::;
2925print &CORE(), &CORE::(), &CORE::::();
257296eb 2926print \&CORE, \&CORE::, \&CORE::::;
dd666160
Z
2927print *CORE, *CORE::, *CORE::::;
2928print stat CORE, stat CORE::::;
2929print CORE 1;
2930print CORE:::: 2;
2931print $CORE::foo, $CORE::foo::, $CORE::foo::::;
2932print @CORE::foo, @CORE::foo::, @CORE::foo::::;
2933print %CORE::foo, %CORE::foo::, %CORE::foo::::;
2934print $CORE::foo{'a'}, $CORE::foo::{'a'}, $CORE::foo::::{'a'};
2935print &CORE::foo, &CORE::foo::, &CORE::foo::::;
2936print &CORE::foo(), &CORE::foo::(), &CORE::foo::::();
257296eb 2937print \&CORE::foo, \&CORE::foo::, \&CORE::foo::::;
dd666160
Z
2938print *CORE::foo, *CORE::foo::, *CORE::foo::::;
2939print stat CORE::foo::, stat CORE::foo::::;
2940print CORE::foo:: 1;
2941print CORE::foo:::: 2;
257296eb
Z
2942####
2943# \&foo
2944my sub foo {
2945 1;
2946}
2947no strict 'vars';
2948print \&main::foo;
2949print \&{foo};
2950print \&bar;
2951use strict 'vars';
2952print \&main::foo;
2953print \&{foo};
2954print \&main::bar;
2955####
2956# exists(&foo)
2957my sub foo {
2958 1;
2959}
2960no strict 'vars';
2961print exists &main::foo;
2962print exists &{foo};
2963print exists &bar;
2964use strict 'vars';
2965print exists &main::foo;
2966print exists &{foo};
2967print exists &main::bar;
ed34dca8
DM
2968# precedence of optimised-away 'keys' (OPpPADHV_ISKEYS/OPpRV2HV_ISKEYS)
2969my($r1, %h1, $res);
2970our($r2, %h2);
2971$res = keys %h1;
2972$res = keys %h2;
2973$res = keys %$r1;
2974$res = keys %$r2;
2975$res = keys(%h1) / 2 - 1;
2976$res = keys(%h2) / 2 - 1;
2977$res = keys(%$r1) / 2 - 1;
2978$res = keys(%$r2) / 2 - 1;
2979####
2980# ditto in presence of sub keys {}
2981# CONTEXT sub keys {}
2982no warnings;
2983my($r1, %h1, $res);
2984our($r2, %h2);
2985CORE::keys %h1;
2986CORE::keys(%h1) / 2;
2987$res = CORE::keys %h1;
2988$res = CORE::keys %h2;
2989$res = CORE::keys %$r1;
2990$res = CORE::keys %$r2;
2991$res = CORE::keys(%h1) / 2 - 1;
2992$res = CORE::keys(%h2) / 2 - 1;
2993$res = CORE::keys(%$r1) / 2 - 1;
2994$res = CORE::keys(%$r2) / 2 - 1;
4b75096e
DM
2995####
2996# concat: STACKED: ambiguity between .= and optimised nested
2997my($a, $b);
2998$b = $a . $a . $a;
2999(($a .= $a) .= $a) .= $a;
b2362f9c
DM
3000####
3001# multiconcat: $$ within string
3002my($a, $x);
3003$x = "${$}abc";
3004$x = "\$$a";
c4874d8a
DM
3005####
3006# single state aggregate assignment
3007# CONTEXT use feature "state";
3008state @a = (1, 2, 3);
3009state %h = ('a', 1, 'b', 2);
4a4aa6e0
DM
3010####
3011# state var with attribute
3012# CONTEXT use feature "state";
3013state $x :shared;
3014state $y :shared = 1;
3015state @a :shared;
3016state @b :shared = (1, 2);
3017state %h :shared;
3018state %i :shared = ('a', 1, 'b', 2);