summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2012-09-23 06:02:58 -0700
committerFather Chrysostomos <sprout@cpan.org>2012-09-23 06:03:50 -0700
commit518618af9da07b079c1585df2b7c76a1aed0f19c (patch)
treecf07652a1d714b64d2e0b62b1d0720f46e856a00
parent02a7bbbc28f17133923631eccec205b5a0c2c52d (diff)
downloadperl-518618af9da07b079c1585df2b7c76a1aed0f19c.tar.gz
[perl #97466] Stop defined from propagating ref cx too far
-rw-r--r--MANIFEST1
-rw-r--r--op.c2
-rw-r--r--t/op/defined.t20
3 files changed, 22 insertions, 1 deletions
diff --git a/MANIFEST b/MANIFEST
index 9aa104588b..a633ad54f3 100644
--- 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 9e4dd3004c..d074c0c8a5 100644
--- 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
index 0000000000..7129e47a88
--- /dev/null
+++ b/t/op/defined.t
@@ -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)';