Skip to content

dereferencing result of ternary operator skips autovivification #18669

Open
@spuelrich

Description

@spuelrich

Description
Using the ternary conditional operator together with autovivification and dereferencing works no more in v5.32.

Steps to Reproduce

Example 1: Push a value onto a dereferenced hash entry, which does not yet exist:

> perl -MData::Dumper -wE 'my $x={arr=>undef}; push( @{$x->{decide} ? $x->{not_there} : $x->{new}} , "nana"); say Data::Dumper::Dumper($x)'
Not an ARRAY reference at -e line 1.

Example 2: Pushing onto an existing, but undefined hash entry

> perl -MData::Dumper -wE 'my $x={arr=>undef}; push( @{$x->{decide} ? $x->{not_there} : $x->{arr}} , "nana"); say Data::Dumper::Dumper($x)'
Not an ARRAY reference at -e line 1.

Problem can be reproduced with strawberry perl and self-compiled perl under linux.

Expected behavior
Same code works with older perl v5.30.3.1

Example 1:

> perl -MData::Dumper -wE 'my $x={arr=>undef}; push( @{$x->{decide} ? $x->{not_there} : $x->{new}} , "nana"); say Data::Dumper::Dumper($x)'
$VAR1 = {
          'new' => [
                     'nana'
                   ],
          'arr' => undef
        };

Example 2:

> perl -MData::Dumper -wE 'my $x={arr=>undef}; push( @{$x->{decide} ? $x->{not_there} : $x->{arr}} , "nana"); say Data::Dumper::Dumper($x)'
$VAR1 = {
          'arr' => [
                     'nana'
                   ]
        };

Perl configuration

Summary of my perl5 (revision 5 version 32 subversion 0) configuration:

  Platform:
    osname=linux
    osvers=4.12.14-95.54-default
    archname=x86_64-linux
    uname='linux sles12sp4 4.12.14-95.54-default #1 smp thu jun 4 12:49:28 utc 2020 (892ef1f) x86_64 x86_64 x86_64 gnulinux '
    config_args='-des -Dprefix=/opt/perl-5.32.0/ -Duserelocatableinc -Duse64bitint'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=undef
    usemultiplicity=undef
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-O2'
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion=''
    gccversion='4.8.5'
    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 -L/usr/local/lib'
    libpth=/usr/local/lib /usr/lib64/gcc/x86_64-suse-linux/4.8/include-fixed /usr/lib64/gcc/x86_64-suse-linux/4.8/../../../../x86_64-suse-linux/lib /usr/lib /lib/../lib64 /usr/lib/../lib64 /lib /lib64 /usr/lib64 /usr/local/lib64
    libs=-lpthread -lnsl -ldb -ldl -lm -lcrypt -lutil -lc
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.22.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.22'
  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'


Characteristics of this binary (from libperl):
  Compile-time options:
    HAS_TIMES
    PERLIO_LAYERS
    PERL_COPY_ON_WRITE
    PERL_DONT_CREATE_GVSV
    PERL_MALLOC_WRAP
    PERL_OP_PARENT
    PERL_PRESERVE_IVUV
    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 Dec 14 2020 15:22:37
  @INC:
    /work/perl/v5.32.0.1/linux/lib/site_perl/5.32.0/x86_64-linux
    /work/perl/v5.32.0.1/linux/lib/site_perl/5.32.0
    /work/perl/v5.32.0.1/linux/lib/5.32.0/x86_64-linux
    /work/perl/v5.32.0.1/linux/lib/5.32.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions