develooper Front page | perl.perl5.porters | Postings from August 2013

[perl #119501] can change the value of 4

From:
Zefram
Date:
August 28, 2013 09:47
Subject:
[perl #119501] can change the value of 4
Message ID:
rt-3.6.HEAD-1873-1377683219-930.119501-75-0@perl.org
# New Ticket Created by  Zefram 
# Please include the string:  [perl #119501]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org:443/rt3/Ticket/Display.html?id=119501 >



This is a bug report for perl from zefram@fysh.org,
generated with the help of perlbug 1.39 running under perl 5.19.3.


-----------------------------------------------------------------
[Please describe your issue here]

$ perl5.19.3 -lwe 'for(1..3) { my $x = \(3+1); print $$x; $$x = 5; }'
4
5
5

I'd expect that the sequence "my $x = \(3+1); print $$x;" would always
print 4.  Whether assignment to $$x is then permitted is up for debate,
but such assignment mustn't break the behaviour of the next execution
of that 4-printing code.

Perl 5.19.2 and earlier do not permit the assignment ("Modification of
a read-only value attempted").  Because it's immutable, it's acceptable
for \(3+1) to reference the same 4 each time.  5.19.3 is also referencing
the same scalar each time, but now it's a variable, so referencing the
same one each time is semantically significant.

Interestingly, if "\(3+1)" is replaced with "\4" then 5.19.3 prohibits
the assignment, just as earlier Perls do.  Also, if it's replaced with
"\(3+$z)", with $z initialised to 1, both 5.19.3 and earlier Perls permit
the assignment and print 4 each time, indicating that they're generating
a fresh variable each time.

I think FC was aiming to resolve the inconsistency of what the addition
operator returns.  He seems to have aimed for a literal expression to
consistently return an immutable scalar while an arithmetic expression
consistently returns a mutable scalar.  The bit that's missing is that
it needs to consistently be a *fresh* mutable scalar.

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags:
    category=core
    severity=medium
---
Site configuration information for perl 5.19.3:

Configured by root at Wed Aug 21 10:26:55 UTC 2013.

Summary of my perl5 (revision 5 version 19 subversion 3) configuration:
   
  Platform:
    osname=linux, osvers=2.6.32-5-686, archname=i686-linux-64int-ld
    uname='linux beryllium.photobox.priv 2.6.32-5-686 #1 smp mon feb 25 01:04:36 utc 2013 i686 gnulinux '
    config_args='-des -Dusedevel -Uversiononly -Duseshrplib -Duse64bitint -Duselongdouble -Uusethreads -Uusemultiplicity -Dprefix=/opt/perl-5.19.3 -Dsiteprefix=/opt/perl-5.19.3 -Dvendorprefix=/opt/perl-5.19.3/vendor -Doptimize=-ggdb -O2 -Dcccdlflags=-fPIC -O2 -pipe'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=define, use64bitall=undef, uselongdouble=define
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-ggdb -O2',
    cppflags='-fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.7.2', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long long', ivsize=8, nvtype='long double', nvsize=12, Off_t='off_t', lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -fstack-protector -L/usr/local/lib'
    libpth=/usr/local/lib /lib/i386-linux-gnu /lib/../lib /usr/lib/i386-linux-gnu /usr/lib/../lib /lib /usr/lib
    libs=-lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=, so=so, useshrplib=true, libperl=libperl.so
    gnulibc_version='2.13'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E -Wl,-rpath,/opt/perl-5.19.3/lib/5.19.3/i686-linux-64int-ld/CORE'
    cccdlflags='-fPIC -O2 -pipe', lddlflags='-shared -ggdb -O2 -L/usr/local/lib -fstack-protector'


---
@INC for perl 5.19.3:
    /opt/perl-5.19.3/lib/site_perl/5.19.3/i686-linux-64int-ld
    /opt/perl-5.19.3/lib/site_perl/5.19.3
    /opt/perl-5.19.3/vendor/lib/vendor_perl/5.19.3/i686-linux-64int-ld
    /opt/perl-5.19.3/vendor/lib/vendor_perl/5.19.3
    /opt/perl-5.19.3/lib/5.19.3/i686-linux-64int-ld
    /opt/perl-5.19.3/lib/5.19.3
    .

---
Environment for perl 5.19.3:
    HOME=/root
    LANG (unset)
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/opt/perl-5.19.3/bin:/root/pub/i686-pc-linux-gnu/bin:/root/pub/common/bin:/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin:/usr/games:/opt/geoip/bin:/opt/httpd/bin:/opt/perl/bin
    PERL_BADLANG (unset)
    SHELL=/usr/bin/zsh




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About