From: Gerard Goossen Date: Mon, 16 Nov 2009 12:58:24 +0000 (+0100) Subject: Force OP_REQUIRE to scalar context at the end of ck_require and don't let it become... X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=021f53de09926928546378b3552f9240c9241dde;p=p5sagit%2Fp5-mst-13.2.git Force OP_REQUIRE to scalar context at the end of ck_require and don't let it become void context. Fixes problem with require not always being in scalar context. --- diff --git a/op.c b/op.c index f506bff..d4f6fb3 100644 --- a/op.c +++ b/op.c @@ -985,7 +985,7 @@ Perl_scalarvoid(pTHX_ OP *o) want = o->op_flags & OPf_WANT; if ((want && want != OPf_WANT_SCALAR) || (PL_parser && PL_parser->error_count) - || o->op_type == OP_RETURN) + || o->op_type == OP_RETURN || o->op_type == OP_REQUIRE) { return o; } @@ -1215,10 +1215,6 @@ Perl_scalarvoid(pTHX_ OP *o) case OP_ENTEREVAL: scalarkids(o); break; - case OP_REQUIRE: - /* all requires must return a boolean value */ - o->op_flags &= ~OPf_WANT; - /* FALL THROUGH */ case OP_SCALAR: return scalar(o); } @@ -1307,10 +1303,6 @@ Perl_list(pTHX_ OP *o) } PL_curcop = &PL_compiling; break; - case OP_REQUIRE: - /* all requires must return a boolean value */ - o->op_flags &= ~OPf_WANT; - return scalar(o); } return o; } @@ -7677,7 +7669,7 @@ Perl_ck_require(pTHX_ OP *o) return newop; } - return ck_fun(o); + return scalar(ck_fun(o)); } OP * diff --git a/pp_ctl.c b/pp_ctl.c index a629887..8074b9f 100644 --- a/pp_ctl.c +++ b/pp_ctl.c @@ -3104,14 +3104,8 @@ S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq) SAVEFREEOP(PL_eval_root); /* Set the context for this new optree. - * If the last op is an OP_REQUIRE, force scalar context. - * Otherwise, propagate the context from the eval(). */ - if (PL_eval_root->op_type == OP_LEAVEEVAL - && cUNOPx(PL_eval_root)->op_first->op_type == OP_LINESEQ - && cLISTOPx(cUNOPx(PL_eval_root)->op_first)->op_last->op_type - == OP_REQUIRE) - scalar(PL_eval_root); - else if ((gimme & G_WANT) == G_VOID) + * Propagate the context from the eval(). */ + if ((gimme & G_WANT) == G_VOID) scalarvoid(PL_eval_root); else if ((gimme & G_WANT) == G_ARRAY) list(PL_eval_root); diff --git a/t/comp/require.t b/t/comp/require.t index a868457..baf4887 100644 --- a/t/comp/require.t +++ b/t/comp/require.t @@ -166,9 +166,8 @@ print $x; # Test that scalar context is forced for require write_file('bleah.pm', <<'**BLEAH**' -my $TODO = $i == 38 ? " # TODO " : ""; print "not " if !defined wantarray || wantarray ne ''; -print "ok $i - require() context $TODO\n"; +print "ok $i - require() context\n"; 1; **BLEAH** );