Rafael Garcia-Suarez schrieb: > 2008/6/20 via RT Nicholas Clark <perlbug-followup@perl.org>: >> $ ./perl -Ilib -e 'sub foo {return return}' >> $ >> >> How come this isn't a syntax error? It can't possibly do anything useful. >> (Actually, it seems that anything can be passed the return value of return. >> C<print return> works just fine). > > return is technically parsed as a list operator (LSTOP). > That enables using it in compound expressions. > > Note that this syntax works also for other control flow statements : > > $ perl -wle '$i=3;while(1){print($i--||last)}' > 3 > 2 > 1 > > I don't really see a reason to change it. Well, if we once want to emit a warning, here it is: $ ./perl -e'sub foo {return return}; foo' Ignored return return at -e line 1. $ ./perl -e'sub foo {return 'xx', return}; foo' Ignored return return at -e line 1. $ ./perl -e'sub foo {return 1 || return}; foo' $ ./perl -e'sub foo {return 0 || return}; foo' Ignored return return at -e line 1. I'm not entirely sure if optimizing it away is correct though. The only way I found is in peep(), not in ck_return() and not in perly.y See http://www.xray.mpe.mpg.de/mailing-lists/perl5-porters/2008-06/msg00650.html diff -u op.c.orig op.c --- op.c.orig 2008-06-17 11:25:08.000000000 +0000 +++ op.c 2008-06-24 16:40:24.359375000 +0000 @@ -8822,6 +8822,18 @@ assert (!cPMOP->op_pmstashstartu.op_pmreplstart); } break; + + case OP_RETURN: + if ((o->op_type != OP_LEAVESUBLV) + && (o->op_next->op_type == OP_RETURN)) + { /* [perl #56150] return return */ + Perl_warner(aTHX_ packWARN(WARN_SYNTAX), + "Ignored return return"); + o->op_type = OP_NULL; + /*o->op_ppaddr = PL_ppaddr[OP_NULL];*/ + o->op_opt = 1; + } + break; } oldop = o; } -- Reini Urban http://phpwiki.org/ http://murbreak.at/Thread Previous | Thread Next