summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraham Barr <bodg@tiuk.ti.com>1997-01-03 21:29:04 +0000
committerChip Salzenberg <chip@atlantic.net>1997-01-08 11:52:00 +1200
commit3112f5de73952f91aa4e8005d9852dfddbcf0402 (patch)
tree9c23985248fcb02a8816ca984d35f5e1172ac5d5
parent218104faecb0ec19e0f4f89e084959e757a5230f (diff)
downloadperl-3112f5de73952f91aa4e8005d9852dfddbcf0402.tar.gz
Fix: empty @_ when calling empty-proto subs without parens
Graham Barr wrote: <snip> > 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.
-rw-r--r--perly.c2
-rw-r--r--perly.y2
2 files changed, 2 insertions, 2 deletions
diff --git a/perly.c b/perly.c
index 6ff2f58731..50a28ff222 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 a281dff9b9..30ae76fd2c 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); }