From: Gerard Goossen Date: Tue, 8 Dec 2009 11:42:58 +0000 (+0100) Subject: proper error on "grep $x (1,2,3)". Solves [perl #37314] X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f6435df36c4167f97876032948ee21a446b75f27;p=p5sagit%2Fp5-mst-13.2.git proper error on "grep $x (1,2,3)". Solves [perl #37314] --- diff --git a/op.c b/op.c index 5cbf917..bc8403a 100644 --- a/op.c +++ b/op.c @@ -7210,10 +7210,10 @@ Perl_ck_grep(pTHX_ OP *o) if (o->op_flags & OPf_STACKED) { OP* k; o = ck_sort(o); - kid = cLISTOPo->op_first->op_sibling; - if (!cUNOPx(kid)->op_next) - Perl_croak(aTHX_ "panic: ck_grep"); - for (k = cUNOPx(kid)->op_first; k; k = k->op_next) { + kid = cUNOPx(cLISTOPo->op_first->op_sibling)->op_first; + if (kid->op_type != OP_SCOPE && kid->op_type != OP_LEAVE) + return no_fh_allowed(o); + for (k = kid; k; k = k->op_next) { kid = k; } NewOp(1101, gwop, 1, LOGOP); diff --git a/t/op/grep.t b/t/op/grep.t index d7fe515..456b6c5 100644 --- a/t/op/grep.t +++ b/t/op/grep.t @@ -10,7 +10,7 @@ BEGIN { } require "test.pl"; -plan( tests => 60 ); +plan( tests => 61 ); { my @lol = ([qw(a b c)], [], [qw(1 2 3)]); @@ -207,3 +207,10 @@ plan( tests => 60 ); my @empty = map { while (1) {} } (); cmp_ok("@empty", 'eq', '', 'staying alive'); } + +{ + my $x; + eval 'grep $x (1,2,3);'; + like($@, qr/Missing comma after first argument to grep function/, + "proper error on variable as block. [perl #37314]"); +}