This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Don’t let ?: folding affect stat
authorFather Chrysostomos <sprout@cpan.org>
Thu, 26 Jul 2012 03:15:36 +0000 (20:15 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Thu, 26 Jul 2012 05:08:32 +0000 (22:08 -0700)
stat(${\1} ? foo : bar) and stat(1 ? foo : bar) should behave the same
way, but were treated differently, due to the way ?: is folded in
the latter case.  Now that foldedness is recorded in the op tree
(cc2ebcd7902), we can use the OPpCONST_FOLDED flag to distinguish
stat(1 ? foo : bar) from stat(foo).

op.c
t/comp/fold.t

diff --git a/op.c b/op.c
index b5ebd79..52e600f 100644 (file)
--- a/op.c
+++ b/op.c
@@ -8130,7 +8130,8 @@ Perl_ck_ftst(pTHX_ OP *o)
        SVOP * const kid = (SVOP*)cUNOPo->op_first;
        const OPCODE kidtype = kid->op_type;
 
-       if (kidtype == OP_CONST && (kid->op_private & OPpCONST_BARE)) {
+       if (kidtype == OP_CONST && (kid->op_private & OPpCONST_BARE)
+        && !(kid->op_private & OPpCONST_FOLDED)) {
            OP * const newop = newGVOP(type, OPf_REF,
                gv_fetchsv(kid->op_sv, GV_ADD, SVt_PVIO));
 #ifdef PERL_MAD
index 69d1903..c600067 100644 (file)
@@ -4,7 +4,7 @@
 # we've not yet verified that use works.
 # use strict;
 
-print "1..23\n";
+print "1..25\n";
 my $test = 0;
 
 # Historically constant folding was performed by evaluating the ops, and if
@@ -132,3 +132,10 @@ package other { # hide the "ok" sub
  print " ", ++$test, " - print followed by const || URSINE\n";
  BEGIN { $^W = 1 }
 }
+
+# or stat
+print "not " unless stat(1 ? INSTALL : 0) eq stat("INSTALL");
+print "ok ", ++$test, " - stat(const ? word : ....)\n";
+# in case we are in t/
+print "not " unless stat(1 ? TEST : 0) eq stat("TEST");
+print "ok ", ++$test, " - stat(const ? word : ....)\n";