diff options
-rw-r--r-- | pod/perl5110delta.pod | 12 | ||||
-rw-r--r-- | pod/perltodo.pod | 9 | ||||
-rw-r--r-- | t/comp/colon.t | 6 | ||||
-rw-r--r-- | toke.c | 6 |
4 files changed, 18 insertions, 15 deletions
diff --git a/pod/perl5110delta.pod b/pod/perl5110delta.pod index d7eb6dcd61..82d11e4130 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<goto>, C<last>, C<next> or C<redo> +statements cannot be keywords anymore. This restriction will prevent +potential confusion between the C<goto LABEL> and C<goto EXPR> syntaxes: +for example, a statement like C<goto print> would jump to a label whose +name would be the return value of print(), (usually 1), instead of a +label named C<print>. 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<overloading> pragma diff --git a/pod/perltodo.pod b/pod/perltodo.pod index ba0462e47a..7b10f5fa3a 100644 --- a/pod/perltodo.pod +++ b/pod/perltodo.pod @@ -804,15 +804,6 @@ also the warning messages (see L<perllexwarn>, C<warnings.pl>). 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<goto keyword> "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 d2c64fe4c5..122e33ead9 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"); @@ -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; |