Skip to content

Unexpected syntax error in map when first element is literal #22716

@happy-barney

Description

@happy-barney

Description
There is unexpected syntax error when using map (see example)

Steps to Reproduce
Run following code:

package Foo {
	sub list {
		+{ name => 1 },
	}
};

my $self = bless {}, Foo::;

my @list1 = map { $_->{name} => $_ } $self->list;
my @list2 = map { "$_->{name}" => $_ } $self->list;
my @list3 = map { name => $_ } $self->list;

While list1 expression is ok, list2 and list3 ends with

syntax error at ..., near "} $self"

Update: using + (eg: +name) mitigates bug

Expected behavior
both list2 and list3 expressions should be valid

Perl configuration
tested with:

  • perl 5.28
  • perl 5.38
  • perl 5.40
    (perlbrew perls, -V for 5.40)
Summary of my perl5 (revision 5 version 40 subversion 0) configuration:
   
  Platform:
    osname=linux
    osvers=5.15.0-113-generic
    archname=x86_64-linux
    uname='linux happy-barney 5.15.0-113-generic #123-ubuntu smp mon jun 10 08:16:17 utc 2024 x86_64 x86_64 x86_64 gnulinux '
    config_args='-de -Dprefix=/home/brano/.cache/perlbrew/perls/perl-5.40 -Aeval:scriptdir=/home/brano/.cache/perlbrew/perls/perl-5.40/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 ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='11.4.0'
    gccosandvers=''
    intsize=4
    longsize=8
    ptrsize=8
    doublesize=8
    byteorder=12345678
    doublekind=3
    d_longlong=define
    longlongsize=8
    d_longdbl=define
    longdblsize=16
    longdblkind=3
    ivtype='long'
    ivsize=8
    nvtype='double'
    nvsize=8
    Off_t='off_t'
    lseeksize=8
    alignbytes=8
    prototype=define
  Linker and Libraries:
    ld='cc'
    ldflags =' -fstack-protector-strong -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib/x86_64-linux-gnu /usr/lib /usr/lib64
    libs=-lpthread -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -ldl -lm -lcrypt -lutil -lc
    libc=/lib/x86_64-linux-gnu/libc.so.6
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.35'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector-strong'


Characteristics of this binary (from libperl): 
  Compile-time options:
    HAS_LONG_DOUBLE
    HAS_STRTOLD
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_HASH_FUNC_SIPHASH13
    PERL_HASH_USE_SBOX32
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    PERL_USE_SAFE_PUTENV
    USE_64_BIT_ALL
    USE_64_BIT_INT
    USE_LARGE_FILES
    USE_LOCALE
    USE_LOCALE_COLLATE
    USE_LOCALE_CTYPE
    USE_LOCALE_NUMERIC
    USE_LOCALE_TIME
    USE_PERLIO
    USE_PERL_ATOF
  Built under linux
  Compiled at Jul  6 2024 19:31:58
  %ENV:
    PERL5LIB="/home/brano/.perlbrew/libs/perl-5.40@common/lib/perl5:/home/brano/lib/perl5/:/home/brano/lib/perl5/:/home/brano/lib/perl5/"
    PERLBREW_HOME="/home/brano/.perlbrew"
    PERLBREW_LIB="common"
    PERLBREW_MANPATH="/home/brano/.perlbrew/libs/perl-5.40@common/man:/home/brano/.cache/perlbrew/perls/perl-5.40/man"
    PERLBREW_PATH="/home/brano/.perlbrew/libs/perl-5.40@common/bin:/home/brano/.cache/perlbrew/bin:/home/brano/.cache/perlbrew/perls/perl-5.40/bin"
    PERLBREW_PERL="perl-5.40"
    PERLBREW_ROOT="/home/brano/.cache/perlbrew"
    PERLBREW_SHELLRC_VERSION="0.86"
    PERLBREW_VERSION="0.94"
    PERL_LOCAL_LIB_ROOT="/home/brano/.perlbrew/libs/perl-5.40@common"
    PERL_MB_OPT="--install_base /home/brano/.perlbrew/libs/perl-5.40@common"
    PERL_MM_OPT="INSTALL_BASE=/home/brano/.perlbrew/libs/perl-5.40@common"
  @INC:
    /home/brano/.perlbrew/libs/perl-5.40@common/lib/perl5/x86_64-linux
    /home/brano/.perlbrew/libs/perl-5.40@common/lib/perl5
    /home/brano/lib/perl5/
    /home/brano/lib/perl5/
    /home/brano/lib/perl5/
    /home/brano/.cache/perlbrew/perls/perl-5.40/lib/site_perl/5.40.0/x86_64-linux
    /home/brano/.cache/perlbrew/perls/perl-5.40/lib/site_perl/5.40.0
    /home/brano/.cache/perlbrew/perls/perl-5.40/lib/5.40.0/x86_64-linux
    /home/brano/.cache/perlbrew/perls/perl-5.40/lib/5.40.0

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