Skip to content

[doc] perlsyn: mention something about multiple identical labels #18369

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jidanni opened this issue Nov 30, 2020 · 2 comments · Fixed by #23259
Closed

[doc] perlsyn: mention something about multiple identical labels #18369

jidanni opened this issue Nov 30, 2020 · 2 comments · Fixed by #23259

Comments

@jidanni
Copy link
Member

jidanni commented Nov 30, 2020

On perlsyn, around

The LABEL is optional, and if present, consists of an identifier
followed by a colon. The LABEL identifies the loop for the loop control
statements "next", "last", and "redo".

do say something like "If more than one label with the same name occurs, it
refers to the nearest one above it".

As there is no error in doing e.g., this,

  L: while ( $_ = shift @pids ) {
        my $c = -1;
      L: for my $genre (@genres) {
            $c++;
          L: if ( $genre->{Exclude} && $$p{$_}{title} =~ /$genre->{Exclude}/i ) {
                next;
            }
            else {
              L: for my $match ( @{ $genre->{Matches} } ) {
                    if ( $$p{$_}{title} =~ /$match/i ) {
                        push @{ $genre->{Playlists} }, $_;
                        next L;
                    }
                }
              L: for my $match ( @{ $genre->{Matches} } ) {
                    if ( $$p{$_}{title} =~ /$match/i ) {
                        push @{ $genre->{Playlists} }, $_;
                        next L;
                    }
                }
            }

        }
    }

But the document don't say what multiple identical labels are supposed
to do. It only goes on to mention the case of no label at all,

If the LABEL is omitted, the loop control statement refers to the
innermost enclosing loop.

And even cautions,

This may include dynamically looking back your call- stack at run time
to find the LABEL. Such desperate behavior triggers a warning if you
use the "use warnings" pragma or the -w flag.

But still never touches on multiple identical label cases.

"Why would anybody add multiple identical labels, even on the same block
level?"

That's not a concern of me. I'm just saying the document needs to say
what will happen... or errors should be triggered.

@jkeenan
Copy link
Contributor

jkeenan commented Nov 30, 2020 via email

@jidanni
Copy link
Member Author

jidanni commented Nov 30, 2020

Here's how I discovered this documentation bug:
I intended to move label to a different line, but I forgot to remove the original label, ending up with two. Then I noticed that neither Perltidy nor the compiler detected any problem. So maybe it's not officially illegal, but at least it's what is supposed to happen should still be documented. I'm sorry you'll have to devise your own tests because, well, that's for the pros.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants