Skip to content
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

(*THEN) doesn't work in the simplest test possible #22193

Open
florian-pe opened this issue May 3, 2024 · 2 comments
Open

(*THEN) doesn't work in the simplest test possible #22193

florian-pe opened this issue May 3, 2024 · 2 comments

Comments

@florian-pe
Copy link

florian-pe commented May 3, 2024

This code

"abcde" =~ m{
        \A
        (?{ say "branch 1.1" })
        a
        (b (?{ say "branch 2.1: b" }) | . (?{ say "branch 2.2: ." }))
        (*THEN)
        (*FAIL)
    |
        \A
        (?{ say "branch 1.2" })
        a
}x;

outputs

branch 1.1
branch 2.1: b
branch 2.2: .
branch 1.2

(The line branch 2.2: . shouldn't be printed.)

The issue is that the regex engine backtracks into the inner branch 2 while it shouldn't backtrack at all in between the start of the current alternation (or whole match if the top level isn't an alternation) and the predicate (*THEN) if the control flow in the match attempt went after (*THEN), which it has in this case.

(*THEN) also fails to work properly in the case where the top level isn't an alternation:

"abcde" =~ m{
        \A
        (?{ say "start" })
        a
        (b (?{ say "branch 2.1: b" }) | . (?{ say "branch 2.2: ." }))
        (*THEN)
        (*FAIL)
}x;

which outputs

start
branch 2.1: b
branch 2.2: .

again the line branch 2.2: . should not be printed.

This was already reported in the issue #17069.

In these 2 test cases, replacing (*THEN) by (*PRUNE) does cut the backtracking normally.

@florian-pe
Copy link
Author

On a side note, do we need to have github repository privileges to remove the "Needs Triage" label and add new ones?

@jkeenan
Copy link
Contributor

jkeenan commented May 3, 2024

On a side note, do we need to have github repository privileges to remove the "Needs Triage" label and add new ones?

I believe the answer to those two questions is "Yes." "Needs Triage" is, I believe, automatically added to every new Issue. Other labels, e.g., "documentation," may be added if you select one of the other options at https://github.com/Perl/perl5/issues/new/choose.

If you have further questions about this or want to discuss it further, that discussion should not take place inside this or any GH issue. It's a policy issue, and so it should be discussed on the perl5-porters mailing list.

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

No branches or pull requests

2 participants