develooper Front page | perl.perl5.porters | Postings from July 2008

[perl #57012] Result of FETCH not checked for overload?

Steve Fink
July 16, 2008 14:40
[perl #57012] Result of FETCH not checked for overload?
Message ID:
# New Ticket Created by  "Steve Fink" 
# Please include the string:  [perl #57012]
# in the subject line of all future correspondence about this issue. 
# <URL: >

This is a bug report for perl from,
generated with the help of perlbug 1.35 running under perl v5.8.8.

[Please enter your report here]

I have a tie'd variable %h that returns values from its FETCH()
routine that are blessed into a package that uses overloads.
When I use the += operator on the return value from that FETCH,
the overloading is ignored.

If I use the + operator, it works fine.

Example (uncomment the two commented-out lines to prove that
the overloading is ignored):

package Over;

use overload '+' => \&add;
#use overload '+=' => \&add2;
use overload '""' => \&toString;

sub add {
  my ($a, $b, $swapped) = @_;
  return bless [ $a->[0] + $b->[0], $a->[1] + $b->[1] ], 'Over';

#sub add2 { die "add2 called" }

sub toString {
  my ($self) = @_;
  return "<$self->[0],$self->[1]>";

package Tied;

  my ($selfpkg, $data) = @_;
  return bless \$data, $selfpkg;

sub FETCH {
  my ($self, $key) = @_;
  return bless [ $key, $key ], 'Over';

sub STORE {
  my ($self, $key, $value) = @_;
  print "STORE($key,$value) called\n";

package main;

my $v = bless [ 1, 2 ], 'Over';

my %h;
tie %h, 'Tied';

print "v = $v\n";
print "h{1} = $h{1}\n";
print "h{1} + [10,10] = ", ($h{1} + [10,10]), "\n";
print "h{1} += [10,10] = ", ($h{1} += [10,10]), "\n";
# The overloading was ignored on the previous line. It correctly
# fetched key '1' and converted it into a blessed ref, but then
# when it applied the += operator to the result, it didn't respect
# the overloading.

[Please do not change anything below this line]
This perlbug was built using Perl v5.8.8 in the Red Hat build system.
It is being executed now by Perl v5.8.8 - Thu Jan  3 23:26:16 PST 2008.

Site configuration information for perl v5.8.8:

Configured by Red Hat, Inc. at Thu Jan  3 23:26:16 PST 2008.

Summary of my perl5 (revision 5 version 8 subversion 8) configuration:
    osname=linux, osvers=2.6.18-8.el5, archname=i386-linux-thread-multi
    uname='linux 2.6.18-8.el5 #1 smp thu mar 15
19:57:35 edt 2007 i686 i686 i386 gnulinux '
    config_args='-des -Doptimize=-O2 -g -march=i386 -mcpu=i686
-Dversion=5.8.8 -Dmyhostname=localhost -Dperladmin=root@localhost
-Dcc=gcc -Dcf_by=Red Hat, Inc. -Dinstallprefix=/usr -Dprefix=/usr
-Darchname=i386-linux -Dvendorprefix=/usr -Dsiteprefix=/usr
-Duseshrplib -Dusethreads -Duseithreads -Duselargefiles -Dd_mymalloc
-Dusemymalloc -Dd_dosuid -Dd_semctl_semun -Di_db -Ui_ndbm -Di_gdbm
-Di_shadow -Di_syslog -Dman3ext=3pm -Duseperlio -Dinstallusrbinperl=n
-Ubincompat5005 -Uversiononly -Dpager=/usr/bin/less -isr
-Dd_gethostent_r_proto -Ud_endhostent_r_proto -Ud_sethostent_r_proto
-Ud_endprotoent_r_proto -Ud_setprotoent_r_proto -Ud_endservent_r_proto
-Ud_setservent_r_proto -Dinc_version_list=5.8.7 5.8.6 5.8.5
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define
    useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
    usemymalloc=y, bincompat5005=undef
    cc='gcc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING
-fno-strict-aliasing -pipe -Wdeclaration-after-statement
    optimize='-O2 -g -march=i386 -mcpu=i686',
-fno-strict-aliasing -pipe -Wdeclaration-after-statement
-I/usr/local/include -I/usr/include/gdbm'
    ccversion='', gccversion='4.1.1 20070105 (Red Hat 4.1.1-52)',
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lresolv -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lresolv -lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=/lib/, so=so, useshrplib=true,
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -march=i386
-mcpu=i686 -L/usr/local/lib'

Locally applied patches:

@INC for perl v5.8.8:

Environment for perl v5.8.8:
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PERL_BADLANG (unset)
    SHELL=/bin/zsh Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About