Skip Menu |
Report information
Id: 132634
Status: resolved
Priority: 0/
Queue: perl5

Owner: Nobody
Requestors: trizen [at] protonmail.com
Cc:
AdminCc:

Operating System: (no value)
PatchStatus: (no value)
Severity: low
Type: unknown
Perl Version: (no value)
Fixed In: (no value)



From: Trizen <trizen [...] protonmail.com>
Subject: Strange bug in the new given/whereis/whereso construct (perl-5.27.7)
To: "perlbug [...] perl.org" <perlbug [...] perl.org>
Date: Thu, 21 Dec 2017 00:46:31 -0500
Download (untitled) / with headers
text/plain 4.5k
Download (untitled) / with headers
text/html 14.1k
Hi,

There seems to be a minor bug in the simplified version of given/when, as illustrated in the following code:

# ======BEGIN-OF-CODE======

use 5.027007;
use experimental qw(smartmatch);

package FooObj {

    use overload
      '~~'  => sub { 1 },
      q{""} => sub { 'foo' };

    sub new { bless {} }

    sub append {
        say "In append: $_[1]";
    }
}

my $obj = FooObj->new;

$obj->append(
    do {
        given (FooObj->new) {

            my $t = qr/bar/;

            my $v = do {     # this seems to cause it
                whereis($t) { 'incorrect' }
            };

            whereis(FooObj->new()) { 'correct' }
        }
      }
);

# ======END-OF-CODE======

The expected output is "In append: correct".

The output under perl-5.27.7 is:

Can't call method "append" on an undefined value at bug.pl line 21.

For some reason, the $obj variable magically becomes undefined.

Output of perlbug -d:

---
Flags:
    category=core
    severity=low
---
Site configuration information for perl 5.27.7:

Configured by swampyx at Thu Dec 21 06:00:57 EET 2017.

Summary of my perl5 (revision 5 version 27 subversion 7) configuration:
  
  Platform:
    osname=linux
    osvers=4.14.7-1-arch
    archname=x86_64-linux-thread-multi
    uname='linux arch 4.14.7-1-arch #1 smp preempt sun dec 17 19:13:39 utc 2017 x86_64 gnulinux '
    config_args='-de -Dprefix=/home/swampyx/perl5/perlbrew/perls/perl-5.27.7 -Doptimize=-march=native -Ofast -pipe -Dman1dir=none -Dman3dir=none -Dusethreads -Dusemultiplicity -Dusedevel -Aeval:scriptdir=/home/swampyx/perl5/perlbrew/perls/perl-5.27.7/bin'
    hint=recommended
    useposix=true
    d_sigaction=define
    useithreads=define
    usemultiplicity=define
    use64bitint=define
    use64bitall=define
    uselongdouble=undef
    usemymalloc=n
    default_inc_excludes_dot=define
    bincompat5005=undef
  Compiler:
    cc='cc'
    ccflags ='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_FORTIFY_SOURCE=2'
    optimize='-march=native -Ofast -pipe'
    cppflags='-D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/local/include'
    ccversion=''
    gccversion='7.2.1 20171128'
    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/gcc/x86_64-pc-linux-gnu/7.2.1/include-fixed /usr/lib /lib/../lib /usr/lib/../lib /lib /lib64 /usr/lib64
    libs=-lpthread -lnsl -lgdbm -ldb -ldl -lm -lcrypt -lutil -lc -lgdbm_compat
    perllibs=-lpthread -lnsl -ldl -lm -lcrypt -lutil -lc
    libc=libc-2.26.so
    so=so
    useshrplib=false
    libperl=libperl.a
    gnulibc_version='2.26'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs
    dlext=so
    d_dlsymun=undef
    ccdlflags='-Wl,-E'
    cccdlflags='-fPIC'
    lddlflags='-shared -march=native -Ofast -pipe -L/usr/local/lib -fstack-protector-strong'

Locally applied patches:
    Devel::PatchPerl 1.48

---
@INC for perl 5.27.7:
    /home/swampyx/perl5/perlbrew/perls/perl-5.27.7/lib/site_perl/5.27.7/x86_64-linux-thread-multi
    /home/swampyx/perl5/perlbrew/perls/perl-5.27.7/lib/site_perl/5.27.7
    /home/swampyx/perl5/perlbrew/perls/perl-5.27.7/lib/5.27.7/x86_64-linux-thread-multi
    /home/swampyx/perl5/perlbrew/perls/perl-5.27.7/lib/5.27.7

---
Environment for perl 5.27.7:
    HOME=/home/swampyx
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LC_CTYPE=en_US.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/swampyx/perl5/perlbrew/bin:/home/swampyx/perl5/perlbrew/perls/perl-5.27.7/bin:/usr/lib/ccache/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/usr/share/perl6/vendor/bin
    PERL5LIB=
    PERLBREW_LIB=
    PERLBREW_MANPATH=/home/swampyx/perl5/perlbrew/perls/perl-5.27.7/man
    PERLBREW_PATH=/home/swampyx/perl5/perlbrew/bin:/home/swampyx/perl5/perlbrew/perls/perl-5.27.7/bin
    PERLBREW_PERL=perl-5.27.7
    PERLBREW_ROOT=/home/swampyx/perl5/perlbrew
    PERLBREW_SKIP_INIT=1
    PERLBREW_VERSION=0.82
    PERL_BADLANG (unset)
    PERL_LOCAL_LIB_ROOT=
    SHELL=/usr/bin/zsh



Sent with ProtonMail Secure Email.

Download bug.pl
text/x-perl 488b

Message body is not shown because sender requested not to inline it.

To: perl5-porters [...] perl.org
Date: Sat, 23 Dec 2017 04:55:32 +0000
From: Zefram <zefram [...] fysh.org>
Subject: Re: [perl #132634] Strange bug in the new given/whereis/whereso construct (perl-5.27.7)
Download (untitled) / with headers
text/plain 701b
Trizen wrote: Show quoted text
>There seems to be a minor bug in the simplified version of given/when,
Thanks, that's interesting. Turns out it doesn't need any actual smartmatching, overloading or regexps. It reduces to: $ perl5.27.7 -Mexperimental=smartmatch -Mfeature=switch -lwe 'bless({})->append(do { given (3) { my $v = do { whereso(0) { } }; } });' Can't call method "append" on an undefined value at -e line 1. and it's not specific to the new version of switch, it also happens on the old version: $ perl5.27.6 -Mexperimental=smartmatch -Mfeature=switch -lwe 'bless({})->append(do { given (3) { my $v = do { when(0) { } }; } });' Can't call method "append" on an undefined value at -e line 1. -zefram
From: Zefram <zefram [...] fysh.org>
Subject: Re: [perl #132634] Strange bug in the new given/whereis/whereso construct (perl-5.27.7)
To: perl5-porters [...] perl.org
Date: Sat, 23 Dec 2017 05:48:50 +0000
Fixed in commit b98da25d1df8fcfc0b2bcb79d46a7624d3d98ea5. -zefram


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

For issues related to this RT instance (aka "perlbug"), please contact perlbug-admin at perl.org