From: Graham Barr Date: Fri, 3 Jan 1997 21:29:04 +0000 (+0000) Subject: Fix: empty @_ when calling empty-proto subs without parens X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3112f5de73952f91aa4e8005d9852dfddbcf0402;p=p5sagit%2Fp5-mst-13.2.git Fix: empty @_ when calling empty-proto subs without parens Graham Barr wrote: > OK, so I thought that prototypes in Socket.pm (which is probably > a good idea) could help here, but... guess what the following > script outputs > > sub fred () > { > warn join(" ",@_); > } > > fred; > @_ = qw(a b c); > &fred; > fred; > __END__ > > It outputs ... > > Warning: something's wrong at yyy line 3. > a b c at yyy line 3. > a b c at yyy line 3. > > OK I can belive the second one as it has the & style call (which > the pod states overrides prototypes) but I was very amazed at > the last call. > > Is this a bug ?? I think so as the pod suggests that a sub defined > as > > sub mytime (); > > and a statement such as > > mytime +2; > > will by the same as > > mytime() + 2 > > but this is not the case, it seems it would be > > &mytime(@_) + 2 > OK, here is a patch which fixes this. It requires a modification to perly.y and perly.c (I cannot re-generate perly.c here but it is a simple fix) it chamges the output of the above script to Warning: something's wrong at yyy line 3. Warning: something's wrong at yyy line 3. a b c at yyy line 3. --- diff --git a/perly.c b/perly.c index 6ff2f58..50a28ff 100644 --- a/perly.c +++ b/perly.c @@ -2097,7 +2097,7 @@ case 141: break; case 142: #line 531 "perly.y" -{ yyval.opval = newUNOP(OP_ENTERSUB, 0, +{ yyval.opval = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar(yyvsp[0].opval)); } break; case 143: diff --git a/perly.y b/perly.y index a281dff..30ae76f 100644 --- a/perly.y +++ b/perly.y @@ -528,7 +528,7 @@ term : term ASSIGNOP term | FUNC0 '(' ')' { $$ = newOP($1, 0); } | FUNC0SUB - { $$ = newUNOP(OP_ENTERSUB, 0, + { $$ = newUNOP(OP_ENTERSUB, OPf_STACKED, scalar($1)); } | FUNC1 '(' ')' { $$ = newOP($1, OPf_SPECIAL); }