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

[ID 20010812.010] closure references wrong value of external lexical

Thread Previous | Thread Next
From:
joe
Date:
August 12, 2001 16:57
Subject:
[ID 20010812.010] closure references wrong value of external lexical
Message ID:
200108122356.f7CNux022822@mumonkan.sunstarsys.com

This is a bug report for perl from joe@sunstarsys.com,
generated with the help of perlbug 1.33 running under perl v5.6.1.


-----------------------------------------------------------------
[Please enter your report here]

Anonymous subs that reference variables from the "grandparent scope"
don't seem to use the right value unless the variable also appears
in the "parent scope".

Here's some code that I would typically expect to produce:

        bar
        bar
        bar
        bar

as output.  Alas, it doesn't on linux 5.6.0 or 5.00503.

#!/usr/bin/perl -wl
use strict;
{
  my $x = "bar";

  sub foo {

    if (@_) {
        $x if 0;        # noop ?
        return sub {$x};
    }

    return sub {$x};
  }
}

  print foo(1)->();     # bar
  print foo()->();      # undefined
  print foo(1)->();     # bar
  print foo()->();      # undefined

__END__



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

Configured by joe at Tue Jun 12 14:52:01 EDT 2001.

Summary of my perl5 (revision 5.0 version 6 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.4.3, archname=i586-linux-thread-multi
    uname='linux mumonkan.sunstarsys.com 2.4.3 #3 thu apr 26 11:39:34 edt 2001 i586 unknown '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=define use5005threads=undef useithreads=define usemultiplicity=define
    useperlio=define d_sfio=define uselargefiles=define usesocks=undef
    use64bitint=undef use64bitall=undef uselongdouble=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/gnu/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g',
    cppflags='-D_REENTRANT -DDEBUGGING -fno-strict-aliasing -I/usr/local/include -I/usr/gnu/include'
    ccversion='', gccversion='2.96 20000731 (Red Hat Linux 7.0)', gccosandvers=''
    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', lseeksize=8
    alignbytes=4, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib -L/usr/gnu/lib'
    libpth=/usr/local/lib /usr/gnu/lib /lib /usr/lib
    libs=-lsfio -lnsl -lndbm -lgdbm -ldl -lm -lpthread -lc -lposix -lcrypt -lutil
    perllibs=-lsfio -lnsl -ldl -lm -lpthread -lc -lposix -lcrypt -lutil
    libc=/lib/libc-2.1.92.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib -L/usr/gnu/lib'

Locally applied patches:
    

---
@INC for perl v5.6.1:
    /usr/lib/perl5/5.6.1/i586-linux-thread-multi
    /usr/lib/perl5/5.6.1
    /usr/lib/perl5/site_perl/5.6.1/i586-linux-thread-multi
    /usr/lib/perl5/site_perl/5.6.1
    /usr/lib/perl5/site_perl
    /usr/local/lib/perl5/vendor/lib/perl5/vendor_perl/5.6.1/i586-linux-thread-multi
    /usr/local/lib/perl5/vendor/lib/perl5/vendor_perl/5.6.1
    /usr/local/lib/perl5/vendor/lib/perl5/vendor_perl
    .

---
Environment for perl v5.6.1:
    HOME=/home/joe
    LANG=en_US
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/usr/kerberos/sbin:/home/joe/bin:/home/joe/bin:/usr/kerberos/bin:/usr/bin:/bin:/usr/X11R6/bin:/usr/local/bin:/opt/bin:/usr/gnu/bin:/usr/X11R6/bin:/usr/bin/mh:/usr/gnu/bin:/usr/X11R6/bin:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh:/usr/bin/mh
    PERL_BADLANG (unset)
    SHELL=/bin/bash



Thread Previous | Thread Next


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