Actually submit previous change.
[p5sagit/p5-mst-13.2.git] / t / lib / warnings / op
index c5f8147..8dadc7a 100644 (file)
@@ -1,25 +1,5 @@
   op.c         AOK
 
-     "my" variable %s masks earlier declaration in same scope
-       my $x;
-       my $x ;
-
-     Variable "%s" may be unavailable 
-       sub x {
-           my $x;
-           sub y {
-               $x
-           }
-       }
-
-     Variable "%s" will not stay shared 
-       sub x {
-           my $x;
-           sub y {
-               sub { $x }
-           }
-       }
-
      Found = in conditional, should be ==
        1 if $a = 1 ;
 
         sub fred() ;
         sub fred($) {}
 
-    %s never introduced                [pad_leavemy]   TODO
     Runaway prototype          [newSUB]        TODO
     oops: oopsAV               [oopsAV]        TODO
     oops: oopsHV               [oopsHV]        TODO
     
 __END__
 # op.c
-use warnings 'misc' ;
-my $x ;
-my $x ;
-my $y = my $y ;
-no warnings 'misc' ;
-my $x ;
-my $y ;
-EXPECT
-"my" variable $x masks earlier declaration in same scope at - line 4.
-"my" variable $y masks earlier declaration in same statement at - line 5.
-########
-# op.c
-use warnings 'closure' ;
-sub x {
-      my $x;
-      sub y {
-         $x
-      }
-   }
-EXPECT
-Variable "$x" will not stay shared at - line 7.
-########
-# op.c
-no warnings 'closure' ;
-sub x {
-      my $x;
-      sub y {
-         $x
-      }
-   }
-EXPECT
-
-########
-# op.c
-use warnings 'closure' ;
-sub x {
-      our $x;
-      sub y {
-         $x
-      }
-   }
-EXPECT
-
-########
-# op.c
-use warnings 'closure' ;
-sub x {
-      my $x;
-      sub y {
-         sub { $x }
-      }
-   }
-EXPECT
-Variable "$x" may be unavailable at - line 6.
-########
-# op.c
-no warnings 'closure' ;
-sub x {
-      my $x;
-      sub y {
-         sub { $x }
-      }
-   }
-EXPECT
-
-########
-# op.c
 use warnings 'syntax' ;
 1 if $a = 1 ;
 no warnings 'syntax' ;
