summaryrefslogtreecommitdiff
path: root/pp_ctl.c
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-06-25 19:25:47 +0000
committerRafael Garcia-Suarez <rgarciasuarez@gmail.com>2003-06-25 19:25:47 +0000
commit0c58d367e297133798f6e191e83d3087e2617588 (patch)
tree84781f22fd6028b3549edec1f17110ccfcc84d8c /pp_ctl.c
parent23bb1b96cfae0dc23679ea6dd44cf0deadeb9fbf (diff)
downloadperl-0c58d367e297133798f6e191e83d3087e2617588.tar.gz
Fix [perl #21742] :
require() should always be called in scalar context, even when it's the last statement in an eval(""). p4raw-id: //depot/perl@19851
Diffstat (limited to 'pp_ctl.c')
-rw-r--r--pp_ctl.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/pp_ctl.c b/pp_ctl.c
index 30e7b1356a..dbfc39cb4d 100644
--- a/pp_ctl.c
+++ b/pp_ctl.c
@@ -2828,8 +2828,7 @@ S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq)
else
sv_setpv(ERRSV,"");
if (yyparse() || PL_error_count || !PL_eval_root) {
- SV **newsp;
- I32 gimme;
+ SV **newsp; /* Used by POPBLOCK. */
PERL_CONTEXT *cx;
I32 optype = 0; /* Might be reset by POPEVAL. */
STRLEN n_a;
@@ -2873,7 +2872,16 @@ S_doeval(pTHX_ int gimme, OP** startop, CV* outside, U32 seq)
*startop = PL_eval_root;
} else
SAVEFREEOP(PL_eval_root);
- if (gimme & G_VOID)
+
+ /* 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_VOID)
scalarvoid(PL_eval_root);
else if (gimme & G_ARRAY)
list(PL_eval_root);