This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Remove ‘Runaway prototype’ warning
[perl5.git] / t / lib / warnings / op
index 3c10751..6dfcf5d 100644 (file)
@@ -3,12 +3,6 @@
      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 ;
-
      Useless use of time in void context
      Useless use of a variable in void context
      Useless use of a constant in void context
      defined(%hash) is deprecated
        (Maybe you should just omit the defined()?)
        my %h ; defined %h ;
-    
+
+     $[ used in comparison (did you mean $] ?)
+
+     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 +85,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,7 +97,6 @@
         sub fred() ;
         sub fred($) {}
 
-    Runaway prototype          [newSUB]        TODO
     oops: oopsAV               [oopsAV]        TODO
     oops: oopsHV               [oopsHV]        TODO
     
@@ -112,23 +110,14 @@ EXPECT
 Found = in conditional, should be == at - line 3.
 ########
 # op.c
-use warnings 'deprecated' ;
-split ;
-no warnings 'deprecated' ;
-split ;
-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' ;
+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';
 my (@foo, %foo);
 %main::foo->{"bar"};
 %foo->{"bar"};
@@ -148,14 +137,14 @@ $foo = {}; %$foo->{"bar"};
 $main::foo = []; @$main::foo->[34];
 $foo = []; @$foo->[34];
 EXPECT
+Using a hash as a reference is deprecated at - line 3.
 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 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 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 9.
 Using an array as a reference is deprecated at - line 10.
-Using an array as a reference is deprecated at - line 11.
 ########
 # op.c
 use warnings 'void' ; close STDIN ;
@@ -211,6 +200,10 @@ 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
+use 5.015;
+__SUB__                        # OP_RUNCV
 EXPECT
 Useless use of repeat (x) in void context at - line 3.
 Useless use of wantarray in void context at - line 5.
@@ -250,6 +243,9 @@ 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 __SUB__ in void context at - line 58.
 ########
 # op.c
 use warnings 'void' ; close STDIN ;
@@ -525,36 +521,67 @@ 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
-$[ = 2; # should not warn
 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 in void context at - line 3.
-Useless use of a constant in void context at - line 4.
+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 ("\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 ;
+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/;
 {
 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/ ;
@@ -567,22 +594,26 @@ 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/ ;
 }
 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.
+Can't modify array dereference in substitution (s///) at - line 6, near "s/a/b/ ;"
+BEGIN not safe after errors--compilation aborted at - line 20.
 ########
 # op.c
 use warnings 'parenthesis' ;
@@ -680,15 +711,10 @@ Value of readdir() operator can be "0"; test with defined() at - line 4.
 ########
 # op.c
 use warnings 'misc';
-use feature 'err';
 open FH, "<abc";
-$_ = <FH> err $_ = 1;
 ($_ = <FH>) // ($_ = 1);
 opendir DH, ".";
-$_ = readdir DH err $_ = 1;
-$_ = <*> err $_ = 1;
 %a = (1,2,3,4) ;
-$_ = each %a err $_ = 1;
 EXPECT
 ########
 # op.c
@@ -710,18 +736,28 @@ EXPECT
 Constant subroutine fred redefined at - line 4.
 ########
 # op.c
+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
 no warnings 'redefine' ;
 sub fred () { 1 }
 sub fred () { 2 }
 EXPECT
-Constant subroutine fred redefined at - line 4.
 ########
 # 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' ;
@@ -736,69 +772,64 @@ 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.
+Array @FRED missing the @ in argument 1 of push() at - line 2.
 ########
 # op.c
-use warnings 'deprecated' ;
 @a = keys FRED ;
 no warnings 'deprecated' ;
 @a = keys FRED ;
 EXPECT
-Hash %FRED missing the % in argument 1 of keys() at - line 3.
+Hash %FRED missing the % in argument 1 of keys() at - line 2.
 ########
 # op.c
-BEGIN {
-    if ($^O eq 'MacOS') {
-       print <<EOM;
-SKIPPED
-# no exec on Mac OS
-EOM
-       exit;
-    }
-}
 use warnings 'syntax' ;
 exec "$^X -e 1" ; 
 my $a
 EXPECT
-Statement unlikely to be reached at - line 13.
+Statement unlikely to be reached at - line 4.
        (Maybe you meant system() when you said exec()?)
 ########
+# op.c, no warning if exec isn't a statement.
+use warnings 'syntax' ;
+$a || exec "$^X -e 1" ;
+my $a
+EXPECT
+########
+# op.c
+defined(@a);
+EXPECT
+defined(@array) is deprecated at - line 2.
+       (Maybe you should just omit the defined()?)
+########
 # op.c
-use warnings 'deprecated' ;
 my @a; defined(@a);
 EXPECT
-defined(@array) is deprecated at - line 3.
+defined(@array) is deprecated at - line 2.
        (Maybe you should just omit the defined()?)
 ########
 # op.c
-use warnings 'deprecated' ;
 defined(@a = (1,2,3));
 EXPECT
-defined(@array) is deprecated at - line 3.
+defined(@array) is deprecated at - line 2.
+       (Maybe you should just omit the defined()?)
+########
+# op.c
+defined(%h);
+EXPECT
+defined(%hash) is deprecated at - line 2.
        (Maybe you should just omit the defined()?)
 ########
 # op.c
-use warnings 'deprecated' ;
 my %h; defined(%h);
 EXPECT
-defined(%hash) is deprecated at - line 3.
+defined(%hash) is deprecated at - line 2.
        (Maybe you should just omit the defined()?)
 ########
 # op.c
-BEGIN {
-    if ($^O eq 'MacOS') {
-       print <<EOM;
-SKIPPED
-# no exec on Mac OS
-EOM
-       exit;
-    }
-}
 no warnings 'syntax' ;
 exec "$^X -e 1" ; 
 my $a
@@ -812,6 +843,70 @@ EXPECT
 Prototype mismatch: sub main::fred () vs ($) at - line 3.
 ########
 # 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
+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
+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
+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
+Illegal character in prototype for main::foo : \0 at (eval 1) line 1.
+########
+# op.c
+use warnings;
+eval "sub foo (\xAB) {}";
+EXPECT
+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
+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 ;
 sub fred() ;
 sub fred($) {}
@@ -830,12 +925,93 @@ 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 [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_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() ; 
@@ -1024,7 +1200,6 @@ local(pos($x));           # OP_POS
 local(vec($x,0,1));    # OP_VEC
 local($a[$b]);         # OP_AELEM              ok
 local($a{$b});         # OP_HELEM              ok
-local($[);             # OP_CONST
 
 no warnings 'syntax';
 EXPECT
@@ -1058,7 +1233,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;
@@ -1074,27 +1248,114 @@ 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
-use feature 'state';
-use warnings 'misc';
-state($x) = 1;
-(state $y) = 2;
-(state $z, my $t) = (3, 4);
-(state $foo, state $bar) = (5, 6);
-no warnings 'misc';
-state($x) = 1;
-(state $y) = 2;
-(state $z, my $t) = (3, 4);
-(state $foo, state $bar) = (5, 6);
-EXPECT
-State variable $z will be reinitialized at - line 6.
-State variable $foo will be reinitialized at - line 7.
-State variable $bar will be reinitialized at - line 7.
+$[ = 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.
+########