Skip to content

Interpreter and JIT return different capture counts when a recursion returns the called group #1048

Open

Description

@ybai08

Found while working on #1046. When a recursion returns the called group itself through a capture list, the interpreter and JIT report a different number of captures for the same match:

/(?&r(2))(x)?(?(DEFINE)(?<r>(a)))/
    a

/(?&r(2))(x)?(?(DEFINE)(?<r>(a)))/jit
    a

pcre2test output (main at 9b338eb, CMake Release build, JIT on, macOS arm64):

/(?&r(2))(x)?(?(DEFINE)(?<r>(a)))/
    a
 0: a
 1: <unset>
 2: <unset>

/(?&r(2))(x)?(?(DEFINE)(?<r>(a)))/jit
    a
 0: a

Here r is group 2 and (a) is group 3, so (?&r(2)) returns the called group. Both engines leave groups 1 and 2 unset, but the interpreter returns 3 (two trailing <unset> groups) while JIT returns 1. Returning group 3 instead ((?&r(3))) gives the same output in both (3: a, with 1 and 2 unset). The same output is produced with #1046 applied. It is not clear to me which return count is intended here, or whether group 2 should be set to a by the return.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions