This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
fix deparsing of Test::More's use_ok()
[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 }
f9d3bdea 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####
de183bbb
FC
788# Split to our array
789our @array = split(//, 'foo', 0);
790####
ef7999f1
FC
791# Split to my array
792my @array = split(//, 'foo', 0);
793####
507a68aa 794# bug #40055
31c6271a
RD
795do { () };
796####
507a68aa 797# bug #40055
31c6271a 798do { my $x = 1; $x };
d9002312 799####
507a68aa 800# <20061012113037.GJ25805@c4.convolution.nl>
d9002312
SM
801my $f = sub {
802 +{[]};
803} ;
8b2d6640 804####
507a68aa 805# bug #43010
8b2d6640
FC
806'!@$%'->();
807####
507a68aa 808# bug #43010
8b2d6640
FC
809::();
810####
507a68aa 811# bug #43010
8b2d6640
FC
812'::::'->();
813####
507a68aa 814# bug #43010
8b2d6640 815&::::;
09d856fb 816####
1b38d782
FC
817# [perl #77172]
818package rt77172;
819sub foo {} foo & & & foo;
820>>>>
821package rt77172;
822foo(&{&} & foo());
823####
507a68aa 824# variables as method names
09d856fb
CK
825my $bar;
826'Foo'->$bar('orz');
35a99a08 827'Foo'->$bar('orz') = 'a stranger stranger than before';
09d856fb 828####
507a68aa 829# constants as method names
09d856fb
CK
830'Foo'->bar('orz');
831####
507a68aa 832# constants as method names without ()
09d856fb 833'Foo'->bar;
0ced6c29 834####
28bfcb02 835# [perl #47359] "indirect" method call notation
1bf8bbb0
FC
836our @bar;
837foo{@bar}+1,->foo;
838(foo{@bar}+1),foo();
839foo{@bar}1 xor foo();
840>>>>
841our @bar;
842(foo { @bar } 1)->foo;
843(foo { @bar } 1), foo();
844foo { @bar } 1 xor foo();
845####
9d52f6f3
FC
846# indirops with blocks
847# CONTEXT use 5.01;
848print {*STDOUT;} 'foo';
849printf {*STDOUT;} 'foo';
850say {*STDOUT;} 'foo';
851system {'foo';} '-foo';
852exec {'foo';} '-foo';
853####
e9c69003 854# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
205fef88 855# CONTEXT use feature ':5.10';
507a68aa 856# say
7ddd1a01
NC
857say 'foo';
858####
8f57bb34 859# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
8f57bb34
NC
860# CONTEXT use 5.10.0;
861# say in the context of use 5.10.0
862say 'foo';
863####
864# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
8f57bb34
NC
865# say with use 5.10.0
866use 5.10.0;
867say 'foo';
868>>>>
127ce1cd 869no feature ':all';
8f57bb34
NC
870use feature ':5.10';
871say 'foo';
872####
873# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
874# say with use feature ':5.10';
875use feature ':5.10';
876say 'foo';
877>>>>
878use feature 'say', 'state', 'switch';
879say 'foo';
880####
881# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
8f57bb34
NC
882# CONTEXT use feature ':5.10';
883# say with use 5.10.0 in the context of use feature
884use 5.10.0;
885say 'foo';
886>>>>
127ce1cd 887no feature ':all';
8f57bb34
NC
888use feature ':5.10';
889say 'foo';
890####
891# SKIP ?$] < 5.010 && "say not implemented on this Perl version"
892# CONTEXT use 5.10.0;
893# say with use feature ':5.10' in the context of use 5.10.0
894use feature ':5.10';
895say 'foo';
896>>>>
897say 'foo';
898####
899# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
900# CONTEXT use feature ':5.15';
901# __SUB__
902__SUB__;
903####
904# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
8f57bb34
NC
905# CONTEXT use 5.15.0;
906# __SUB__ in the context of use 5.15.0
907__SUB__;
908####
909# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
8f57bb34
NC
910# __SUB__ with use 5.15.0
911use 5.15.0;
912__SUB__;
913>>>>
127ce1cd 914no feature ':all';
8f57bb34
NC
915use feature ':5.16';
916__SUB__;
917####
918# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
919# __SUB__ with use feature ':5.15';
920use feature ':5.15';
921__SUB__;
922>>>>
923use feature 'current_sub', 'evalbytes', 'fc', 'say', 'state', 'switch', 'unicode_strings', 'unicode_eval';
924__SUB__;
925####
926# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
8f57bb34
NC
927# CONTEXT use feature ':5.15';
928# __SUB__ with use 5.15.0 in the context of use feature
929use 5.15.0;
930__SUB__;
931>>>>
127ce1cd 932no feature ':all';
8f57bb34
NC
933use feature ':5.16';
934__SUB__;
935####
936# SKIP ?$] < 5.015 && "__SUB__ not implemented on this Perl version"
937# CONTEXT use 5.15.0;
938# __SUB__ with use feature ':5.15' in the context of use 5.15.0
939use feature ':5.15';
940__SUB__;
941>>>>
942__SUB__;
943####
e9c69003 944# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
205fef88 945# CONTEXT use feature ':5.10';
507a68aa 946# state vars
0ced6c29
RGS
947state $x = 42;
948####
e9c69003 949# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
205fef88 950# CONTEXT use feature ':5.10';
507a68aa 951# state var assignment
7ddd1a01
NC
952{
953 my $y = (state $x = 42);
954}
955####
e9c69003 956# SKIP ?$] < 5.010 && "state vars not implemented on this Perl version"
205fef88 957# CONTEXT use feature ':5.10';
c4a6f826 958# state vars in anonymous subroutines
7ddd1a01
NC
959$a = sub {
960 state $x;
961 return $x++;
962}
963;
644741fd
NC
964####
965# SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
507a68aa 966# each @array;
644741fd
NC
967each @ARGV;
968each @$a;
969####
970# SKIP ?$] < 5.011 && 'each @array not implemented on this Perl version'
507a68aa 971# keys @array; values @array
644741fd
NC
972keys @$a if keys @ARGV;
973values @ARGV if values @$a;
35925e80 974####
507a68aa 975# Anonymous arrays and hashes, and references to them
35925e80
RGS
976my $a = {};
977my $b = \{};
978my $c = [];
979my $d = \[];
9210de83
FR
980####
981# SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
0f539b13 982# CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
507a68aa 983# implicit smartmatch in given/when
9210de83
FR
984given ('foo') {
985 when ('bar') { continue; }
986 when ($_ ~~ 'quux') { continue; }
987 default { 0; }
988}
7ecdd211 989####
507a68aa 990# conditions in elsifs (regression in change #33710 which fixed bug #37302)
7ecdd211
PJ
991if ($a) { x(); }
992elsif ($b) { x(); }
993elsif ($a and $b) { x(); }
994elsif ($a or $b) { x(); }
995else { x(); }
03b22f1b 996####
507a68aa 997# interpolation in regexps
03b22f1b
RGS
998my($y, $t);
999/x${y}z$t/;
227375e1 1000####
4a4b8592 1001# TODO new undocumented cpan-bug #33708
507a68aa 1002# cpan-bug #33708
227375e1
RU
1003%{$_ || {}}
1004####
4a4b8592 1005# TODO hash constants not yet fixed
507a68aa 1006# cpan-bug #33708
227375e1
RU
1007use constant H => { "#" => 1 }; H->{"#"}
1008####
4a4b8592 1009# TODO optimized away 0 not yet fixed
507a68aa 1010# cpan-bug #33708
227375e1 1011foreach my $i (@_) { 0 }
edbe35ea 1012####
507a68aa 1013# tests with not, not optimized
07f3cdf5 1014my $c;
edbe35ea
VP
1015x() unless $a;
1016x() if not $a and $b;
1017x() if $a and not $b;
1018x() unless not $a and $b;
1019x() unless $a and not $b;
1020x() if not $a or $b;
1021x() if $a or not $b;
1022x() unless not $a or $b;
1023x() unless $a or not $b;
07f3cdf5
VP
1024x() if $a and not $b and $c;
1025x() if not $a and $b and not $c;
1026x() unless $a and not $b and $c;
1027x() unless not $a and $b and not $c;
1028x() if $a or not $b or $c;
1029x() if not $a or $b or not $c;
1030x() unless $a or not $b or $c;
1031x() unless not $a or $b or not $c;
edbe35ea 1032####
507a68aa 1033# tests with not, optimized
07f3cdf5 1034my $c;
edbe35ea
VP
1035x() if not $a;
1036x() unless not $a;
1037x() if not $a and not $b;
1038x() unless not $a and not $b;
1039x() if not $a or not $b;
1040x() unless not $a or not $b;
07f3cdf5
VP
1041x() if not $a and not $b and $c;
1042x() unless not $a and not $b and $c;
1043x() if not $a or not $b or $c;
1044x() unless not $a or not $b or $c;
1045x() if not $a and not $b and not $c;
1046x() unless not $a and not $b and not $c;
1047x() if not $a or not $b or not $c;
1048x() unless not $a or not $b or not $c;
1049x() unless not $a or not $b or not $c;
edbe35ea 1050>>>>
07f3cdf5 1051my $c;
edbe35ea
VP
1052x() unless $a;
1053x() if $a;
1054x() unless $a or $b;
1055x() if $a or $b;
1056x() unless $a and $b;
07f3cdf5
VP
1057x() if $a and $b;
1058x() if not $a || $b and $c;
1059x() unless not $a || $b and $c;
1060x() if not $a && $b or $c;
1061x() unless not $a && $b or $c;
1062x() unless $a or $b or $c;
1063x() if $a or $b or $c;
1064x() unless $a and $b and $c;
1065x() if $a and $b and $c;
1066x() unless not $a && $b && $c;
71c4dbc3 1067####
507a68aa 1068# tests that should be constant folded
71c4dbc3
VP
1069x() if 1;
1070x() if GLIPP;
1071x() if !GLIPP;
1072x() if GLIPP && GLIPP;
1073x() if !GLIPP || GLIPP;
1074x() if do { GLIPP };
1075x() if do { no warnings 'void'; 5; GLIPP };
1076x() if do { !GLIPP };
1077if (GLIPP) { x() } else { z() }
1078if (!GLIPP) { x() } else { z() }
1079if (GLIPP) { x() } elsif (GLIPP) { z() }
1080if (!GLIPP) { x() } elsif (GLIPP) { z() }
1081if (GLIPP) { x() } elsif (!GLIPP) { z() }
1082if (!GLIPP) { x() } elsif (!GLIPP) { z() }
1083if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (GLIPP) { t() }
1084if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
1085if (!GLIPP) { x() } elsif (!GLIPP) { z() } elsif (!GLIPP) { t() }
1086>>>>
1087x();
1088x();
1089'???';
1090x();
1091x();
1092x();
1093x();
1094do {
1095 '???'
1096};
1097do {
1098 x()
1099};
1100do {
1101 z()
1102};
1103do {
1104 x()
1105};
1106do {
1107 z()
1108};
1109do {
1110 x()
1111};
1112'???';
1113do {
1114 t()
1115};
1116'???';
1117!1;
1118####
719c50dc
RGS
1119# TODO constant deparsing has been backed out for 5.12
1120# XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
507a68aa 1121# tests that shouldn't be constant folded
ac0f1413
NC
1122# It might be fundamentally impossible to make this work on ithreads, in which
1123# case the TODO should become a SKIP
71c4dbc3
VP
1124x() if $a;
1125if ($a == 1) { x() } elsif ($b == 2) { z() }
1126if (do { foo(); GLIPP }) { x() }
1127if (do { $a++; GLIPP }) { x() }
1128>>>>
1129x() if $a;
1130if ($a == 1) { x(); } elsif ($b == 2) { z(); }
2990415a
FR
1131if (do { foo(); GLIPP }) { x(); }
1132if (do { ++$a; GLIPP }) { x(); }
1133####
0fa4a265 1134# TODO constant deparsing has been backed out for 5.12
507a68aa 1135# tests for deparsing constants
2990415a
FR
1136warn PI;
1137####
0fa4a265 1138# TODO constant deparsing has been backed out for 5.12
507a68aa 1139# tests for deparsing imported constants
3779476a 1140warn O_TRUNC;
2990415a 1141####
0fa4a265 1142# TODO constant deparsing has been backed out for 5.12
507a68aa 1143# tests for deparsing re-exported constants
2990415a
FR
1144warn O_CREAT;
1145####
0fa4a265 1146# TODO constant deparsing has been backed out for 5.12
507a68aa 1147# tests for deparsing imported constants that got deleted from the original namespace
aaf9c2b2 1148warn O_APPEND;
2990415a 1149####
0fa4a265
DM
1150# TODO constant deparsing has been backed out for 5.12
1151# XXXTODO ? $Config::Config{useithreads} && "doesn't work with threads"
507a68aa 1152# tests for deparsing constants which got turned into full typeglobs
ac0f1413
NC
1153# It might be fundamentally impossible to make this work on ithreads, in which
1154# case the TODO should become a SKIP
2990415a
FR
1155warn O_EXCL;
1156eval '@Fcntl::O_EXCL = qw/affe tiger/;';
1157warn O_EXCL;
1158####
0fa4a265 1159# TODO constant deparsing has been backed out for 5.12
507a68aa 1160# tests for deparsing of blessed constant with overloaded numification
2990415a 1161warn OVERLOADED_NUMIFICATION;
79289e05 1162####
507a68aa 1163# strict
79289e05 1164no strict;
415d4c68
FC
1165print $x;
1166use strict 'vars';
1167print $main::x;
1168use strict 'subs';
1169print $main::x;
1170use strict 'refs';
1171print $main::x;
1172no strict 'vars';
79289e05
NC
1173$x;
1174####
1175# TODO Subsets of warnings could be encoded textually, rather than as bitflips.
507a68aa 1176# subsets of warnings
79289e05
NC
1177no warnings 'deprecated';
1178my $x;
1179####
1180# TODO Better test for CPAN #33708 - the deparsed code has different behaviour
507a68aa 1181# CPAN #33708
79289e05
NC
1182use strict;
1183no warnings;
1184
1185foreach (0..3) {
1186 my $x = 2;
1187 {
1188 my $x if 0;
1189 print ++$x, "\n";
1190 }
1191}
d83f38d8 1192####
507a68aa 1193# no attribute list
d83f38d8
NC
1194my $pi = 4;
1195####
2dc78664
NC
1196# SKIP ?$] > 5.013006 && ":= is now a syntax error"
1197# := treated as an empty attribute list
d83f38d8
NC
1198no warnings;
1199my $pi := 4;
1200>>>>
1201no warnings;
1202my $pi = 4;
1203####
507a68aa 1204# : = empty attribute list
d83f38d8
NC
1205my $pi : = 4;
1206>>>>
1207my $pi = 4;
689e417f 1208####
507a68aa 1209# in place sort
689e417f
VP
1210our @a;
1211my @b;
1212@a = sort @a;
1213@b = sort @b;
1214();
1215####
507a68aa 1216# in place reverse
689e417f
VP
1217our @a;
1218my @b;
1219@a = reverse @a;
1220@b = reverse @b;
1221();
06fc6867 1222####
507a68aa 1223# #71870 Use of uninitialized value in bitwise and B::Deparse
06fc6867
VP
1224my($r, $s, @a);
1225@a = split(/foo/, $s, 0);
1226$r = qr/foo/;
1227@a = split(/$r/, $s, 0);
1228();
98a1a137 1229####
507a68aa 1230# package declaration before label
98a1a137
Z
1231{
1232 package Foo;
1233 label: print 123;
1234}
538f5756 1235####
507a68aa 1236# shift optimisation
538f5756
RZ
1237shift;
1238>>>>
1239shift();
1240####
507a68aa 1241# shift optimisation
538f5756
RZ
1242shift @_;
1243####
507a68aa 1244# shift optimisation
538f5756
RZ
1245pop;
1246>>>>
1247pop();
1248####
507a68aa 1249# shift optimisation
538f5756 1250pop @_;
a539498a 1251####
507a68aa 1252#[perl #20444]
a539498a
FC
1253"foo" =~ (1 ? /foo/ : /bar/);
1254"foo" =~ (1 ? y/foo// : /bar/);
5e5a1632 1255"foo" =~ (1 ? y/foo//r : /bar/);
a539498a
FC
1256"foo" =~ (1 ? s/foo// : /bar/);
1257>>>>
1258'foo' =~ ($_ =~ /foo/);
1259'foo' =~ ($_ =~ tr/fo//);
5e5a1632 1260'foo' =~ ($_ =~ tr/fo//r);
a539498a 1261'foo' =~ ($_ =~ s/foo//);
e0ab66ad 1262####
5e5a1632
FC
1263# The fix for [perl #20444] broke this.
1264'foo' =~ do { () };
1265####
4b58603b
FC
1266# [perl #81424] match against aelemfast_lex
1267my @s;
1268print /$s[1]/;
1269####
36727b53
FC
1270# /$#a/
1271print /$#main::a/;
1272####
bae5b54e
FC
1273# /@array/
1274our @a;
1275my @b;
1276print /@a/;
1277print /@b/;
1278print qr/@a/;
1279print qr/@b/;
1280####
3b91d897
FC
1281# =~ QR_CONSTANT
1282use constant QR_CONSTANT => qr/a/soupmix;
1283'' =~ QR_CONSTANT;
1284>>>>
1285'' =~ /a/impsux;
1286####
9e32885a
FC
1287# $lexical =~ //
1288my $x;
1289$x =~ //;
1290####
b9bc576f 1291# [perl #91318] /regexp/applaud
09622ee2
FC
1292print /a/a, s/b/c/a;
1293print /a/aa, s/b/c/aa;
1294print /a/p, s/b/c/p;
1295print /a/l, s/b/c/l;
1296print /a/u, s/b/c/u;
b9bc576f
FC
1297{
1298 use feature "unicode_strings";
09622ee2 1299 print /a/d, s/b/c/d;
b9bc576f
FC
1300}
1301{
1302 use re "/u";
09622ee2 1303 print /a/d, s/b/c/d;
b9bc576f 1304}
dff5ffe4
FC
1305{
1306 use 5.012;
1307 print /a/d, s/b/c/d;
1308}
b9bc576f 1309>>>>
09622ee2
FC
1310print /a/a, s/b/c/a;
1311print /a/aa, s/b/c/aa;
1312print /a/p, s/b/c/p;
1313print /a/l, s/b/c/l;
1314print /a/u, s/b/c/u;
b9bc576f 1315{
a8095af7 1316 use feature 'unicode_strings';
09622ee2 1317 print /a/d, s/b/c/d;
b9bc576f
FC
1318}
1319{
0bb01b05
FC
1320 BEGIN { $^H{'reflags'} = '0';
1321 $^H{'reflags_charset'} = '2'; }
09622ee2 1322 print /a/d, s/b/c/d;
b9bc576f 1323}
dff5ffe4 1324{
127ce1cd 1325 no feature ':all';
dff5ffe4
FC
1326 use feature ':5.12';
1327 print /a/d, s/b/c/d;
1328}
b9bc576f 1329####
dc6dfd62
LM
1330# all the flags (qr//)
1331$_ = qr/X/m;
1332$_ = qr/X/s;
1333$_ = qr/X/i;
1334$_ = qr/X/x;
1335$_ = qr/X/p;
1336$_ = qr/X/o;
1337$_ = qr/X/u;
1338$_ = qr/X/a;
1339$_ = qr/X/l;
1340$_ = qr/X/n;
1341####
1342use feature 'unicode_strings';
1343$_ = qr/X/d;
1344####
1345# all the flags (m//)
1346/X/m;
1347/X/s;
1348/X/i;
1349/X/x;
1350/X/p;
1351/X/o;
1352/X/u;
1353/X/a;
1354/X/l;
1355/X/n;
1356/X/g;
1357/X/cg;
1358####
1359use feature 'unicode_strings';
1360/X/d;
1361####
1362# all the flags (s///)
1363s/X//m;
1364s/X//s;
1365s/X//i;
1366s/X//x;
1367s/X//p;
1368s/X//o;
1369s/X//u;
1370s/X//a;
1371s/X//l;
1372s/X//n;
1373s/X//g;
1374s/X/'';/e;
1375s/X//r;
1376####
1377use feature 'unicode_strings';
1378s/X//d;
1379####
1380# all the flags (tr///)
1381tr/X/Y/c;
1382tr/X//d;
1383tr/X//s;
1384tr/X//r;
1385####
9f125c4a
FC
1386# [perl #119807] s//\(3)/ge should not warn when deparsed (\3 warns)
1387s/foo/\(3);/eg;
1388####
c9fa6ae9 1389# [perl #115256]
c9fa6ae9
FC
1390"" =~ /a(?{ print q|
1391|})/;
1392>>>>
f6b6ee63 1393'' =~ /a(?{ print "\n"; })/;
c9fa6ae9
FC
1394####
1395# [perl #123217]
c9fa6ae9
FC
1396$_ = qr/(??{<<END})/
1397f.o
1398b.r
1399END
1400>>>>
1401$_ = qr/(??{ "f.o\nb.r\n"; })/;
1402####
1403# More regexp code block madness
c9fa6ae9
FC
1404my($b, @a);
1405/(?{ die $b; })/;
1406/a(?{ die $b; })a/;
1407/$a(?{ die $b; })/;
1408/@a(?{ die $b; })/;
1409/(??{ die $b; })/;
1410/a(??{ die $b; })a/;
1411/$a(??{ die $b; })/;
1412/@a(??{ die $b; })/;
1413qr/(?{ die $b; })/;
1414qr/a(?{ die $b; })a/;
1415qr/$a(?{ die $b; })/;
1416qr/@a(?{ die $b; })/;
1417qr/(??{ die $b; })/;
1418qr/a(??{ die $b; })a/;
1419qr/$a(??{ die $b; })/;
1420qr/@a(??{ die $b; })/;
1421s/(?{ die $b; })//;
1422s/a(?{ die $b; })a//;
1423s/$a(?{ die $b; })//;
1424s/@a(?{ die $b; })//;
1425s/(??{ die $b; })//;
1426s/a(??{ die $b; })a//;
1427s/$a(??{ die $b; })//;
1428s/@a(??{ die $b; })//;
1429####
ba0372a0
FC
1430# /(?x)<newline><tab>/
1431/(?x)
1432 /;
1433####
e7afc405 1434# y///r
d52196e1 1435tr/a/b/r + $a =~ tr/p/q/r;
cb8157e3 1436####
12cea2fa
FC
1437# y///d in list [perl #119815]
1438() = tr/a//d;
1439####
cb8578ff 1440# [perl #90898]
f4002a4b 1441<a,>;
18371617
LM
1442glob 'a,';
1443>>>>
1444glob 'a,';
1445glob 'a,';
09dcfa7d
FC
1446####
1447# [perl #91008]
26230909 1448# SKIP ?$] >= 5.023 && "autoderef deleted in this Perl version"
d401967c 1449# CONTEXT no warnings 'experimental::autoderef';
09dcfa7d
FC
1450each $@;
1451keys $~;
1452values $!;
5d8c42c2
FC
1453####
1454# readpipe with complex expression
1455readpipe $a + $b;
93bad3fd
NC
1456####
1457# aelemfast
1458$b::a[0] = 1;
1459####
1460# aelemfast for a lexical
1461my @a;
1462$a[0] = 1;
80e3f4ad
FC
1463####
1464# feature features without feature
0f539b13 1465# CONTEXT no warnings 'experimental::smartmatch';
80e3f4ad 1466CORE::state $x;
223b1722
FC
1467CORE::say $x;
1468CORE::given ($x) {
1469 CORE::when (3) {
1470 continue;
1471 }
1472 CORE::default {
1473 CORE::break;
1474 }
1475}
1476CORE::evalbytes '';
1477() = CORE::__SUB__;
838f2281 1478() = CORE::fc $x;
223b1722
FC
1479####
1480# feature features when feature has been disabled by use VERSION
0f539b13 1481# CONTEXT no warnings 'experimental::smartmatch';
223b1722
FC
1482use feature (sprintf(":%vd", $^V));
1483use 1;
412989c2 1484CORE::say $_;
223b1722 1485CORE::state $x;
223b1722
FC
1486CORE::given ($x) {
1487 CORE::when (3) {
1488 continue;
1489 }
1490 CORE::default {
1491 CORE::break;
1492 }
1493}
1494CORE::evalbytes '';
1495() = CORE::__SUB__;
1496>>>>
412989c2 1497CORE::say $_;
205fef88 1498CORE::state $x;
205fef88
NC
1499CORE::given ($x) {
1500 CORE::when (3) {
1501 continue;
1502 }
1503 CORE::default {
1504 CORE::break;
1505 }
1506}
1507CORE::evalbytes '';
1508() = CORE::__SUB__;
1509####
1510# (the above test with CONTEXT, and the output is equivalent but different)
0f539b13 1511# CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
205fef88
NC
1512# feature features when feature has been disabled by use VERSION
1513use feature (sprintf(":%vd", $^V));
1514use 1;
412989c2 1515CORE::say $_;
205fef88 1516CORE::state $x;
205fef88
NC
1517CORE::given ($x) {
1518 CORE::when (3) {
1519 continue;
1520 }
1521 CORE::default {
1522 CORE::break;
1523 }
1524}
1525CORE::evalbytes '';
1526() = CORE::__SUB__;
1527>>>>
127ce1cd 1528no feature ':all';
0bb01b05 1529use feature ':default';
412989c2 1530CORE::say $_;
223b1722 1531CORE::state $x;
80e3f4ad
FC
1532CORE::given ($x) {
1533 CORE::when (3) {
1534 continue;
1535 }
1536 CORE::default {
e36901c8 1537 CORE::break;
80e3f4ad
FC
1538 }
1539}
7d789282 1540CORE::evalbytes '';
84ed0108 1541() = CORE::__SUB__;
6ec73527 1542####
7741ceed
FC
1543# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
1544# lexical subroutines and keywords of the same name
1545# CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental';
1546my sub default;
1547my sub else;
1548my sub elsif;
1549my sub for;
1550my sub foreach;
1551my sub given;
1552my sub if;
1553my sub m;
1554my sub no;
1555my sub package;
1556my sub q;
1557my sub qq;
1558my sub qr;
1559my sub qx;
1560my sub require;
1561my sub s;
1562my sub sub;
1563my sub tr;
1564my sub unless;
1565my sub until;
1566my sub use;
1567my sub when;
1568my sub while;
1569CORE::default { die; }
1570CORE::if ($1) { die; }
1571CORE::if ($1) { die; }
1572CORE::elsif ($1) { die; }
1573CORE::else { die; }
1574CORE::for (die; $1; die) { die; }
1575CORE::foreach $_ (1 .. 10) { die; }
1576die CORE::foreach (1);
1577CORE::given ($1) { die; }
1578CORE::m[/];
1579CORE::m?/?;
1580CORE::package foo;
1581CORE::no strict;
1582() = (CORE::q['], CORE::qq["$_], CORE::qr//, CORE::qx[`]);
1583CORE::require 1;
1584CORE::s///;
1585() = CORE::sub { die; } ;
1586CORE::tr///;
1587CORE::unless ($1) { die; }
1588CORE::until ($1) { die; }
1589die CORE::until $1;
1590CORE::use strict;
1591CORE::when ($1 ~~ $2) { die; }
1592CORE::while ($1) { die; }
1593die CORE::while $1;
1594####
0bb01b05
FC
1595# Feature hints
1596use feature 'current_sub', 'evalbytes';
1597print;
1598use 1;
1599print;
1600use 5.014;
1601print;
1602no feature 'unicode_strings';
1603print;
1604>>>>
a8095af7 1605use feature 'current_sub', 'evalbytes';
0bb01b05 1606print $_;
127ce1cd 1607no feature ':all';
0bb01b05
FC
1608use feature ':default';
1609print $_;
127ce1cd 1610no feature ':all';
0bb01b05
FC
1611use feature ':5.12';
1612print $_;
a8095af7 1613no feature 'unicode_strings';
0bb01b05
FC
1614print $_;
1615####
6ec73527
FC
1616# $#- $#+ $#{%} etc.
1617my @x;
5b6da579 1618@x = ($#{`}, $#{~}, $#{!}, $#{@}, $#{$}, $#{%}, $#{^}, $#{&}, $#{*});
6ec73527
FC
1619@x = ($#{(}, $#{)}, $#{[}, $#{{}, $#{]}, $#{}}, $#{'}, $#{"}, $#{,});
1620@x = ($#{<}, $#{.}, $#{>}, $#{/}, $#{?}, $#{=}, $#+, $#{\}, $#{|}, $#-);
b6bba886 1621@x = ($#{;}, $#{:}, $#{1}), $#_;
61154ac0 1622####
ff683671
NC
1623# ${#} interpolated
1624# It's a known TODO that warnings are deparsed as bits, not textually.
1625no warnings;
61154ac0 1626() = "${#}a";
958ed56b 1627####
337d7381
FC
1628# [perl #86060] $( $| $) in regexps need braces
1629/${(}/;
1630/${|}/;
1631/${)}/;
1632/${(}${|}${)}/;
3f193e55 1633/@{+}@{-}/;
337d7381 1634####
958ed56b
FC
1635# ()[...]
1636my(@a) = ()[()];
521795fe
FC
1637####
1638# sort(foo(bar))
1639# sort(foo(bar)) is interpreted as sort &foo(bar)
1640# sort foo(bar) is interpreted as sort foo bar
1641# parentheses are not optional in this case
1642print sort(foo('bar'));
1643>>>>
1644print sort(foo('bar'));
24fcb59f
FC
1645####
1646# substr assignment
1647substr(my $a, 0, 0) = (foo(), bar());
1648$a++;
04be0204 1649####
d1718a7c
FC
1650# This following line works around an unfixed bug that we are not trying to
1651# test for here:
1652# CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
04be0204
FC
1653# hint hash
1654BEGIN { $^H{'foo'} = undef; }
1655{
1656 BEGIN { $^H{'bar'} = undef; }
1657 {
1658 BEGIN { $^H{'baz'} = undef; }
1659 {
1660 print $_;
1661 }
1662 print $_;
1663 }
1664 print $_;
1665}
035146a3
FC
1666BEGIN { $^H{q[']} = '('; }
1667print $_;
c306e834 1668####
d1718a7c
FC
1669# This following line works around an unfixed bug that we are not trying to
1670# test for here:
1671# CONTEXT BEGIN { $^H{a} = "b"; delete $^H{a} } # make %^H localised
c306e834
FC
1672# hint hash changes that serialise the same way with sort %hh
1673BEGIN { $^H{'a'} = 'b'; }
1674{
1675 BEGIN { $^H{'b'} = 'a'; delete $^H{'a'}; }
1676 print $_;
1677}
1678print $_;
94bb57f9
FC
1679####
1680# [perl #47361] do({}) and do +{} (variants of do-file)
1681do({});
1682do +{};
8b46c09b
FC
1683sub foo::do {}
1684package foo;
1685CORE::do({});
1686CORE::do +{};
94bb57f9
FC
1687>>>>
1688do({});
1689do({});
8b46c09b
FC
1690package foo;
1691CORE::do({});
1692CORE::do({});
9c56d9ea
FC
1693####
1694# [perl #77096] functions that do not follow the llafr
1695() = (return 1) + time;
1696() = (return ($1 + $2) * $3) + time;
1697() = (return ($a xor $b)) + time;
1698() = (do 'file') + time;
1699() = (do ($1 + $2) * $3) + time;
1700() = (do ($1 xor $2)) + time;
41df74e3
FC
1701() = (goto 1) + 3;
1702() = (require 'foo') + 3;
1703() = (require foo) + 3;
266da325 1704() = (CORE::dump 1) + 3;
41df74e3
FC
1705() = (last 1) + 3;
1706() = (next 1) + 3;
1707() = (redo 1) + 3;
5830412d
FC
1708() = (-R $_) + 3;
1709() = (-W $_) + 3;
1710() = (-X $_) + 3;
1711() = (-r $_) + 3;
1712() = (-w $_) + 3;
1713() = (-x $_) + 3;
2462c3cc 1714####
917a8f4f
FC
1715# require(foo()) and do(foo())
1716require (foo());
1717do (foo());
df465735
FC
1718goto (foo());
1719CORE::dump (foo());
1720last (foo());
1721next (foo());
1722redo (foo());
917a8f4f 1723####
5e7acd25
FC
1724# require vstring
1725require v5.16;
1726####
1cabb3b3
FC
1727# [perl #97476] not() *does* follow the llafr
1728$_ = ($a xor not +($1 || 2) ** 2);
1729####
4d8ac5c7
FC
1730# Precedence conundrums with argument-less function calls
1731() = (eof) + 1;
1732() = (return) + 1;
1733() = (return, 1);
7bc8c979
FC
1734() = warn;
1735() = warn() + 1;
4d8ac5c7
FC
1736() = setpgrp() + 1;
1737####
1eb0b7be
FC
1738# loopexes have assignment prec
1739() = (CORE::dump a) | 'b';
1740() = (goto a) | 'b';
1741() = (last a) | 'b';
1742() = (next a) | 'b';
1743() = (redo a) | 'b';
1744####
2462c3cc
FC
1745# [perl #63558] open local(*FH)
1746open local *FH;
564cd6cb 1747pipe local *FH, local *FH;
843b15cc 1748####
b89b7257
FC
1749# [perl #91416] open "string"
1750open 'open';
1751open '####';
1752open '^A';
1753open "\ca";
1754>>>>
1755open *open;
1756open '####';
1757open '^A';
1758open *^A;
1759####
be6cf5cf
FC
1760# "string"->[] ->{}
1761no strict 'vars';
1762() = 'open'->[0]; #aelemfast
1763() = '####'->[0];
1764() = '^A'->[0];
1765() = "\ca"->[0];
b861b87f 1766() = 'a::]b'->[0];
10e8e32b
FC
1767() = 'open'->[$_]; #aelem
1768() = '####'->[$_];
1769() = '^A'->[$_];
1770() = "\ca"->[$_];
b861b87f 1771() = 'a::]b'->[$_];
10e8e32b
FC
1772() = 'open'->{0}; #helem
1773() = '####'->{0};
1774() = '^A'->{0};
1775() = "\ca"->{0};
b861b87f 1776() = 'a::]b'->{0};
be6cf5cf 1777>>>>
415d4c68 1778no strict 'vars';
be6cf5cf
FC
1779() = $open[0];
1780() = '####'->[0];
1781() = '^A'->[0];
1782() = $^A[0];
b861b87f 1783() = 'a::]b'->[0];
10e8e32b
FC
1784() = $open[$_];
1785() = '####'->[$_];
1786() = '^A'->[$_];
1787() = $^A[$_];
b861b87f 1788() = 'a::]b'->[$_];
10e8e32b
FC
1789() = $open{'0'};
1790() = '####'->{'0'};
1791() = '^A'->{'0'};
1792() = $^A{'0'};
b861b87f 1793() = 'a::]b'->{'0'};
be6cf5cf 1794####
843b15cc
FC
1795# [perl #74740] -(f()) vs -f()
1796$_ = -(f());
c75b4828
FC
1797####
1798# require <binop>
1799require 'a' . $1;
afb60448
HY
1800####
1801#[perl #30504] foreach-my postfix/prefix difference
1802$_ = 'foo' foreach my ($foo1, $bar1, $baz1);
1803foreach (my ($foo2, $bar2, $baz2)) { $_ = 'foo' }
1804foreach my $i (my ($foo3, $bar3, $baz3)) { $i = 'foo' }
1805>>>>
1806$_ = 'foo' foreach (my($foo1, $bar1, $baz1));
1807foreach $_ (my($foo2, $bar2, $baz2)) {
1808 $_ = 'foo';
1809}
1810foreach my $i (my($foo3, $bar3, $baz3)) {
1811 $i = 'foo';
1812}
1813####
1814#[perl #108224] foreach with continue block
1815foreach (1 .. 3) { print } continue { print "\n" }
1816foreach (1 .. 3) { } continue { }
1817foreach my $i (1 .. 3) { print $i } continue { print "\n" }
1818foreach my $i (1 .. 3) { } continue { }
1819>>>>
1820foreach $_ (1 .. 3) {
1821 print $_;
1822}
1823continue {
1824 print "\n";
1825}
1826foreach $_ (1 .. 3) {
1827 ();
1828}
1829continue {
1830 ();
1831}
1832foreach my $i (1 .. 3) {
1833 print $i;
1834}
1835continue {
1836 print "\n";
1837}
1838foreach my $i (1 .. 3) {
1839 ();
1840}
1841continue {
1842 ();
1843}
bc1cc2c3
DM
1844####
1845# file handles
1846no strict;
1847my $mfh;
1848open F;
1849open *F;
1850open $fh;
1851open $mfh;
1852open 'a+b';
1853select *F;
1854select F;
1855select $f;
1856select $mfh;
1857select 'a+b';
a7fd8ef6
DM
1858####
1859# 'my' works with padrange op
1860my($z, @z);
1861my $m1;
1862$m1 = 1;
1863$z = $m1;
1864my $m2 = 2;
1865my($m3, $m4);
1866($m3, $m4) = (1, 2);
1867@z = ($m3, $m4);
1868my($m5, $m6) = (1, 2);
1869my($m7, undef, $m8) = (1, 2, 3);
1870@z = ($m7, undef, $m8);
1871($m7, undef, $m8) = (1, 2, 3);
1872####
1873# 'our/local' works with padrange op
a7fd8ef6
DM
1874our($z, @z);
1875our $o1;
0298c760 1876no strict;
a7fd8ef6
DM
1877local $o11;
1878$o1 = 1;
1879local $o1 = 1;
1880$z = $o1;
1881$z = local $o1;
1882our $o2 = 2;
1883our($o3, $o4);
1884($o3, $o4) = (1, 2);
1885local($o3, $o4) = (1, 2);
1886@z = ($o3, $o4);
1887@z = local($o3, $o4);
1888our($o5, $o6) = (1, 2);
1889our($o7, undef, $o8) = (1, 2, 3);
1890@z = ($o7, undef, $o8);
1891@z = local($o7, undef, $o8);
1892($o7, undef, $o8) = (1, 2, 3);
1893local($o7, undef, $o8) = (1, 2, 3);
1894####
1895# 'state' works with padrange op
412989c2 1896# CONTEXT no strict; use feature 'state';
a7fd8ef6
DM
1897state($z, @z);
1898state $s1;
1899$s1 = 1;
1900$z = $s1;
1901state $s2 = 2;
1902state($s3, $s4);
1903($s3, $s4) = (1, 2);
1904@z = ($s3, $s4);
1905# assignment of state lists isn't implemented yet
1906#state($s5, $s6) = (1, 2);
1907#state($s7, undef, $s8) = (1, 2, 3);
1908#@z = ($s7, undef, $s8);
1909($s7, undef, $s8) = (1, 2, 3);
1910####
df2b00e8 1911# anon arrays with padrange
a7fd8ef6
DM
1912my($a, $b);
1913my $c = [$a, $b];
1914my $d = {$a, $b};
1915####
1916# slices with padrange
1917my($a, $b);
1918my(@x, %y);
1919@x = @x[$a, $b];
1920@x = @y{$a, $b};
1921####
1922# binops with padrange
1923my($a, $b, $c);
1924$c = $a cmp $b;
1925$c = $a + $b;
1926$a += $b;
1927$c = $a - $b;
1928$a -= $b;
1929$c = my $a1 cmp $b;
1930$c = my $a2 + $b;
1931$a += my $b1;
1932$c = my $a3 - $b;
1933$a -= my $b2;
1934####
1935# 'x' with padrange
1936my($a, $b, $c, $d, @e);
1937$c = $a x $b;
1938$a x= $b;
1939@e = ($a) x $d;
1940@e = ($a, $b) x $d;
1941@e = ($a, $b, $c) x $d;
1942@e = ($a, 1) x $d;
d5524600
DM
1943####
1944# @_ with padrange
1945my($a, $b, $c) = @_;
ce4062e7
AC
1946####
1947# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
ce4062e7 1948# lexical subroutine
db629560 1949# CONTEXT use feature 'lexical_subs';
601448c3 1950no warnings "experimental::lexical_subs";
ce4062e7
AC
1951my sub f {}
1952print f();
d4f1bfe7 1953>>>>
bc304ab2 1954BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55"}
d4f1bfe7 1955my sub f {
d4f1bfe7
FC
1956
1957}
d4f1bfe7 1958print f();
f0cf3754
AC
1959####
1960# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
f0cf3754 1961# lexical "state" subroutine
db629560 1962# CONTEXT use feature 'state', 'lexical_subs';
f0cf3754
AC
1963no warnings 'experimental::lexical_subs';
1964state sub f {}
1965print f();
d4f1bfe7 1966>>>>
bc304ab2 1967BEGIN {${^WARNING_BITS} = "\x54\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x55\x54\x55\x55\x55"}
db629560 1968state sub f {
d4f1bfe7
FC
1969
1970}
d4f1bfe7 1971print f();
bcbe2b27 1972####
8443930e 1973# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
8443930e
FC
1974# lexical subroutine scoping
1975# CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
1976{
1977 {
1978 my sub a { die; }
1979 {
1980 foo();
1981 my sub b;
bb9bfaa4 1982 b ;
8443930e 1983 main::b();
d49c3562
FC
1984 &main::b;
1985 &main::b();
1986 my $b = \&main::b;
1987 sub b { $b; }
8443930e
FC
1988 }
1989 }
1990 b();
1991}
1992####
bb9bfaa4
FC
1993# self-referential lexical subroutine
1994# CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
1995();
1996state sub sb2;
1997sub sb2 {
1998 sb2 ;
1999}
2000####
494a4b9c
FC
2001# lexical subroutine with outer declaration and inner definition
2002# CONTEXT use feature 'lexical_subs'; no warnings 'experimental::lexical_subs';
2003();
2004my sub f;
2005my sub g {
2006 ();
2007 sub f { }
2008}
2009####
2c5ddcd3
FC
2010# TODO only partially fixed
2011# lexical state subroutine with outer declaration and inner definition
2012# CONTEXT use feature 'lexical_subs', 'state'; no warnings 'experimental::lexical_subs';
2013();
2014state sub sb4;
2015state sub a {
2016 ();
2017 sub sb4 { }
2018}
2019state sub sb5;
2020sub {
2021 ();
2022 sub sb5 { }
2023} ;
2024####
bcbe2b27
FC
2025# Elements of %# should not be confused with $#{ array }
2026() = ${#}{'foo'};
c4cf781e 2027####
cfd916dd 2028# $; [perl #123357]
ddb55548
FC
2029$_ = $;;
2030do {
2031 $;
2032};
2033####
c65b7c4d
FC
2034# Ampersand calls and scalar context
2035# OPTIONS -P
2036package prototest;
2037sub foo($$);
2038foo(bar(),baz());
2039>>>>
2040package prototest;
2041&foo(scalar bar(), scalar baz());
2042####
de4fa237
FC
2043# coderef2text and prototyped sub calls [perl #123435]
2044is 'foo', 'oo';
2045####
fd8be4a1
FC
2046# prototypes with unary precedence
2047package prototest;
2048sub dollar($) {}
2049sub optdollar(;$) {}
2050sub optoptdollar(;;$) {}
2051sub splat(*) {}
2052sub optsplat(;*) {}
2053sub optoptsplat(;;*) {}
2054sub bar(_) {}
2055sub optbar(;_) {}
2056sub optoptbar(;;_) {}
2057sub plus(+) {}
2058sub optplus(;+) {}
2059sub optoptplus(;;+) {}
2060sub wack(\$) {}
2061sub optwack(;\$) {}
2062sub optoptwack(;;\$) {}
2063sub wackbrack(\[$]) {}
2064sub optwackbrack(;\[$]) {}
2065sub optoptwackbrack(;;\[$]) {}
2066dollar($a < $b);
2067optdollar($a < $b);
2068optoptdollar($a < $b);
2069splat($a < $b); # Some of these deparse with ‘&’; if that changes, just
2070optsplat($a < $b); # change the tests.
2071optoptsplat($a < $b);
2072bar($a < $b);
2073optbar($a < $b);
2074optoptbar($a < $b);
2075plus($a < $b);
2076optplus($a < $b);
2077optoptplus($a < $b);
2078wack($a = $b);
2079optwack($a = $b);
2080optoptwack($a = $b);
2081wackbrack($a = $b);
2082optwackbrack($a = $b);
2083optoptwackbrack($a = $b);
2084>>>>
2085package prototest;
2086dollar($a < $b);
2087optdollar($a < $b);
2088optoptdollar($a < $b);
2089&splat($a < $b);
2090&optsplat($a < $b);
2091&optoptsplat($a < $b);
2092bar($a < $b);
2093optbar($a < $b);
2094optoptbar($a < $b);
2095&plus($a < $b);
2096&optplus($a < $b);
2097&optoptplus($a < $b);
2098&wack(\($a = $b));
2099&optwack(\($a = $b));
2100&optoptwack(\($a = $b));
2101&wackbrack(\($a = $b));
2102&optwackbrack(\($a = $b));
2103&optoptwackbrack(\($a = $b));
2104####
b024352e
DM
2105# ensure aelemfast works in the range -128..127 and that there's no
2106# funky edge cases
2107my $x;
2108no strict 'vars';
2109$x = $a[-256] + $a[-255] + $a[-129] + $a[-128] + $a[-127] + $a[-1] + $a[0];
2110$x = $a[1] + $a[126] + $a[127] + $a[128] + $a[255] + $a[256];
2111my @b;
2112$x = $b[-256] + $b[-255] + $b[-129] + $b[-128] + $b[-127] + $b[-1] + $b[0];
2113$x = $b[1] + $b[126] + $b[127] + $b[128] + $b[255] + $b[256];
e09d73a6
DIM
2114####
2115# 'm' must be preserved in m??
2116m??;
c8ec376c
FC
2117####
2118# \(@array) and \(..., (@array), ...)
2119my(@array, %hash, @a, @b, %c, %d);
2120() = \(@array);
2121() = \(%hash);
2122() = \(@a, (@b), (%c), %d);
2123() = \(@Foo::array);
2124() = \(%Foo::hash);
2125() = \(@Foo::a, (@Foo::b), (%Foo::c), %Foo::d);
a958cfbb
FC
2126####
2127# subs synonymous with keywords
2128main::our();
2129main::pop();
2130state();
2131use feature 'state';
2132main::state();
9187b6e4
FC
2133####
2134# lvalue references
baabe3fb 2135# CONTEXT use feature "state", 'refaliasing', 'lexical_subs'; no warnings 'experimental';
9187b6e4
FC
2136our $x;
2137\$x = \$x;
2138my $m;
2139\$m = \$x;
2140\my $n = \$x;
2141(\$x) = @_;
2142\($x) = @_;
2143\($m) = @_;
2144(\$m) = @_;
2145\my($p) = @_;
2146(\my $r) = @_;
2147\($x, my $a) = @{[\$x, \$x]};
2148(\$x, \my $b) = @{[\$x, \$x]};
2149\local $x = \3;
2150\local($x) = \3;
2151\state $c = \3;
2152\state($d) = \3;
2153\our $e = \3;
2154\our($f) = \3;
2155\$_[0] = foo();
2156\($_[1]) = foo();
2157my @a;
2158\$a[0] = foo();
2159\($a[1]) = foo();
2160\local($a[1]) = foo();
2161\@a[0,1] = foo();
2162\(@a[2,3]) = foo();
2163\local @a[0,1] = (\$a)x2;
2164\$_{a} = foo();
2165\($_{b}) = foo();
2166my %h;
2167\$h{a} = foo();
2168\($h{b}) = foo();
2169\local $h{a} = \$x;
2170\local($h{b}) = \$x;
2171\@h{'a','b'} = foo();
2172\(@h{2,3}) = foo();
2173\local @h{'a','b'} = (\$x)x2;
2174\@_ = foo();
2175\@a = foo();
2176(\@_) = foo();
2177(\@a) = foo();
2178\my @c = foo();
2179(\my @d) = foo();
2180\(@_) = foo();
2181\(@a) = foo();
2182\my(@g) = foo();
2183\local @_ = \@_;
2184(\local @_) = \@_;
2185\state @e = [1..3];
2186\state(@f) = \3;
2187\our @i = [1..3];
2188\our(@h) = \3;
2189\%_ = foo();
2190\%h = foo();
2191(\%_) = foo();
2192(\%h) = foo();
2193\my %c = foo();
2194(\my %d) = foo();
2195\local %_ = \%h;
2196(\local %_) = \%h;
2197\state %y = {1,2};
2198\our %z = {1,2};
2199(\our %zz) = {1,2};
2200\&a = foo();
2201(\&a) = foo();
2202\(&a) = foo();
2203{
2204 my sub a;
2205 \&a = foo();
2206 (\&a) = foo();
2207 \(&a) = foo();
2208}
2209(\$_, $_) = \(1, 2);
2210$_ == 3 ? \$_ : $_ = \3;
2211$_ == 3 ? \$_ : \$x = \3;
2212\($_ == 3 ? $_ : $x) = \3;
2213for \my $topic (\$1, \$2) {
2214 die;
2215}
2216for \state $topic (\$1, \$2) {
2217 die;
2218}
2219for \our $topic (\$1, \$2) {
2220 die;
2221}
2222for \$_ (\$1, \$2) {
2223 die;
2224}
2225for \my @a ([1,2], [3,4]) {
2226 die;
2227}
2228for \state @a ([1,2], [3,4]) {
2229 die;
2230}
2231for \our @a ([1,2], [3,4]) {
2232 die;
2233}
2234for \@_ ([1,2], [3,4]) {
2235 die;
2236}
2237for \my %a ({5,6}, {7,8}) {
2238 die;
2239}
2240for \our %a ({5,6}, {7,8}) {
2241 die;
2242}
2243for \state %a ({5,6}, {7,8}) {
2244 die;
2245}
2246for \%_ ({5,6}, {7,8}) {
2247 die;
2248}
2249{
2250 my sub a;
2251 for \&a (sub { 9; }, sub { 10; }) {
2252 die;
2253 }
2254}
2255for \&a (sub { 9; }, sub { 10; }) {
2256 die;
2257}
2258>>>>
2259our $x;
2260\$x = \$x;
2261my $m;
2262\$m = \$x;
2263\my $n = \$x;
2264(\$x) = @_;
2265(\$x) = @_;
2266(\$m) = @_;
2267(\$m) = @_;
2268(\my $p) = @_;
2269(\my $r) = @_;
2270(\$x, \my $a) = @{[\$x, \$x];};
2271(\$x, \my $b) = @{[\$x, \$x];};
2272\local $x = \3;
2273(\local $x) = \3;
2274\state $c = \3;
2275(\state $d) = \3;
2276\our $e = \3;
2277(\our $f) = \3;
2278\$_[0] = foo();
2279(\$_[1]) = foo();
2280my @a;
2281\$a[0] = foo();
2282(\$a[1]) = foo();
2283(\local $a[1]) = foo();
2284(\@a[0, 1]) = foo();
2285(\@a[2, 3]) = foo();
2286(\local @a[0, 1]) = (\$a) x 2;
2287\$_{'a'} = foo();
2288(\$_{'b'}) = foo();
2289my %h;
2290\$h{'a'} = foo();
2291(\$h{'b'}) = foo();
2292\local $h{'a'} = \$x;
2293(\local $h{'b'}) = \$x;
2294(\@h{'a', 'b'}) = foo();
2295(\@h{2, 3}) = foo();
2296(\local @h{'a', 'b'}) = (\$x) x 2;
2297\@_ = foo();
2298\@a = foo();
2299(\@_) = foo();
2300(\@a) = foo();
2301\my @c = foo();
2302(\my @d) = foo();
2303(\(@_)) = foo();
2304(\(@a)) = foo();
2305(\(my @g)) = foo();
2306\local @_ = \@_;
2307(\local @_) = \@_;
2308\state @e = [1..3];
2309(\(state @f)) = \3;
2310\our @i = [1..3];
2311(\(our @h)) = \3;
2312\%_ = foo();
2313\%h = foo();
2314(\%_) = foo();
2315(\%h) = foo();
2316\my %c = foo();
2317(\my %d) = foo();
2318\local %_ = \%h;
2319(\local %_) = \%h;
2320\state %y = {1, 2};
2321\our %z = {1, 2};
2322(\our %zz) = {1, 2};
2323\&a = foo();
2324(\&a) = foo();
2325(\&a) = foo();
2326{
2327 my sub a;
2328 \&a = foo();
2329 (\&a) = foo();
2330 (\&a) = foo();
2331}
2332(\$_, $_) = \(1, 2);
2333$_ == 3 ? \$_ : $_ = \3;
2334$_ == 3 ? \$_ : \$x = \3;
2335($_ == 3 ? \$_ : \$x) = \3;
2336foreach \my $topic (\$1, \$2) {
2337 die;
2338}
2339foreach \state $topic (\$1, \$2) {
2340 die;
2341}
2342foreach \our $topic (\$1, \$2) {
2343 die;
2344}
2345foreach \$_ (\$1, \$2) {
2346 die;
2347}
2348foreach \my @a ([1, 2], [3, 4]) {
2349 die;
2350}
2351foreach \state @a ([1, 2], [3, 4]) {
2352 die;
2353}
2354foreach \our @a ([1, 2], [3, 4]) {
2355 die;
2356}
2357foreach \@_ ([1, 2], [3, 4]) {
2358 die;
2359}
2360foreach \my %a ({5, 6}, {7, 8}) {
2361 die;
2362}
2363foreach \our %a ({5, 6}, {7, 8}) {
2364 die;
2365}
2366foreach \state %a ({5, 6}, {7, 8}) {
2367 die;
2368}
2369foreach \%_ ({5, 6}, {7, 8}) {
2370 die;
2371}
2372{
2373 my sub a;
2374 foreach \&a (sub { 9; } , sub { 10; } ) {
2375 die;
2376 }
2377}
2378foreach \&a (sub { 9; } , sub { 10; } ) {
2379 die;
2380}
3b4e2a4d
FC
2381####
2382# join $foo, pos
2383my $foo;
2384$_ = join $foo, pos
2385>>>>
2386my $foo;
2387$_ = join('???', pos $_);
fedf30e1
DM
2388####
2389# exists $a[0]
2390our @a;
2391exists $a[0];
2392####
2393# my @a; exists $a[0]
2394my @a;
2395exists $a[0];
2396####
2397# delete $a[0]
2398our @a;
2399delete $a[0];
2400####
2401# my @a; delete $a[0]
2402my @a;
2403delete $a[0];
2404####
2405# $_[0][$_[1]]
2406$_[0][$_[1]];
2407####
2408# f($a[0]);
2409my @a;
2410f($a[0]);
2411####
2412#qr/\Q$h{'key'}\E/;
2413my %h;
2414qr/\Q$h{'key'}\E/;
2415####
2416# my $x = "$h{foo}";
2417my %h;
2418my $x = "$h{'foo'}";
2419####
2420# weird constant hash key
2421my %h;
2422my $x = $h{"\000\t\x{100}"};
2423####
2424# multideref and packages
2425package foo;
2426my(%bar) = ('a', 'b');
2427our(@bar) = (1, 2);
2428$bar{'k'} = $bar[200];
2429$main::bar{'k'} = $main::bar[200];
2430$foo::bar{'k'} = $foo::bar[200];
2431package foo2;
2432$bar{'k'} = $bar[200];
2433$main::bar{'k'} = $main::bar[200];
2434$foo::bar{'k'} = $foo::bar[200];
2435>>>>
2436package foo;
2437my(%bar) = ('a', 'b');
2438our(@bar) = (1, 2);
2439$bar{'k'} = $bar[200];
2440$main::bar{'k'} = $main::bar[200];
2441$foo::bar{'k'} = $bar[200];
2442package foo2;
2443$bar{'k'} = $foo::bar[200];
2444$main::bar{'k'} = $main::bar[200];
2445$foo::bar{'k'} = $foo::bar[200];
2446####
2447# multideref and local
2448my %h;
2449local $h{'foo'}[0] = 1;
2450####
2451# multideref and exists
2452my(%h, $i);
2453my $e = exists $h{'foo'}[$i];
2454####
2455# multideref and delete
2456my(%h, $i);
2457my $e = delete $h{'foo'}[$i];
2458####
2459# multideref with leading expression
2460my $r;
9527dbdd 2461my $x = +($r // [])->{'foo'}[0];
fedf30e1
DM
2462####
2463# multideref with complex middle index
2464my(%h, $i, $j, $k);
2465my $x = $h{'foo'}[$i + $j]{$k};
0175f038 2466####
9527dbdd
DM
2467# multideref with trailing non-simple index that initially looks simple
2468# (i.e. the constant "3")
2469my($r, $i, $j, $k);
2470my $x = +($r || {})->{'foo'}[$i + $j]{3 + $k};
2471####
3c4a43a5
FC
2472# chdir
2473chdir 'file';
0175f038 2474chdir FH;
3c4a43a5 2475chdir;
27f31adf
FC
2476####
2477# 5.22 bitops
2478# CONTEXT use feature "bitwise"; no warnings "experimental::bitwise";
2479$_ = $_ | $_;
2480$_ = $_ & $_;
2481$_ = $_ ^ $_;
2482$_ = ~$_;
2483$_ = $_ |. $_;
2484$_ = $_ &. $_;
2485$_ = $_ ^. $_;
2486$_ = ~.$_;
2487$_ |= $_;
2488$_ &= $_;
2489$_ ^= $_;
2490$_ |.= $_;
2491$_ &.= $_;
2492$_ ^.= $_;