stat $ioref should reset the internal stat type
authorFather Chrysostomos <sprout@cpan.org>
Sat, 14 Jan 2012 00:43:30 +0000 (16:43 -0800)
committerFather Chrysostomos <sprout@cpan.org>
Sat, 14 Jan 2012 05:24:54 +0000 (21:24 -0800)
In addition to a stat buffer, Perl keeps track internally of which
type of stat was done last, either stat or lstat, so that lstat _ can
die if the previous type was stat.

This was not being reset for stat $ioref.  Filetest ops were fine.

pp_sys.c
t/op/stat.t

index bd552a1..430aa7c 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -2802,6 +2802,7 @@ PP(pp_stat)
             io = MUTABLE_IO(SvRV(sv));
             if (PL_op->op_type == OP_LSTAT)
                 goto do_fstat_warning_check;
+           PL_laststype = OP_STAT;
             goto do_fstat_have_io; 
         }
         
index fccadba..d2ce8d1 100644 (file)
@@ -20,7 +20,7 @@ if(eval {require File::Spec; 1}) {
 }
 
 
-plan tests => 109;
+plan tests => 110;
 
 my $Perl = which_perl();
 
@@ -456,6 +456,15 @@ eval { lstat _ };
 is( "$@", "", "lstat _ ok after lstat" );
 eval { -l _ };
 is( "$@", "", "-l _ ok after lstat" );
+
+lstat "test.pl";
+{
+    open my $fh, "test.pl";
+    stat *$fh{IO};
+    eval { lstat _ }
+}
+like $@, qr/^The stat preceding lstat\(\) wasn't an lstat at /,
+'stat $ioref resets stat type';
   
 SKIP: {
     skip "No lstat", 2 unless $Config{d_lstat};