summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--op.c2
-rw-r--r--pp.c10
-rwxr-xr-xt/lib/b.t7
-rwxr-xr-xt/op/repeat.t15
4 files changed, 30 insertions, 4 deletions
diff --git a/op.c b/op.c
index 59643e78b1..87ee1af9c2 100644
--- a/op.c
+++ b/op.c
@@ -977,8 +977,6 @@ Perl_scalar(pTHX_ OP *o)
switch (o->op_type) {
case OP_REPEAT:
- if (o->op_private & OPpREPEAT_DOLIST)
- null(((LISTOP*)cBINOPo->op_first)->op_first);
scalar(cBINOPo->op_first);
break;
case OP_OR:
diff --git a/pp.c b/pp.c
index 37a4b25611..c40efef0dc 100644
--- a/pp.c
+++ b/pp.c
@@ -1232,6 +1232,16 @@ PP(pp_repeat)
(void)SvPOK_only_UTF8(TARG);
else
(void)SvPOK_only(TARG);
+
+ if (PL_op->op_private & OPpREPEAT_DOLIST) {
+ /* The parser saw this as a list repeat, and there
+ are probably several items on the stack. But we're
+ in scalar context, and there's no pp_list to save us
+ now. So drop the rest of the items -- robin@kitsite.com
+ */
+ dMARK;
+ SP = MARK;
+ }
PUSHTARG;
}
RETURN;
diff --git a/t/lib/b.t b/t/lib/b.t
index 019a1e8437..b10479ddff 100755
--- a/t/lib/b.t
+++ b/t/lib/b.t
@@ -15,7 +15,7 @@ use warnings;
use strict;
use Config;
-print "1..17\n";
+print "1..18\n";
my $test = 1;
@@ -35,6 +35,11 @@ ok;
print "not " if "{\n \$test /= 2 if ++\$test;\n}" ne
$deparse->coderef2text(sub {++$test and $test/=2;});
ok;
+
+print "not " if "{\n -((1, 2) x 2);\n}" ne
+ $deparse->coderef2text(sub {-((1,2)x2)});
+ok;
+
{
my $a = <<'EOF';
{
diff --git a/t/op/repeat.t b/t/op/repeat.t
index c030ba9a12..26f567d565 100755
--- a/t/op/repeat.t
+++ b/t/op/repeat.t
@@ -2,7 +2,7 @@
# $RCSfile: repeat.t,v $$Revision: 4.1 $$Date: 92/08/07 18:28:21 $
-print "1..20\n";
+print "1..23\n";
# compile time
@@ -96,3 +96,16 @@ print join('', (split(//,"123")) x 2) eq '123123' ? "ok 19\n" : "not ok 19\n";
# jhi@iki.fi
#
print "\xdd" x 24 eq "\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd" ? "ok 20\n" : "not ok 20\n";
+
+# When we use a list repeat in a scalar context, it behaves like
+# a scalar repeat. Make sure that works properly, and doesn't leave
+# extraneous values on the stack.
+# -- robin@kitsite.com
+
+my ($x, $y) = scalar ((1,2)x2);
+print $x eq "22" ? "ok 21\n" : "not ok 21\n";
+print !defined $y ? "ok 22\n" : "not ok 22\n";
+
+# Make sure the stack doesn't get truncated too much - the left
+# operand of the eq binop needs to remain!
+print (77 eq scalar ((1,7)x2) ? "ok 23\n" : "not ok 23\n");