summaryrefslogtreecommitdiff
path: root/op.c
diff options
context:
space:
mode:
authorHojung Yoon <amoc.yn@gmail.com>2011-05-24 18:18:14 -0700
committerFather Chrysostomos <sprout@cpan.org>2011-05-24 20:08:32 -0700
commit459b64da6c5743fa9093a9ef5214a82b46f2f7d0 (patch)
treecd1efb6cc33c5a8f9dee02b6434b87103345c9f6 /op.c
parenteee8d40ab2eee78fd8a8a007a74b8b97b9f3c053 (diff)
downloadperl-459b64da6c5743fa9093a9ef5214a82b46f2f7d0.tar.gz
[perl #90888] each(ARRAY) on scalar context should wrapped into defined()
"perldoc -f each" says that if each() is performed on ARRAY in scalar context, it will return only the index in an array. Calling each(HASH) in scalar context worked well but calling each(ARRAY) didn't because it was not wrapped into defined OPCODE. So, in Perl_newWHILEOP() and Perl_newLOOPOP(), they are modified to check them and wrap with defined OP if needed. In S_new_logop(), it's reasonable to warn if return value of each(ARRAY) is being used for boolean value, as it's first return value will be "0", the false. issue: #90888 link: http://rt.perl.org/rt3/Public/Bug/Display.html?id=90888
Diffstat (limited to 'op.c')
-rw-r--r--op.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/op.c b/op.c
index 0d4e1e6ad6..e1bf3539c5 100644
--- a/op.c
+++ b/op.c
@@ -5103,7 +5103,8 @@ S_new_logop(pTHX_ I32 type, I32 flags, OP** firstp, OP** otherp)
if (k1->op_type == OP_READDIR
|| k1->op_type == OP_GLOB
|| (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
- || k1->op_type == OP_EACH)
+ || k1->op_type == OP_EACH
+ || k1->op_type == OP_AEACH)
{
warnop = ((k1->op_type == OP_NULL)
? (OPCODE)k1->op_targ : k1->op_type);
@@ -5347,7 +5348,8 @@ Perl_newLOOPOP(pTHX_ I32 flags, I32 debuggable, OP *expr, OP *block)
if (k1 && (k1->op_type == OP_READDIR
|| k1->op_type == OP_GLOB
|| (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
- || k1->op_type == OP_EACH))
+ || k1->op_type == OP_EACH
+ || k1->op_type == OP_AEACH))
expr = newUNOP(OP_DEFINED, 0, expr);
break;
}
@@ -5435,7 +5437,8 @@ Perl_newWHILEOP(pTHX_ I32 flags, I32 debuggable, LOOP *loop,
if (k1 && (k1->op_type == OP_READDIR
|| k1->op_type == OP_GLOB
|| (k1->op_type == OP_NULL && k1->op_targ == OP_GLOB)
- || k1->op_type == OP_EACH))
+ || k1->op_type == OP_EACH
+ || k1->op_type == OP_AEACH))
expr = newUNOP(OP_DEFINED, 0, expr);
break;
}