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

Owner: Nobody
Requestors: dolmen <dolmen [at] cpan.org>
Cc:
AdminCc:

Operating System: Linux
PatchStatus: (no value)
Severity: low
Type: core
Perl Version: 5.20.0
Fixed In: 5.22.0



Subject: Call on object overloading &{} returned by a constant -> fails to compile
From: Olivier Mengué <dolmen [...] cpan.org>
To: perlbug [...] perl.org
Date: Sun, 24 Aug 2014 23:54:46 +0300
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
RT-Send-CC: perl5-porters [...] perl.org
On Sun Aug 24 13:55:26 2014, dolmen wrote: Show quoted text
> 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.
That’s a known bug, or at least known to me. I don’t remember whether I have filed a ticket, but it’s on my to-do list. Basically there is a whole block of code in op.c:ck_rvconst that is ill-conceived and just needs to be deleted. I may do it tonight. (Then again, I may not.) -- Father Chrysostomos
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 1.1k
On Sun Aug 24 19:00:47 2014, sprout wrote: Show quoted text
> On Sun Aug 24 13:55:26 2014, dolmen wrote:
> > 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.
> > That’s a known bug, or at least known to me. I don’t remember whether > I have filed a ticket, but it’s on my to-do list. Basically there is > a whole block of code in op.c:ck_rvconst that is ill-conceived and > just needs to be deleted. I may do it tonight. (Then again, I may > not.)
Done in eff754733. -- Father Chrysostomos
Subject: Your ticket against Perl 5 has been resolved
Download (untitled) / with headers
text/plain 222b
Thanks for submitting this ticket The issue should be resolved with the release today of Perl v5.22. If you find that the problem persists, feel free to reopen this ticket -- Karl Williamson for the Perl 5 porters team
RT-Send-CC: perl5-porters [...] perl.org
Download (untitled) / with headers
text/plain 534b
Le Dim 24 Aoû 2014 13:55:26, dolmen a écrit : Show quoted text
> # == 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") ); > # ========================
Here are two workarounds I use for perl < 5.21.4: say do{ CONST_CLS }->("OK"); say &{ +CONST_CLS }("OK"); See Term::Chrome as real world use of &{} overloading and "use constant" combination. https://metacpan.org/pod/Term::Chrome


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