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

[perl #122607] Call on object overloading &{} returned by a constant -> fails to compile

Thread Previous
From:
Olivier Mengué
Date:
August 24, 2014 20:55
Subject:
[perl #122607] Call on object overloading &{} returned by a constant -> fails to compile
Message ID:
rt-4.0.18-28945-1408913726-1197.122607-75-0@perl.org
# New Ticket Created by  Olivier Mengué 
# Please include the string:  [perl #122607]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=122607 >


This is a bug report for perl from dolmen@cpan.org,
generated with the help of perlbug 1.40 running under perl 5.20.0.


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


This (maybe parser-related) issue is a combination of:
- a class overloading CODE deref &{}
- a constant object of that class (declared with 'use constant')
- dereferencing the value of that constant (that has probably been inlined)
  to call it as a method.

Result: the code doesn't pass compile and perl reports:
    "Constant is not a CODE reference"

This is real code that I'm trying to use in a future release of my module
Test::Chrome.

Here is a the reduced case that says more:

-------8<-------8<-------8<-------8<-------8<-------8<-------
use feature 'say';

{
    package Cls;
    use overload '&{}' => sub { sub { "< $_[0] >" } };
}

use constant CONST_CLS => bless [], 'Cls';

# == This works ==========
my $x = CONST_CLS;
say( $x->("OK") );
# ========================

# == This doesn't works ==
# Compile fails: "Constant is not a CODE reference"
#say( CONST_CLS->("OK") );
# ========================

-------8<-------8<-------8<-------8<-------8<-------8<-------


Olivier Mengué (DOLMEN), from YAPC::EU::2014

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

Configured by dolmen at Sat May 31 00:03:03 CEST 2014.

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

  Platform:
    osname=linux, osvers=3.13.0-24-generic, archname=x86_64-linux
    uname='linux carbon 3.13.0-24-generic #47-ubuntu smp fri may 2 23:30:00
utc 2014 x86_64 x86_64 x86_64 gnulinux '
    config_args='-Dprefix=/home/dolmen/.plenv/versions/5.20.0 -de
-Dusedevel -A'eval:scriptdir=/home/dolmen/.plenv/versions/5.20.0/bin''
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=undef, usemultiplicity=undef
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, 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',
    optimize='-O2',
    cppflags='-fwrapv -fno-strict-aliasing -pipe -fstack-protector
-I/usr/local/include'
    ccversion='', gccversion='4.8.2', gccosandvers=''
    intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    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/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
/usr/include/x86_64-linux-gnu /usr/lib /lib/x86_64-linux-gnu /lib/../lib
/usr/lib/x86_64-linux-gnu /usr/lib/../lib /lib
    libs=-lnsl -ldl -lm -lcrypt -lutil -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc
    libc=, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.19'
  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'


---
@INC for perl 5.20.0:

/home/dolmen/.plenv/versions/5.20.0/lib/perl5/site_perl/5.20.0/x86_64-linux
    /home/dolmen/.plenv/versions/5.20.0/lib/perl5/site_perl/5.20.0
    /home/dolmen/.plenv/versions/5.20.0/lib/perl5/5.20.0/x86_64-linux
    /home/dolmen/.plenv/versions/5.20.0/lib/perl5/5.20.0
    .

---
Environment for perl 5.20.0:
    HOME=/home/dolmen
    LANG=fr_FR.UTF-8
    LANGUAGE=fr_FR
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=/home/dolmen/.plenv/versions/5.20.0/bin:/home/dolmen/.plenv/libexec:/home/dolmen/.plenv/plugins/perl-build/bin:/home/dolmen/.nvm/v0.11.13/bin:/home/dolmen/bin:/home/dolmen/.plenv/shims:/home/dolmen/.plenv/bin:/home/dolmen/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
    PERL_BADLANG (unset)
    SHELL=/bin/bash


Thread Previous


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