From: Rafael Garcia-Suarez Date: Tue, 28 Jul 2009 07:47:24 +0000 (+0200) Subject: Forbid labels with keyword names X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f71d6157c7933c0d3df645f0411d97d7e2b66b2f;p=p5sagit%2Fp5-mst-13.2.git Forbid labels with keyword names --- diff --git a/pod/perl5110delta.pod b/pod/perl5110delta.pod index d7eb6dc..82d11e4 100644 --- a/pod/perl5110delta.pod +++ b/pod/perl5110delta.pod @@ -114,6 +114,18 @@ to avoid relying on the object's underlying structure). (However, if the object overloads the stringification or the numification operators, and if overload fallback is active, it will be used instead, as usual.) +=head2 Labels can't be keywords + +Labels used as targets for the C, C, C or C +statements cannot be keywords anymore. This restriction will prevent +potential confusion between the C and C syntaxes: +for example, a statement like C would jump to a label whose +name would be the return value of print(), (usually 1), instead of a +label named C. Moreover, the other control flow statements +would just ignore any keyword passed to them as a label name. Since +such labels cannot be defined anymore, this kind of error will be +avoided. + =head1 Core Enhancements =head2 The C pragma diff --git a/pod/perltodo.pod b/pod/perltodo.pod index ba0462e..7b10f5f 100644 --- a/pod/perltodo.pod +++ b/pod/perltodo.pod @@ -804,15 +804,6 @@ also the warning messages (see L, C). These tasks would need C knowledge, and knowledge of how the interpreter works, or a willingness to learn. -=head2 forbid labels with keyword names - -Currently C "computes" the label value: - - $ perl -e 'goto print' - Can't find label 1 at -e line 1. - -It would be nice to forbid labels with keyword names, to avoid confusion. - =head2 truncate() prototype The prototype of truncate() is currently C<$$>. It should probably diff --git a/t/comp/colon.t b/t/comp/colon.t index d2c64fe..122e33e 100644 --- a/t/comp/colon.t +++ b/t/comp/colon.t @@ -125,14 +125,14 @@ ok 22, (not eval "y:1" and not eval "y:echo: eq y|echo|" and eval "y:echo:ohce: >= 0"); -ok 23, (eval "AUTOLOAD:1" and +ok 23, (not eval "AUTOLOAD:1" and not eval "AUTOLOAD:echo: eq AUTOLOAD|echo|" and not eval "AUTOLOAD:echo:ohce: >= 0"); -ok 24, (eval "and:1" and +ok 24, (not eval "and:1" and not eval "and:echo: eq and|echo|" and not eval "and:echo:ohce: >= 0"); -ok 25, (eval "alarm:1" and +ok 25, (not eval "alarm:1" and not eval "alarm:echo: eq alarm|echo|" and not eval "alarm:echo:ohce: >= 0"); diff --git a/toke.c b/toke.c index 658d163..554975a 100644 --- a/toke.c +++ b/toke.c @@ -5275,6 +5275,9 @@ Perl_yylex(pTHX) while (d < PL_bufend && isSPACE(*d)) d++; /* no comments skipped here, or s### is misparsed */ + /* Check for keywords */ + tmp = keyword(PL_tokenbuf, len, 0); + /* Is this a label? */ if (!tmp && PL_expect == XSTATE && d < PL_bufend && *d == ':' && *(d + 1) != ':') { @@ -5284,9 +5287,6 @@ Perl_yylex(pTHX) TOKEN(LABEL); } - /* Check for keywords */ - tmp = keyword(PL_tokenbuf, len, 0); - /* Is this a word before a => operator? */ if (*d == '=' && d[1] == '>') { CLINE;