X-Git-Url: https://perl5.git.perl.org/perl5.git/blobdiff_plain/7921d0f22732c0609e6c9d21be9aaf6e52f99e6b..02a7a248fa1942d10cc4d2479e0f47432d239322:/t/lib/warnings/op diff --git a/t/lib/warnings/op b/t/lib/warnings/op index c39a7b2..009a102 100644 --- a/t/lib/warnings/op +++ b/t/lib/warnings/op @@ -1,13 +1,14 @@ op.c AOK + Use of my $_ is experimental + my $_ ; + Found = in conditional, should be == 1 if $a = 1 ; - Use of implicit split to @_ is deprecated - split ; - - Use of implicit split to @_ is deprecated - $a = split ; + Scalar value %.*s better written as $%.*s" + @a[3] = 2; + @a{3} = 2; Useless use of time in void context Useless use of a variable in void context @@ -60,25 +61,34 @@ format FRED = . - Array @%s missing the @ in argument %d of %s() - push fred ; - - Hash %%%s missing the %% in argument %d of %s() - keys joe ; + push on reference is experimental [ck_fun] + pop on reference is experimental + shift on reference is experimental + unshift on reference is experimental + splice on reference is experimental Statement unlikely to be reached (Maybe you meant system() when you said exec()? exec "true" ; my $a - defined(@array) is deprecated - (Maybe you should just omit the defined()?) + Can't use defined(@array) (Maybe you should just omit the defined()?) my @a ; defined @a ; defined (@a = (1,2,3)) ; - defined(%hash) is deprecated - (Maybe you should just omit the defined()?) + Can't use defined(%hash) (Maybe you should just omit the defined()?) my %h ; defined %h ; - + + "my %s" used in sort comparison + + $[ used in comparison (did you mean $] ?) + + each on reference is experimental [ck_each] + keys on reference is experimental + values on reference is experimental + + length() used on @array (did you mean "scalar(@array)"?) + length() used on %hash (did you mean "scalar(keys %hash)"?) + /---/ should probably be written as "---" join(/---/, @foo); @@ -86,7 +96,7 @@ fred() ; sub fred ($$) {} - Package `%s' not found (did you use the incorrect case?) + Package '%s' not found (did you use the incorrect case?) Use of /g modifier is meaningless in split @@ -98,68 +108,256 @@ sub fred() ; sub fred($) {} - Runaway prototype [newSUB] TODO oops: oopsAV [oopsAV] TODO oops: oopsHV [oopsHV] TODO __END__ # op.c +use warnings 'experimental::lexical_topic' ; +my $_; +CORE::state $_; +no warnings 'experimental::lexical_topic' ; +my $_; +CORE::state $_; +EXPECT +Use of my $_ is experimental at - line 3. +Use of state $_ is experimental at - line 4. +######## +# op.c use warnings 'syntax' ; 1 if $a = 1 ; +1 if $a + = 1 ; no warnings 'syntax' ; 1 if $a = 1 ; +1 if $a + = 1 ; EXPECT Found = in conditional, should be == at - line 3. +Found = in conditional, should be == at - line 4. ######## # op.c -use warnings 'deprecated' ; -split ; -no warnings 'deprecated' ; -split ; +use warnings 'syntax' ; +use constant foo => 1; +1 if $a = foo ; +no warnings 'syntax' ; +1 if $a = foo ; EXPECT -Use of implicit split to @_ is deprecated at - line 3. ######## # op.c -use warnings 'deprecated' ; -$a = split ; -no warnings 'deprecated' ; -$a = split ; +use warnings 'syntax' ; +@a[3]; +@a{3}; +@a["]"]; +@a{"]"}; +@a["}"]; +@a{"}"}; +@a{$_}; +@a{--$_}; +@a[$_]; +@a[--$_]; +no warnings 'syntax' ; +@a[3]; +@a{3}; EXPECT -Use of implicit split to @_ is deprecated at - line 3. +Scalar value @a[3] better written as $a[3] at - line 3. +Scalar value @a{3} better written as $a{3} at - line 4. +Scalar value @a["]"] better written as $a["]"] at - line 5. +Scalar value @a{"]"} better written as $a{"]"} at - line 6. +Scalar value @a["}"] better written as $a["}"] at - line 7. +Scalar value @a{"}"} better written as $a{"}"} at - line 8. +Scalar value @a{...} better written as $a{...} at - line 9. +Scalar value @a{...} better written as $a{...} at - line 10. +Scalar value @a[...] better written as $a[...] at - line 11. +Scalar value @a[...] better written as $a[...] at - line 12. ######## # op.c -use warnings 'deprecated'; -my (@foo, %foo); -%main::foo->{"bar"}; -%foo->{"bar"}; -@main::foo->[23]; -@foo->[23]; -$main::foo = {}; %$main::foo->{"bar"}; -$foo = {}; %$foo->{"bar"}; -$main::foo = []; @$main::foo->[34]; -$foo = []; @$foo->[34]; -no warnings 'deprecated'; +use utf8; +use open qw( :utf8 :std ); +use warnings 'syntax' ; +@à[3]; +@à{3}; +no warnings 'syntax' ; +@à[3]; +@à{3}; +EXPECT +Scalar value @à[3] better written as $à[3] at - line 5. +Scalar value @à{3} better written as $à{3} at - line 6. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +use warnings 'syntax' ; +@ぁ[3]; +@ぁ{3}; +no warnings 'syntax' ; +@ぁ[3]; +@ぁ{3}; +EXPECT +Scalar value @ぁ[3] better written as $ぁ[3] at - line 5. +Scalar value @ぁ{3} better written as $ぁ{3} at - line 6. +######## +# op.c +# "Scalar value better written as" false positives +# [perl #28380] and [perl #114024] +use warnings 'syntax'; + +# hashes +@h{qw"a b c"} = 1..3; +@h{qw'a b c'} = 1..3; +@h{qw$a b c$} = 1..3; +@h{qw-a b c-} = 1..3; +@h{qw#a b c#} = 1..3; +@h{ qw#a b c#} = 1..3; +@h{ qw#a b c#} = 1..3; # tab before qw +@h{qw "a"}; +@h{ qw "a"}; +@h{ qw "a"}; +sub foo() { qw/abc def ghi/ } +@X{+foo} = ( 1 .. 3 ); +$_ = "abc"; @X{split ""} = ( 1 .. 3 ); +my @s = @f{"}", "a"}; +my @s = @f{"]", "a"}; +@a{$],0}; +@_{0} = /(.*)/; +@h{m "$re"}; +@h{qx ""} if 0; +@h{glob ""}; +@h{readline ""}; +@h{m ""}; +use constant phoo => 1..3; +@h{+phoo}; # rv2av +@h{sort foo}; +@h{reverse foo}; +@h{caller 0}; +@h{lstat ""}; +@h{stat ""}; +@h{readdir ""}; +@h{system ""} if 0; +@h{+times} if 0; +@h{localtime 0}; +@h{gmtime 0}; +@h{eval ""}; +{ + no warnings 'experimental::autoderef'; + @h{each $foo} if 0; + @h{keys $foo} if 0; + @h{values $foo} if 0; +} + +# arrays +@h[qw"a b c"] = 1..3; +@h[qw'a b c'] = 1..3; +@h[qw$a b c$] = 1..3; +@h[qw-a b c-] = 1..3; +@h[qw#a b c#] = 1..3; +@h[ qw#a b c#] = 1..3; +@h[ qw#a b c#] = 1..3; # tab before qw +@h[qw "a"]; +@h[ qw "a"]; +@h[ qw "a"]; +sub foo() { qw/abc def ghi/ } +@X[+foo] = ( 1 .. 3 ); +$_ = "abc"; @X[split ""] = ( 1 .. 3 ); +my @s = @f["}", "a"]; +my @s = @f["]", "a"]; +@a[$],0]; +@_[0] = /(.*)/; +@h[m "$re"]; +@h[qx ""] if 0; +@h[glob ""]; +@h[readline ""]; +@h[m ""]; +use constant phoo => 1..3; +@h[+phoo]; # rv2av +@h[sort foo]; +@h[reverse foo]; +@h[caller 0]; +@h[lstat ""]; +@h[stat ""]; +@h[readdir ""]; +@h[system ""] if 0; +@h[+times] if 0; +@h[localtime 0]; +@h[gmtime 0]; +@h[eval ""]; +{ + no warnings 'experimental::autoderef'; + @h[each $foo] if 0; + @h[keys $foo] if 0; + @h[values $foo] if 0; +} +EXPECT +######## +# op.c +# "Scalar value better written as" should not trigger for syntax errors +use warnings 'syntax'; +@a[] +EXPECT +syntax error at - line 4, near "[]" +Execution of - aborted due to compilation errors. +######## +# op.c +my %foo; %main::foo->{"bar"}; +EXPECT +OPTION fatal +Can't use a hash as a reference at - line 3. +######## +# op.c +my %foo; %foo->{"bar"}; +EXPECT +OPTION fatal +Can't use a hash as a reference at - line 3. +######## +# op.c +my @foo; @main::foo->[23]; +EXPECT +OPTION fatal +Can't use an array as a reference at - line 3. +######## +# op.c +my @foo; @foo->[23]; +EXPECT +OPTION fatal +Can't use an array as a reference at - line 3. +######## +# op.c +my %foo; $main::foo = {}; %$main::foo->{"bar"}; +EXPECT +OPTION fatal +Can't use a hash as a reference at - line 3. +######## +# op.c +my %foo; $foo = {}; %$foo->{"bar"}; +EXPECT +OPTION fatal +Can't use a hash as a reference at - line 3. +######## +# op.c +my @foo; $main::foo = []; @$main::foo->[34]; +EXPECT +OPTION fatal +Can't use an array as a reference at - line 3. +######## +# op.c +my @foo; $foo = []; @$foo->[34]; EXPECT -Using a hash as a reference is deprecated at - line 4. -Using a hash as a reference is deprecated at - line 5. -Using an array as a reference is deprecated at - line 6. -Using an array as a reference is deprecated at - line 7. -Using a hash as a reference is deprecated at - line 8. -Using a hash as a reference is deprecated at - line 9. -Using an array as a reference is deprecated at - line 10. -Using an array as a reference is deprecated at - line 11. +OPTION fatal +Can't use an array as a reference at - line 3. ######## # op.c -use warnings 'void' ; close STDIN ; -1 x 3 ; # OP_REPEAT +use warnings 'void' ; no warnings 'experimental::smartmatch'; close STDIN ; +#line 2 +1 x 3 ; # OP_REPEAT (folded) +(1) x 3 ; # OP_REPEAT # OP_GVSV wantarray ; # OP_WANTARRAY # OP_GV @@ -169,7 +367,7 @@ wantarray ; # OP_WANTARRAY # OP_PADANY # OP_AV2ARYLEN ref ; # OP_REF -\@a ; # OP_REFGEN +\(@a) ; # OP_REFGEN \$a ; # OP_SREFGEN defined $a ; # OP_DEFINED hex $a ; # OP_HEX @@ -189,7 +387,7 @@ $a{0} ; # OP_HELEM @a{0} ; # OP_HSLICE unpack "a", "a" ; # OP_UNPACK pack $a,"" ; # OP_PACK -join "" ; # OP_JOIN +join "", @_ ; # OP_JOIN (@a)[0,1] ; # OP_LSLICE # OP_ANONLIST # OP_ANONHASH @@ -211,7 +409,17 @@ eval { getgrgid 1 }; # OP_GGRGID eval { getpwnam 1 }; # OP_GPWNAM eval { getpwuid 1 }; # OP_GPWUID prototype "foo"; # OP_PROTOTYPE +$a ~~ $b; # OP_SMARTMATCH +$a <=> $b; # OP_NCMP +"dsatrewq"; +"diatrewq"; +"igatrewq"; +use 5.015; +__SUB__ ; # OP_RUNCV +[]; # OP_ANONLIST +grep /42/, (1,2); # OP_GREP, not warned about, in the "everything" & "void_unusual" category EXPECT +Useless use of a constant ("111") in void context at - line 2. Useless use of repeat (x) in void context at - line 3. Useless use of wantarray in void context at - line 5. Useless use of reference-type operator in void context at - line 12. @@ -250,6 +458,24 @@ Useless use of getgrgid in void context at - line 51. Useless use of getpwnam in void context at - line 52. Useless use of getpwuid in void context at - line 53. Useless use of subroutine prototype in void context at - line 54. +Useless use of smart match in void context at - line 55. +Useless use of numeric comparison (<=>) in void context at - line 56. +Useless use of a constant ("dsatrewq") in void context at - line 57. +Useless use of a constant ("diatrewq") in void context at - line 58. +Useless use of a constant ("igatrewq") in void context at - line 59. +Useless use of __SUB__ in void context at - line 61. +Useless use of anonymous array ([]) in void context at - line 62. +######## +# op.c +use warnings 'void_unusual' ; close STDIN ; +grep /42/, (1,2); # OP_GREP +no warnings 'void_unusual'; +grep /42/, (1,2); # OP_GREP +use warnings 'everything'; +grep /42/, (1,2); # OP_GREP +EXPECT +Unusual use of grep in void context at - line 3. +Unusual use of grep in void context at - line 7. ######## # op.c use warnings 'void' ; close STDIN ; @@ -525,35 +751,71 @@ Useless use of a variable in void context at - line 6. use warnings 'void' ; "abc"; # OP_CONST 7 ; # OP_CONST -5 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT +"x" . "y"; # optimized to OP_CONST +2 + 2; # optimized to OP_CONST use constant U => undef; +U; +qq/" \n/; +5 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT print "boo\n" if U; # test OPpCONST_SHORTCIRCUIT +if($foo){}elsif(""){} # test OPpCONST_SHORTCIRCUIT no warnings 'void' ; "abc"; # OP_CONST 7 ; # OP_CONST +"x" . "y"; # optimized to OP_CONST +2 + 2; # optimized to OP_CONST +EXPECT +Useless use of a constant ("abc") in void context at - line 3. +Useless use of a constant (7) in void context at - line 4. +Useless use of a constant ("xy") in void context at - line 5. +Useless use of a constant (4) in void context at - line 6. +Useless use of a constant (undef) in void context at - line 8. +Useless use of a constant ("\"\t\n") in void context at - line 9. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +use warnings 'void' ; +"àḆc"; # OP_CONST +"Ẋ" . "ƴ"; # optimized to OP_CONST +FOO; # Bareword optimized to OP_CONST +use constant ů => undef; +ů; +5 || print "bad\n"; # test OPpCONST_SHORTCIRCUIT +print "boo\n" if ů; # test OPpCONST_SHORTCIRCUIT +no warnings 'void' ; +"àḆc"; # OP_CONST +"Ẋ" . "ƴ"; # optimized to OP_CONST EXPECT -Useless use of a constant in void context at - line 3. -Useless use of a constant in void context at - line 4. +Useless use of a constant ("\340\x{1e06}c") in void context at - line 5. +Useless use of a constant ("\x{1e8a}\x{1b4}") in void context at - line 6. +Useless use of a constant ("\x{ff26}\x{ff2f}\x{ff2f}") in void context at - line 7. +Useless use of a constant (undef) in void context at - line 9. ######## # op.c # -use warnings 'misc' ; -my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; +use warnings 'misc' ; use utf8; +my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ;my $d = 'test'; @a =~ /abc/ ; -@a =~ s/a/b/ ; -@a =~ tr/a/b/ ; +@a2 =~ s/a/b/ ; +@a3 =~ tr/a/b/ ; @$b =~ /abc/ ; @$b =~ s/a/b/ ; @$b =~ tr/a/b/ ; %a =~ /abc/ ; -%a =~ s/a/b/ ; -%a =~ tr/a/b/ ; +%a2 =~ s/a/b/ ; +%a3 =~ tr/a/b/ ; %$c =~ /abc/ ; %$c =~ s/a/b/ ; %$c =~ tr/a/b/ ; +$d =~ tr/a/b/d ; +$d2 =~ tr/a/bc/; +$d3 =~ tr//b/c; +$d =~ tr/α/β/d ; +$d2 =~ tr/α/βγ/; { no warnings 'misc' ; -my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; +my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; my $d = 'test'; @a =~ /abc/ ; @a =~ s/a/b/ ; @a =~ tr/a/b/ ; @@ -566,22 +828,29 @@ my $a ; my @a = () ; my %a = () ; my $b = \@a ; my $c = \%a ; %$c =~ /abc/ ; %$c =~ s/a/b/ ; %$c =~ tr/a/b/ ; +$d =~ tr/a/b/d ; +$d =~ tr/a/bc/ ; +$d =~ tr//b/c; } EXPECT -Applying pattern match (m//) to @array will act on scalar(@array) at - line 5. -Applying substitution (s///) to @array will act on scalar(@array) at - line 6. -Applying transliteration (tr///) to @array will act on scalar(@array) at - line 7. +Applying pattern match (m//) to @a will act on scalar(@a) at - line 5. +Applying substitution (s///) to @a2 will act on scalar(@a2) at - line 6. +Applying transliteration (tr///) to @a3 will act on scalar(@a3) at - line 7. Applying pattern match (m//) to @array will act on scalar(@array) at - line 8. Applying substitution (s///) to @array will act on scalar(@array) at - line 9. Applying transliteration (tr///) to @array will act on scalar(@array) at - line 10. -Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 11. -Applying substitution (s///) to %hash will act on scalar(%hash) at - line 12. -Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 13. +Applying pattern match (m//) to %a will act on scalar(%a) at - line 11. +Applying substitution (s///) to %a2 will act on scalar(%a2) at - line 12. +Applying transliteration (tr///) to %a3 will act on scalar(%a3) at - line 13. Applying pattern match (m//) to %hash will act on scalar(%hash) at - line 14. Applying substitution (s///) to %hash will act on scalar(%hash) at - line 15. Applying transliteration (tr///) to %hash will act on scalar(%hash) at - line 16. -Can't modify private array in substitution (s///) at - line 6, near "s/a/b/ ;" -BEGIN not safe after errors--compilation aborted at - line 18. +Useless use of /d modifier in transliteration operator at - line 17. +Replacement list is longer than search list at - line 18. +Useless use of /d modifier in transliteration operator at - line 20. +Replacement list is longer than search list at - line 21. +Can't modify array dereference in substitution (s///) at - line 6, near "s/a/b/ ;" +BEGIN not safe after errors--compilation aborted at - line 23. ######## # op.c use warnings 'parenthesis' ; @@ -627,28 +896,43 @@ Bareword found in conditional at - line 3. use warnings 'misc' ; open FH, " ; +$x = 1 if $x + = ; no warnings 'misc' ; $x = 1 if $x = ; +$x = 1 if $x + = ; EXPECT Value of construct can be "0"; test with defined() at - line 4. +Value of construct can be "0"; test with defined() at - line 5. ######## # op.c use warnings 'misc' ; opendir FH, "." ; $x = 1 if $x = readdir FH ; +$x = 1 if $x + = readdir FH ; no warnings 'misc' ; $x = 1 if $x = readdir FH ; +$x = 1 if $x + = readdir FH ; closedir FH ; EXPECT Value of readdir() operator can be "0"; test with defined() at - line 4. +Value of readdir() operator can be "0"; test with defined() at - line 5. ######## # op.c use warnings 'misc' ; $x = 1 if $x = <*> ; +$x = 1 if $x + = <*> ; no warnings 'misc' ; $x = 1 if $x = <*> ; +$x = 1 if $x + = <*> ; EXPECT Value of glob construct can be "0"; test with defined() at - line 3. +Value of glob construct can be "0"; test with defined() at - line 4. ######## # op.c use warnings 'misc' ; @@ -680,23 +964,24 @@ Value of readdir() operator can be "0"; test with defined() at - line 4. # op.c use warnings 'misc'; open FH, " err $_ = 1; ($_ = ) // ($_ = 1); opendir DH, "."; -$_ = readdir DH err $_ = 1; -$_ = <*> err $_ = 1; %a = (1,2,3,4) ; -$_ = each %a err $_ = 1; EXPECT ######## # op.c use warnings 'redefine' ; sub fred {} sub fred {} +sub fred { # warning should be for this line +} no warnings 'redefine' ; sub fred {} +sub fred { +} EXPECT Subroutine fred redefined at - line 4. +Subroutine fred redefined at - line 5. ######## # op.c use warnings 'redefine' ; @@ -708,18 +993,50 @@ EXPECT Constant subroutine fred redefined at - line 4. ######## # op.c -no warnings 'redefine' ; sub fred () { 1 } sub fred () { 2 } EXPECT +Constant subroutine fred redefined at - line 3. +######## +# op.c +sub fred () { 1 } +*fred = sub () { 2 }; +EXPECT +Constant subroutine main::fred redefined at - line 3. +######## +# op.c +use feature "lexical_subs", "state"; +my sub fred () { 1 } +sub fred { 2 }; +my sub george { 1 } +sub george () { 2 } # should *not* produce redef warnings by default +state sub phred () { 1 } +sub phred { 2 }; +state sub jorge { 1 } +sub jorge () { 2 } # should *not* produce redef warnings by default +EXPECT +The lexical_subs feature is experimental at - line 3. +Prototype mismatch: sub fred () vs none at - line 4. Constant subroutine fred redefined at - line 4. +The lexical_subs feature is experimental at - line 5. +Prototype mismatch: sub george: none vs () at - line 6. +The lexical_subs feature is experimental at - line 7. +Prototype mismatch: sub phred () vs none at - line 8. +Constant subroutine phred redefined at - line 8. +The lexical_subs feature is experimental at - line 9. +Prototype mismatch: sub jorge: none vs () at - line 10. +######## +# op.c +no warnings 'redefine' ; +sub fred () { 1 } +sub fred () { 2 } +EXPECT ######## # op.c no warnings 'redefine' ; sub fred () { 1 } *fred = sub () { 2 }; EXPECT -Constant subroutine main::fred redefined at - line 4. ######## # op.c use warnings 'redefine' ; @@ -733,71 +1050,70 @@ format FRED = EXPECT Format FRED redefined at - line 5. ######## -# op.c -use warnings 'deprecated' ; -push FRED; -no warnings 'deprecated' ; -push FRED; -EXPECT -Array @FRED missing the @ in argument 1 of push() at - line 3. -######## -# op.c -use warnings 'deprecated' ; -@a = keys FRED ; -no warnings 'deprecated' ; -@a = keys FRED ; +# op.c [Perl_ck_fun] +$fred = []; +push $fred; +pop $fred; +shift $fred; +unshift $fred; +splice $fred; +no warnings 'experimental::autoderef' ; +push $fred; +pop $fred; +shift $fred; +unshift $fred; +splice $fred; EXPECT -Hash %FRED missing the % in argument 1 of keys() at - line 3. +push on reference is experimental at - line 3. +pop on reference is experimental at - line 4. +shift on reference is experimental at - line 5. +unshift on reference is experimental at - line 6. +splice on reference is experimental at - line 7. ######## # op.c -BEGIN { - if ($^O eq 'MacOS') { - print <bar; sub foo(@); +use constant bav=>bar; sub bav(); # no warning +sub btu; sub btu(); EXPECT Prototype mismatch: sub main::fred () vs ($) at - line 3. +Prototype mismatch: sub foo () vs (@) at - line 4. +Prototype mismatch: sub btu: none vs () at - line 6. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +sub frèd(); +sub frèd($) {} +EXPECT +Prototype mismatch: sub main::frèd () vs ($) at - line 5. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +use warnings; +eval "sub fòò (@\$\0) {}"; +EXPECT +Prototype after '@' for main::fòò : @$\0 at (eval 1) line 1. +Illegal character in prototype for main::fòò : @$\0 at (eval 1) line 1. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +use warnings; +eval "sub foo (@\0) {}"; +EXPECT +Prototype after '@' for main::foo : @\0 at (eval 1) line 1. +Illegal character in prototype for main::foo : @\0 at (eval 1) line 1. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +use warnings; +BEGIN { $::{"foo"} = "\@\$\0L\351on" } +BEGIN { eval "sub foo (@\$\0L\x{c3}\x{a9}on) {}"; } +EXPECT +Prototype after '@' for main::foo : @$\x{0}L... at (eval 1) line 1. +Illegal character in prototype for main::foo : @$\x{0}L... at (eval 1) line 1. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +use warnings; +BEGIN { eval "sub foo (@\0) {}"; } +EXPECT +Prototype after '@' for main::foo : @\0 at (eval 1) line 1. +Illegal character in prototype for main::foo : @\0 at (eval 1) line 1. +######## +# op.c +use warnings; +eval "sub foo (@\xAB) {}"; +EXPECT +Prototype after '@' for main::foo : @\x{ab} at (eval 1) line 1. +Illegal character in prototype for main::foo : @\x{ab} at (eval 1) line 1. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +use warnings; +BEGIN { eval "sub foo (@\x{30cb}) {}"; } +EXPECT +Prototype after '@' for main::foo : @\x{30cb} at (eval 1) line 1. +Illegal character in prototype for main::foo : @\x{30cb} at (eval 1) line 1. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +use warnings; +BEGIN { $::{"foo"} = "\x{30cb}" } +BEGIN { eval "sub foo {}"; } +EXPECT +Prototype mismatch: sub main::foo (ニ) vs none at (eval 1) line 1. ######## # op.c $^W = 0 ; @@ -828,12 +1219,217 @@ Prototype mismatch: sub main::fred () vs ($) at - line 4. Prototype mismatch: sub main::freD () vs ($) at - line 11. Prototype mismatch: sub main::FRED () vs ($) at - line 14. ######## +# op.c [S_simplify_sort] +# [perl #86136] +my @tests = split /^/, ' + sort {$a <=> $b} @a; + sort {$a cmp $b} @a; + { use integer; sort {$a <=> $b} @a} + sort {$b <=> $a} @a; + sort {$b cmp $a} @a; + { use integer; sort {$b <=> $a} @a} +'; +for my $pragma ('use warnings "syntax";', '') { + for my $vars ('', 'my $a;', 'my $b;', 'my ($a,$b);') { + for my $inner_stmt ('', 'print;', 'func();') { + eval "#line " . ++$line . "01 -\n$pragma\n$vars" + . join "", map s/sort \{\K/$inner_stmt/r, @tests; + $@ and die; + } + } +} +sub func{} +use warnings 'syntax'; +my $a; +# These used to be errors! +sort { ; } $a <=> $b; +sort { ; } $a, "<=>"; +sort { ; } $a, $cmp; +sort $a, $b if $cmpany_name; +sort if $a + $cmp; +sort @t; $a + $cmp; +EXPECT +"my $a" used in sort comparison at - line 403. +"my $a" used in sort comparison at - line 404. +"my $a" used in sort comparison at - line 405. +"my $a" used in sort comparison at - line 406. +"my $a" used in sort comparison at - line 407. +"my $a" used in sort comparison at - line 408. +"my $a" used in sort comparison at - line 503. +"my $a" used in sort comparison at - line 504. +"my $a" used in sort comparison at - line 505. +"my $a" used in sort comparison at - line 506. +"my $a" used in sort comparison at - line 507. +"my $a" used in sort comparison at - line 508. +"my $a" used in sort comparison at - line 603. +"my $a" used in sort comparison at - line 604. +"my $a" used in sort comparison at - line 605. +"my $a" used in sort comparison at - line 606. +"my $a" used in sort comparison at - line 607. +"my $a" used in sort comparison at - line 608. +"my $b" used in sort comparison at - line 703. +"my $b" used in sort comparison at - line 704. +"my $b" used in sort comparison at - line 705. +"my $b" used in sort comparison at - line 706. +"my $b" used in sort comparison at - line 707. +"my $b" used in sort comparison at - line 708. +"my $b" used in sort comparison at - line 803. +"my $b" used in sort comparison at - line 804. +"my $b" used in sort comparison at - line 805. +"my $b" used in sort comparison at - line 806. +"my $b" used in sort comparison at - line 807. +"my $b" used in sort comparison at - line 808. +"my $b" used in sort comparison at - line 903. +"my $b" used in sort comparison at - line 904. +"my $b" used in sort comparison at - line 905. +"my $b" used in sort comparison at - line 906. +"my $b" used in sort comparison at - line 907. +"my $b" used in sort comparison at - line 908. +"my $a" used in sort comparison at - line 1003. +"my $b" used in sort comparison at - line 1003. +"my $a" used in sort comparison at - line 1004. +"my $b" used in sort comparison at - line 1004. +"my $a" used in sort comparison at - line 1005. +"my $b" used in sort comparison at - line 1005. +"my $b" used in sort comparison at - line 1006. +"my $a" used in sort comparison at - line 1006. +"my $b" used in sort comparison at - line 1007. +"my $a" used in sort comparison at - line 1007. +"my $b" used in sort comparison at - line 1008. +"my $a" used in sort comparison at - line 1008. +"my $a" used in sort comparison at - line 1103. +"my $b" used in sort comparison at - line 1103. +"my $a" used in sort comparison at - line 1104. +"my $b" used in sort comparison at - line 1104. +"my $a" used in sort comparison at - line 1105. +"my $b" used in sort comparison at - line 1105. +"my $b" used in sort comparison at - line 1106. +"my $a" used in sort comparison at - line 1106. +"my $b" used in sort comparison at - line 1107. +"my $a" used in sort comparison at - line 1107. +"my $b" used in sort comparison at - line 1108. +"my $a" used in sort comparison at - line 1108. +"my $a" used in sort comparison at - line 1203. +"my $b" used in sort comparison at - line 1203. +"my $a" used in sort comparison at - line 1204. +"my $b" used in sort comparison at - line 1204. +"my $a" used in sort comparison at - line 1205. +"my $b" used in sort comparison at - line 1205. +"my $b" used in sort comparison at - line 1206. +"my $a" used in sort comparison at - line 1206. +"my $b" used in sort comparison at - line 1207. +"my $a" used in sort comparison at - line 1207. +"my $b" used in sort comparison at - line 1208. +"my $a" used in sort comparison at - line 1208. +######## +# op.c [S_simplify_sort] +use warnings 'syntax'; use 5.01; +state $a; +sort { $a <=> $b } (); +EXPECT +"state $a" used in sort comparison at - line 4. +######## +# op.c [Perl_ck_cmp] +use warnings 'syntax' ; +no warnings 'deprecated'; +@a = $[ < 5; +@a = $[ > 5; +@a = $[ <= 5; +@a = $[ >= 5; +@a = 42 < $[; +@a = 42 > $[; +@a = 42 <= $[; +@a = 42 >= $[; +use integer; +@a = $[ < 5; +@a = $[ > 5; +@a = $[ <= 5; +@a = $[ >= 5; +@a = 42 < $[; +@a = 42 > $[; +@a = 42 <= $[; +@a = 42 >= $[; +no integer; +@a = $[ < $5; +@a = $[ > $5; +@a = $[ <= $5; +@a = $[ >= $5; +@a = $42 < $[; +@a = $42 > $[; +@a = $42 <= $[; +@a = $42 >= $[; +use integer; +@a = $[ < $5; +@a = $[ > $5; +@a = $[ <= $5; +@a = $[ >= $5; +@a = $42 < $[; +@a = $42 > $[; +@a = $42 <= $[; +@a = $42 >= $[; +EXPECT +$[ used in numeric lt (<) (did you mean $] ?) at - line 4. +$[ used in numeric gt (>) (did you mean $] ?) at - line 5. +$[ used in numeric le (<=) (did you mean $] ?) at - line 6. +$[ used in numeric ge (>=) (did you mean $] ?) at - line 7. +$[ used in numeric lt (<) (did you mean $] ?) at - line 8. +$[ used in numeric gt (>) (did you mean $] ?) at - line 9. +$[ used in numeric le (<=) (did you mean $] ?) at - line 10. +$[ used in numeric ge (>=) (did you mean $] ?) at - line 11. +$[ used in numeric lt (<) (did you mean $] ?) at - line 13. +$[ used in numeric gt (>) (did you mean $] ?) at - line 14. +$[ used in numeric le (<=) (did you mean $] ?) at - line 15. +$[ used in numeric ge (>=) (did you mean $] ?) at - line 16. +$[ used in numeric lt (<) (did you mean $] ?) at - line 17. +$[ used in numeric gt (>) (did you mean $] ?) at - line 18. +$[ used in numeric le (<=) (did you mean $] ?) at - line 19. +$[ used in numeric ge (>=) (did you mean $] ?) at - line 20. +######## +# op.c [Perl_ck_each] +$fred = {}; +keys $fred; +values $fred; +each $fred; +no warnings 'experimental::autoderef' ; +keys $fred; +values $fred; +each $fred; +EXPECT +keys on reference is experimental at - line 3. +values on reference is experimental at - line 4. +each on reference is experimental at - line 5. +######## +# op.c [Perl_ck_length] +use warnings 'syntax' ; +length(@a); +length(%b); +length(@$c); +length(%$d); +length($a); +length(my %h); +length(my @g); +EXPECT +length() used on @a (did you mean "scalar(@a)"?) at - line 3. +length() used on %b (did you mean "scalar(keys %b)"?) at - line 4. +length() used on @array (did you mean "scalar(@array)"?) at - line 5. +length() used on %hash (did you mean "scalar(keys %hash)"?) at - line 6. +length() used on %h (did you mean "scalar(keys %h)"?) at - line 8. +length() used on @g (did you mean "scalar(@g)"?) at - line 9. +######## # op.c use warnings 'syntax' ; join /---/, 'x', 'y', 'z'; EXPECT /---/ should probably be written as "---" at - line 3. ######## +# op.c +use utf8; +use open qw( :utf8 :std ); +use warnings 'syntax' ; +join /~~~/, 'x', 'y', 'z'; +EXPECT +/~~~/ should probably be written as "~~~" at - line 5. +######## # op.c [Perl_peep] use warnings 'prototype' ; fred() ; @@ -1055,7 +1651,6 @@ Useless localization of match position at - line 49. Useless localization of vec at - line 50. ######## # op.c -use warnings 'deprecated'; my $x1 if 0; my @x2 if 0; my %x3 if 0; @@ -1071,10 +1666,296 @@ if (my $w2) { $a=1 } if ($a && (my $w3 = 1)) {$a = 2} EXPECT +Deprecated use of my() in false conditional at - line 2. Deprecated use of my() in false conditional at - line 3. Deprecated use of my() in false conditional at - line 4. Deprecated use of my() in false conditional at - line 5. Deprecated use of my() in false conditional at - line 6. Deprecated use of my() in false conditional at - line 7. Deprecated use of my() in false conditional at - line 8. -Deprecated use of my() in false conditional at - line 9. +######## +# op.c +$[ = 1; +($[) = 1; +use warnings 'deprecated'; +$[ = 2; +($[) = 2; +no warnings 'deprecated'; +$[ = 3; +($[) = 3; +EXPECT +Use of assignment to $[ is deprecated at - line 2. +Use of assignment to $[ is deprecated at - line 3. +Use of assignment to $[ is deprecated at - line 5. +Use of assignment to $[ is deprecated at - line 6. +######## +# op.c +use warnings 'void'; +@x = split /y/, "z"; +$x = split /y/, "z"; + split /y/, "z"; +no warnings 'void'; +@x = split /y/, "z"; +$x = split /y/, "z"; + split /y/, "z"; +EXPECT +Useless use of split in void context at - line 5. +######## +# op.c +use warnings 'redefine' ; +use utf8; +use open qw( :utf8 :std ); +sub frèd {} +sub frèd {} +no warnings 'redefine' ; +sub frèd {} +EXPECT +Subroutine frèd redefined at - line 6. +######## +# op.c +use warnings 'redefine' ; +use utf8; +use open qw( :utf8 :std ); +sub frèd () { 1 } +sub frèd () { 1 } +no warnings 'redefine' ; +sub frèd () { 1 } +EXPECT +Constant subroutine frèd redefined at - line 6. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +sub frèd () { 1 } +sub frèd () { 2 } +EXPECT +Constant subroutine frèd redefined at - line 5. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +sub frèd () { 1 } +*frèd = sub () { 2 }; +EXPECT +Constant subroutine main::frèd redefined at - line 5. +######## +# op.c +use warnings 'redefine' ; +use utf8; +use open qw( :utf8 :std ); +sub ᚠርƊ {} +sub ᚠርƊ {} +no warnings 'redefine' ; +sub ᚠርƊ {} +EXPECT +Subroutine ᚠርƊ redefined at - line 6. +######## +# op.c +use warnings 'redefine' ; +use utf8; +use open qw( :utf8 :std ); +sub ᚠርƊ () { 1 } +sub ᚠርƊ () { 1 } +no warnings 'redefine' ; +sub ᚠርƊ () { 1 } +EXPECT +Constant subroutine ᚠርƊ redefined at - line 6. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +sub ᚠርƊ () { 1 } +sub ᚠርƊ () { 2 } +EXPECT +Constant subroutine ᚠርƊ redefined at - line 5. +######## +# op.c +use utf8; +use open qw( :utf8 :std ); +sub ᚠርƊ () { 1 } +*ᚠርƊ = sub () { 2 }; +EXPECT +Constant subroutine main::ᚠርƊ redefined at - line 5. +######## +# OPTION regex +sub DynaLoader::dl_error {}; +use warnings; +# We're testing that the warnings report the same line number: +eval <<'EOC' or die $@; +{ + DynaLoader::boot_DynaLoader("DynaLoader"); +} +EOC +eval <<'EOC' or die $@; +BEGIN { + DynaLoader::boot_DynaLoader("DynaLoader"); +} +1 +EOC +EXPECT +OPTION regex +\ASubroutine DynaLoader::dl_error redefined at \(eval 1\) line 2\. +?(?s).* +Subroutine DynaLoader::dl_error redefined at \(eval 2\) line 2\. +######## +# op.c +use warnings; +sub do_warn_1 { return $a or $b; } +sub do_warn_2 { return $a and $b; } +sub do_warn_3 { return $a xor $b; } +sub do_warn_4 { die $a or $b; } +sub do_warn_5 { die $a and $b; } +sub do_warn_6 { die $a xor $b; } +sub do_warn_7 { exit $a or $b; } +sub do_warn_8 { exit $a and $b; } +sub do_warn_9 { exit $a xor $b; } + +# Since exit is an unary operator, it is even stronger than +# || and &&. +sub do_warn_10 { exit $a || $b; } +sub do_warn_11 { exit $a && $b; } + +sub do_warn_12 { goto $a or $b; } +sub do_warn_13 { goto $a and $b; } +sub do_warn_14 { goto $a xor $b; } +sub do_warn_15 { next $a or $b while(1); } +sub do_warn_16 { next $a and $b while(1); } +sub do_warn_17 { next $a xor $b while(1); } +sub do_warn_18 { last $a or $b while(1); } +sub do_warn_19 { last $a and $b while(1); } +sub do_warn_20 { last $a xor $b while(1); } +sub do_warn_21 { redo $a or $b while(1); } +sub do_warn_22 { redo $a and $b while(1); } +sub do_warn_23 { redo $a xor $b while(1); } +# These get re-written to "(return/die $a) and $b" +sub do_warn_24 { $b if return $a; } +sub do_warn_25 { $b if die $a; } +EXPECT +Possible precedence issue with control flow operator at - line 3. +Possible precedence issue with control flow operator at - line 4. +Possible precedence issue with control flow operator at - line 5. +Possible precedence issue with control flow operator at - line 6. +Possible precedence issue with control flow operator at - line 7. +Possible precedence issue with control flow operator at - line 8. +Possible precedence issue with control flow operator at - line 9. +Possible precedence issue with control flow operator at - line 10. +Possible precedence issue with control flow operator at - line 11. +Possible precedence issue with control flow operator at - line 15. +Possible precedence issue with control flow operator at - line 16. +Possible precedence issue with control flow operator at - line 18. +Possible precedence issue with control flow operator at - line 19. +Possible precedence issue with control flow operator at - line 20. +Possible precedence issue with control flow operator at - line 21. +Possible precedence issue with control flow operator at - line 22. +Possible precedence issue with control flow operator at - line 23. +Possible precedence issue with control flow operator at - line 24. +Possible precedence issue with control flow operator at - line 25. +Possible precedence issue with control flow operator at - line 26. +Possible precedence issue with control flow operator at - line 27. +Possible precedence issue with control flow operator at - line 28. +Possible precedence issue with control flow operator at - line 29. +Possible precedence issue with control flow operator at - line 31. +Possible precedence issue with control flow operator at - line 32. +######## +# op.c +# (same as above, except these should not warn) +use constant FEATURE => 1; +use constant MISSING_FEATURE => 0; + +sub dont_warn_1 { MISSING_FEATURE and return or dont_warn_3(); } +sub dont_warn_2 { FEATURE || return and dont_warn_3(); } +sub dont_warn_3 { not FEATURE and return or dont_warn_3(); } +sub dont_warn_4 { !MISSING_FEATURE || return and dont_warn_3(); } +sub dont_warn_5 { MISSING_FEATURE and die or dont_warn_3(); } +sub dont_warn_6 { FEATURE || die and dont_warn_3(); } +sub dont_warn_7 { not FEATURE and die or dont_warn_3(); } +sub dont_warn_8 { !MISSING_FEATURE || die and dont_warn_3(); } +sub dont_warn_9 { MISSING_FEATURE and goto $a or dont_warn_3(); } +sub dont_warn_10 { FEATURE || goto $a and dont_warn_3(); } +sub dont_warn_11 { not FEATURE and goto $a or dont_warn_3(); } +sub dont_warn_12 { !MISSING_FEATURE || goto $a and dont_warn_3(); } + +sub dont_warn_13 { MISSING_FEATURE and exit $a or dont_warn_3(); } +sub dont_warn_14 { FEATURE || exit $a and dont_warn_3(); } +sub dont_warn_15 { not FEATURE and exit $a or dont_warn_3(); } +sub dont_warn_16 { !MISSING_FEATURE || exit $a and dont_warn_3(); } + +sub dont_warn_17 { MISSING_FEATURE and next or dont_warn_3() while(1); } +sub dont_warn_18 { FEATURE || next and dont_warn_3() while(1); } +sub dont_warn_19 { not FEATURE and next or dont_warn_3() while(1); } +sub dont_warn_20 { !MISSING_FEATURE || next and dont_warn_3() while(1); } +sub dont_warn_21 { MISSING_FEATURE and redo or dont_warn_3() while(1); } +sub dont_warn_22 { FEATURE || redo and dont_warn_3() while(1); } +sub dont_warn_23 { not FEATURE and redo or dont_warn_3() while(1); } +sub dont_warn_24 { !MISSING_FEATURE || redo and dont_warn_3() while(1); } +sub dont_warn_25 { MISSING_FEATURE and last or dont_warn_3() while(1); } +sub dont_warn_26 { FEATURE || last and dont_warn_3() while(1); } +sub dont_warn_27 { not FEATURE and last or dont_warn_3() while(1); } +sub dont_warn_28 { !MISSING_FEATURE || last and dont_warn_3() while(1); } + +# These are weird, but at least not ambiguous. +sub dont_warn_29 { return ($a or $b); } +sub dont_warn_30 { return ($a and $b); } +sub dont_warn_31 { return ($a xor $b); } +sub dont_warn_32 { die ($a or $b); } +sub dont_warn_33 { die ($a and $b); } +sub dont_warn_34 { die ($a xor $b); } +sub dont_warn_35 { goto ($a or $b); } +sub dont_warn_36 { goto ($a and $b); } +sub dont_warn_37 { goto ($a xor $b); } +sub dont_warn_38 { next ($a or $b) while(1); } +sub dont_warn_39 { next ($a and $b) while(1); } +sub dont_warn_40 { next ($a xor $b) while(1); } +sub dont_warn_41 { last ($a or $b) while(1); } +sub dont_warn_42 { last ($a and $b) while(1); } +sub dont_warn_43 { last ($a xor $b) while(1); } +sub dont_warn_44 { redo ($a or $b) while(1); } +sub dont_warn_45 { redo ($a and $b) while(1); } +sub dont_warn_46 { redo ($a xor $b) while(1); } +EXPECT +######## +use feature "signatures"; +sub aaa { 2 } +sub bbb ($a) { 4 } +$aaa = sub { 2 }; +$bbb = sub ($a) { 4 }; +EXPECT +The signatures feature is experimental at - line 3. +The signatures feature is experimental at - line 5. +######## +no warnings "experimental::signatures"; +use feature "signatures"; +sub aaa { 2 } +sub bbb ($a) { 4 } +$aaa = sub { 2 }; +$bbb = sub ($a) { 4 }; +EXPECT +######## +use warnings 'numeric'; +my $c = -4.5; +my $a = "y" x $c; +my $b = "y" x -3; +no warnings 'numeric'; +my $d = "y" x $c; +my $e = "y" x -3; +no warnings 'numeric'; +EXPECT +Negative repeat count does nothing at - line 3. +Negative repeat count does nothing at - line 4. +######## +my $a = "inf" + 0; +my $b = -$a; +my $c = "nan" + 0; +use warnings 'numeric'; +my $x = "x" x $a; +my $y = "y" x $b; +my $z = "z" x $c; +no warnings 'numeric'; +my $x = "x" x $a; +my $y = "y" x $b; +my $z = "z" x $c; +no warnings 'numeric'; +EXPECT +Non-finite repeat count does nothing at - line 5. +Non-finite repeat count does nothing at - line 6. +Non-finite repeat count does nothing at - line 7.