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