This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
[perl #97466] Stop defined from propagating ref cx too far
authorFather Chrysostomos <sprout@cpan.org>
Sun, 23 Sep 2012 13:02:58 +0000 (06:02 -0700)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 23 Sep 2012 13:03:50 +0000 (06:03 -0700)
MANIFEST
op.c
t/op/defined.t [new file with mode: 0644]

index 9aa1045..a633ad5 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
@@ -5245,6 +5245,7 @@ t/op/cproto.t                     Check builtin prototypes
 t/op/crypt.t                   See if crypt works
 t/op/current_sub.t             __SUB__ tests
 t/op/dbm.t                     See if dbmopen/dbmclose work
+t/op/defined.t                 See if defined() edge cases work
 t/op/defins.t                  See if auto-insert of defined() works
 t/op/delete.t                  See if delete works
 t/op/die_except.t              See if die/eval avoids $@ clobberage
diff --git a/op.c b/op.c
index 9e4dd30..d074c0c 100644 (file)
--- a/op.c
+++ b/op.c
@@ -2386,7 +2386,7 @@ Perl_doref(pTHX_ OP *o, I32 type, bool set_op_ref)
 
     case OP_SCALAR:
     case OP_NULL:
-       if (!(o->op_flags & OPf_KIDS))
+       if (!(o->op_flags & OPf_KIDS) || type == OP_DEFINED)
            break;
        doref(cBINOPo->op_first, type, set_op_ref);
        break;
diff --git a/t/op/defined.t b/t/op/defined.t
new file mode 100644 (file)
index 0000000..7129e47
--- /dev/null
@@ -0,0 +1,20 @@
+#!perl
+BEGIN {
+    chdir 't';
+    require './test.pl';
+}
+
+plan 5;
+
+sub notdef { undef }
+
+# [perl #97466]
+# These should actually call the sub, instead of testing the sub itself
+ok !defined do { &notdef }, 'defined do { &sub }';
+ok !defined(scalar(42,&notdef)), 'defined(scalar(42,&sub))';
+ok !defined do{();&notdef}, '!defined do{();&sub}';
+
+# Likewise, these should evaluate @array in scalar context
+no warnings "deprecated";
+ok defined($false ? $scalar : @array), 'defined( ... ? ... : @array)';
+ok defined(scalar @array), 'defined(scalar @array)';