Skip to content

Repeated alternating named captures no longer capture reliably under perl v5.38.0 #21563

Open
@thoughtstream

Description

@thoughtstream

This is a bug report for perl from [email protected],
generated with the help of perlbug 1.43 running under perl 5.38.0.


Description

When two named captures in two distinct |-branches
are sequentially matched inside a set of repeated parens
the captures sometimes do not correctly populate the %+ hash,
depending on the order in which they are matched.

Steps to Reproduce

    my $regex = qr{
        (?:
            (?<x> X )
        |   (?<y> Y )
        )+
    }xms;

    use Test::More;

    "XY" =~ $regex;
    is_deeply \%+, { x => 'X', y => 'Y' } => 'XY';

    "YX" =~ $regex;
    is_deeply \%+, { x => 'X', y => 'Y' } => 'YX';

    done_testing();

Expected behavior

Under perls v5.10 through v5.36, both matches correctly populate the %+ hash
with both captures.

Under perl v5.38.0, only the second match correctly populates %+ with both captures.
The first match throws away the first capture (i.e. of the 'X').

The same change in behaviour from v5.36 to v5.38 appears when named captures
are replaced by numbered captures. In that case, the @{^CAPTURE} variable is
not correctly populated under v5.38.0

This change breaks an idiom I frequently use to parse and label
sequences of distinct components.


Flags

  • category=core
  • severity=high

Perl configuration

Site configuration information for perl 5.38.0:

Configured by damian at Tue Jul  4 16:52:21 AEST 2023.

Summary of my perl5 (revision 5 version 38 subversion 0) configuration:
   
  Platform:
    osname=darwin
    osvers=21.6.0
    archname=darwin-2level
    uname='darwin cassandra.local 21.6.0 darwin kernel version 21.6.0: thu jun 8 23:56:13 pdt 2023; root:xnu-8020.240.18.701.6~1release_arm64_t6000 arm64 '
    config_args='-de -Dprefix=/Users/damian/perl5/perlbrew/perls/perl-5.38.0 -Aeval:scriptdir=/Users/damian/perl5/perlbrew/perls/perl-5.38.0/bin'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
  Compiler:
    cc='cc'
    ccflags ='-fno-common -DPERL_DARWIN -mmacosx-version-min=12.6 -DNO_POSIX_2008_LOCALE -fno-strict-aliasing -pipe -fstack-protector-strong'
    optimize='-O3'
    cppflags='-fno-common -DPERL_DARWIN -mmacosx-version-min=12.6 -DNO_POSIX_2008_LOCALE -fno-strict-aliasing -pipe -fstack-protector-strong'
    ccversion=''
    gccversion='Apple LLVM 14.0.0 (clang-1400.0.29.202)'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=8
    longdblkind=0
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -mmacosx-version-min=12.6 -fstack-protector-strong'
    libpth=/Library/Developer/CommandLineTools/usr/lib/clang/14.0.0/lib /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib /Library/Developer/CommandLineTools/usr/lib /usr/lib
    libs= 
    perllibs=
    libc=
    so=dylib
    useshrplib=false
    libperl=libperl.a
    gnulibc_version=''
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=bundle
    d_dlsymun=undef
    ccdlflags=' '
    cccdlflags=' '
    lddlflags=' -mmacosx-version-min=12.6 -bundle -undefined dynamic_lookup -fstack-protector-strong'


---
@INC for perl 5.38.0:
    ./lib
    /Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/perl5/darwin-thread-multi-2level/
    /Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/perl5/darwin-2level/
    /Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/perl5/darwin-2level
    /Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/perl5
    /Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/5.38.0/darwin-2level
    /Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/5.38.0
    /Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib
    /Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/site_perl/5.38.0/darwin-2level
    /Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/site_perl/5.38.0
    /Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/5.38.0/darwin-2level
    /Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/5.38.0

---
Environment for perl 5.38.0:
    DYLD_LIBRARY_PATH (unset)
    HOME=/Users/damian
    LANG=en_AU.UTF-8
    LANGUAGE (unset)
    LC_ALL=en_AU.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/Users/damian/perl5/perlbrew/bin:/Users/damian/perl5/perlbrew/perls/perl-5.38.0/bin:/Library/Frameworks/Python.framework/Versions/3.7/bin:.:/usr/local/opt/rakudo-star/bin:/Applications/Rakudo/bin:/Applications/Rakudo/share/perl6/site/bin:/Users/damian/bin:/Users/damian/bin/macintosh:/Users/damian/perl5/bin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/bin:/usr/bsd:/usr/bin:/usr/sbin:/usr/local/sbin:/usr/local/git/bin:/Applications/Graphviz.app/Contents/MacOS:/Applications/MacGhostView.app/Contents/Resources/bin:/Applications/MacGhostView_old.app/Contents/Resources/bin:/opt/homebrew/bin:/opt/homebrew/Cellar/rakudo-star/2022.06/share/perl6/site/bin
    PERL5LIB=./lib:/Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/perl5/darwin-thread-multi-2level/:/Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/perl5/darwin-2level/:/Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib/perl5:/Users/damian/perl5/perlbrew/perls/perl-5.38.0/lib
    PERL6LIB=./lib6:/Users/damian/lib/perl6
    PERLBREW_HOME=/Users/damian/.perlbrew
    PERLBREW_MANPATH=/Users/damian/perl5/perlbrew/perls/perl-5.38.0/man
    PERLBREW_PATH=/Users/damian/perl5/perlbrew/bin:/Users/damian/perl5/perlbrew/perls/perl-5.38.0/bin
    PERLBREW_PERL=perl-5.38.0
    PERLBREW_ROOT=/Users/damian/perl5/perlbrew
    PERLBREW_SHELLRC_VERSION=0.98
    PERLBREW_VERSION=0.98
    PERL_BADLANG (unset)
    PERL_CPANM_OPT=-M https://cpan.metacpan.org/
    PERL_MB_OPT=--install_base /Users/damian/perl5/perlbrew/perls/perl-5.38.0/
    PERL_MM_OPT=INSTALL_BASE=/Users/damian/perl5/perlbrew/perls/perl-5.38.0/
    SHELL=/bin/tcsh

Metadata

Metadata

Assignees

No one assigned

    Labels

    BBCBlead Breaks CPAN - changes in blead broke a cpan module(s)type-regex

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions