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