diff options
author | Dan Collins <dcollinsn@gmail.com> | 2016-03-30 16:42:39 +1100 |
---|---|---|
committer | Ricardo Signes <rjbs@cpan.org> | 2016-04-07 07:45:08 -0400 |
commit | 8f6eb0aa5efb953e32803878cca6d9c1e28ac03f (patch) | |
tree | 28c475d036a9b1023371f30dd05f705ce46b4fd1 | |
parent | 45d40326f89400e722587fa76ee587404ef594f9 (diff) | |
download | perl-8f6eb0aa5efb953e32803878cca6d9c1e28ac03f.tar.gz |
(perl #126162) warn if stat() is called on an array
-rw-r--r-- | op.c | 4 | ||||
-rw-r--r-- | t/op/stat.t | 10 |
2 files changed, 13 insertions, 1 deletions
@@ -9733,6 +9733,10 @@ Perl_ck_ftst(pTHX_ OP *o) op_free(o); return newop; } + + if (kidtype == OP_RV2AV) { + Perl_warner(aTHX_ packWARN(WARN_SYNTAX), "Array passed to stat will be coerced to a scalar (did you want stat $_[0]?)"); + } scalar((OP *) kid); if ((PL_hints & HINT_FILETEST_ACCESS) && OP_IS_FILETEST_ACCESS(o->op_type)) o->op_private |= OPpFT_ACCESS; diff --git a/t/op/stat.t b/t/op/stat.t index 2d7e3c7b50..c388083af0 100644 --- a/t/op/stat.t +++ b/t/op/stat.t @@ -25,7 +25,7 @@ if ($^O eq 'MSWin32') { ${^WIN32_SLOPPY_STAT} = 0; } -plan tests => 116; +plan tests => 118; my $Perl = which_perl(); @@ -636,6 +636,14 @@ SKIP: { is join("-", 1,2,3,(stat stat stat),4,5,6), "1-2-3-4-5-6", 'stat inside stat gets scalar context'; +# [perl #126162] stat an array should not work +my $statfile = './op/stat.t'; +my @statarg = ($statfile, $statfile); +ok !stat(@statarg), + 'stat on an array of valid paths should warn and should not return any data'; +is $!, 'No such file or directory', + 'stat on an array of valid paths should return "No such file or directory"'; + END { chmod 0666, $tmpfile; unlink_all $tmpfile; |