@@ -613,6 +525,10 @@ 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
+use constant U => undef;
+print "boo\n" if U;    # test OPpCONST_SHORTCIRCUIT
+$[ = 2; # should not warn
 no warnings 'void' ;
 "abc"; # OP_CONST
 7 ; # OP_CONST
@@ -669,20 +585,33 @@ 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.
 ########
 # op.c
-use warnings 'syntax' ;
+use warnings 'parenthesis' ;
 my $a, $b = (1,2);
-no warnings 'syntax' ;
+my @foo,%bar,  $quux; # there's a TAB here
+my $x, $y or print;
+no warnings 'parenthesis' ;
 my $c, $d = (1,2);
 EXPECT
 Parentheses missing around "my" list at - line 3.
+Parentheses missing around "my" list at - line 4.
 ########
 # op.c
-use warnings 'syntax' ;
+use warnings 'parenthesis' ;
+our $a, $b = (1,2);
+no warnings 'parenthesis' ;
+our $c, $d = (1,2);
+EXPECT
+Parentheses missing around "our" list at - line 3.
+########
+# op.c
+use warnings 'parenthesis' ;
 local $a, $b = (1,2);
-no warnings 'syntax' ;
+local *f, *g;
+no warnings 'parenthesis' ;
 local $c, $d = (1,2);
 EXPECT
 Parentheses missing around "local" list at - line 3.
+Parentheses missing around "local" list at - line 4.
 ########
 # op.c
 use warnings 'bareword' ;
@@ -750,6 +679,19 @@ EXPECT
 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
 use warnings 'redefine' ;
 sub fred {}
 sub fred {}
@@ -985,6 +927,7 @@ $a = $b < $c & $d;
 $a = $b >= $c ^ $d;
 $a = $b <= $c | $d;
 $a = $b <=> $c & $d;
+$a &= $b == $c; $a |= $b == $c; $a ^= $b == $c; # shouldn't warn
 no warnings 'precedence';
 $a = $b & $c == $d;
 $a = $b ^ $c != $d;
@@ -1028,3 +971,133 @@ Possible precedence problem on bitwise & operator at - line 7.
 Possible precedence problem on bitwise ^ operator at - line 8.
 Possible precedence problem on bitwise | operator at - line 9.
 Possible precedence problem on bitwise & operator at - line 10.
+########
+# op.c
+
+# ok   => local() has desired effect;
+# ignore=> local() silently ignored
+
+use warnings 'syntax';
+
+local(undef);          # OP_UNDEF              ignore
+sub lval : lvalue {};
+local(lval());         # OP_ENTERSUB
+local($x **= 1);       # OP_POW
+local($x *=  1);       # OP_MULTIPLY
+local($x /=  1);       # OP_DIVIDE
+local($x %=  1);       # OP_MODULO
+local($x x=  1);       # OP_REPEAT
+local($x +=  1);       # OP_ADD
+local($x -=  1);       # OP_SUBTRACT
+local($x .=  1);       # OP_CONCAT
+local($x <<= 1);       # OP_LEFT_SHIFT
+local($x >>= 1);       # OP_RIGHT_SHIFT
+local($x &=  1);       # OP_BIT_AND
+local($x ^=  1);       # OP_BIT_XOR
+local($x |=  1);       # OP_BIT_OR
+{
+    use integer;
+    local($x *= 1);    # OP_I_MULTIPLY
+    local($x /= 1);    # OP_I_DIVIDE
+    local($x %= 1);    # OP_I_MODULO
+    local($x += 1);    # OP_I_ADD
+    local($x -= 1);    # OP_I_SUBTRACT
+}
+local($x?$y:$z) = 1;   # OP_COND_EXPR          ok
+# these two are fatal run-time errors instead
+#local(@$a);           # OP_RV2AV              ok
+#local(%$a);           # OP_RV2HV              ok
+local(*a);             # OP_RV2GV              ok
+local(@a[1,2]);                # OP_ASLICE             ok
+local(@a{1,2});                # OP_HSLICE             ok
+local(@a = (1,2));     # OP_AASSIGN
+local($$x);            # OP_RV2SV              ok
+local($#a);            # OP_AV2ARYLEN
+local($x =   1);       # OP_SASSIGN
+local($x &&= 1);       # OP_ANDASSIGN
+local($x ||= 1);       # OP_ORASSIGN
+local($x //= 1);       # OP_DORASSIGN
+local($a[0]);          # OP_AELEMFAST          ok
+
+local(substr($x,0,1)); # OP_SUBSTR
+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
+Useless localization of subroutine entry at - line 10.
+Useless localization of exponentiation (**) at - line 11.
+Useless localization of multiplication (*) at - line 12.
+Useless localization of division (/) at - line 13.
+Useless localization of modulus (%) at - line 14.
+Useless localization of repeat (x) at - line 15.
+Useless localization of addition (+) at - line 16.
+Useless localization of subtraction (-) at - line 17.
+Useless localization of concatenation (.) or string at - line 18.
+Useless localization of left bitshift (<<) at - line 19.
+Useless localization of right bitshift (>>) at - line 20.
+Useless localization of bitwise and (&) at - line 21.
+Useless localization of bitwise xor (^) at - line 22.
+Useless localization of bitwise or (|) at - line 23.
+Useless localization of integer multiplication (*) at - line 26.
+Useless localization of integer division (/) at - line 27.
+Useless localization of integer modulus (%) at - line 28.
+Useless localization of integer addition (+) at - line 29.
+Useless localization of integer subtraction (-) at - line 30.
+Useless localization of list assignment at - line 39.
+Useless localization of array length at - line 41.
+Useless localization of scalar assignment at - line 42.
+Useless localization of logical and assignment (&&=) at - line 43.
+Useless localization of logical or assignment (||=) at - line 44.
+Useless localization of defined or assignment (//=) at - line 45.
+Useless localization of substr at - line 48.
+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;
+my ($x4) if 0;
+my ($x5,@x6, %x7) if 0;
+0 && my $z1;
+0 && my (%z2);
+# these shouldn't warn
+our $x if 0;
+our $x unless 0;
+if (0) { my $w1 }
+if (my $w2) { $a=1 }
+if ($a && (my $w3 = 1)) {$a = 2}
+
+EXPECT
+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);
+(undef, my $v, state $w) = (7 .. 9);
+no warnings 'misc';
+state($x) = 1;
+(state $y) = 2;
+(state $z, my $t) = (3, 4);
+(state $foo, state $bar) = (5, 6);
+(undef, my $v, state $w) = (7 .. 9);
+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.
+State variable $w will be reinitialized at - line 8.