summaryrefslogtreecommitdiffstats
path: root/gnu/usr.bin/perl/t/lib/warnings/op
diff options
context:
space:
mode:
Diffstat (limited to 'gnu/usr.bin/perl/t/lib/warnings/op')
-rw-r--r--gnu/usr.bin/perl/t/lib/warnings/op207
1 files changed, 204 insertions, 3 deletions
diff --git a/gnu/usr.bin/perl/t/lib/warnings/op b/gnu/usr.bin/perl/t/lib/warnings/op
index de74d2e3604..83d3705f560 100644
--- a/gnu/usr.bin/perl/t/lib/warnings/op
+++ b/gnu/usr.bin/perl/t/lib/warnings/op
@@ -1,5 +1,8 @@
op.c AOK
+ Use of my $_ is experimental
+ my $_ ;
+
Found = in conditional, should be ==
1 if $a = 1 ;
@@ -73,6 +76,8 @@
(Maybe you should just omit the defined()?)
my %h ; defined %h ;
+ "my %s" used in sort comparison
+
$[ used in comparison (did you mean $] ?)
length() used on @array (did you mean "scalar(@array)"?)
@@ -97,18 +102,33 @@
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 'syntax' ;
@@ -148,8 +168,10 @@ Using an array as a reference is deprecated at - line 9.
Using an array as a reference is deprecated at - line 10.
########
# 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
@@ -206,6 +228,7 @@ $a <=> $b; # OP_NCMP
use 5.015;
__SUB__ # OP_RUNCV
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.
@@ -660,28 +683,43 @@ Bareword found in conditional at - line 3.
use warnings 'misc' ;
open FH, "<abc" ;
$x = 1 if $x = <FH> ;
+$x = 1 if $x
+ = <FH> ;
no warnings 'misc' ;
$x = 1 if $x = <FH> ;
+$x = 1 if $x
+ = <FH> ;
EXPECT
Value of <HANDLE> construct can be "0"; test with defined() at - line 4.
+Value of <HANDLE> 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' ;
@@ -722,10 +760,15 @@ EXPECT
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' ;
@@ -749,6 +792,28 @@ 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 }
@@ -840,8 +905,13 @@ EXPECT
# op.c
sub fred();
sub fred($) {}
+use constant foo=>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;
@@ -926,6 +996,116 @@ 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';
@@ -1360,3 +1540,24 @@ sub ᚠርƊ () { 1 }
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\.
+########