Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call on object overloading &{} returned by a constant -> fails to compile #14044

Closed
p5pRT opened this issue Aug 24, 2014 · 8 comments

Comments

@p5pRT
Copy link
Collaborator

@p5pRT p5pRT commented Aug 24, 2014

Migrated from rt.perl.org#122607 (status was 'resolved')

Searchable as RT122607$

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Aug 24, 2014

From @dolmen

Created by dolmen@cpan.org

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

Perl Info

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

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Aug 25, 2014

From @cpansprout

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.)

--

Father Chrysostomos

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Aug 25, 2014

The RT System itself - Status changed from 'new' to 'open'

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Aug 25, 2014

From @cpansprout

On Sun Aug 24 19​:00​:47 2014, sprout wrote​:

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 eff7547.

--

Father Chrysostomos

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Aug 25, 2014

@cpansprout - Status changed from 'open' to 'pending release'

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Jun 2, 2015

From @khwilliamson

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

@p5pRT p5pRT closed this Jun 2, 2015
@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Jun 2, 2015

@khwilliamson - Status changed from 'pending release' to 'resolved'

@p5pRT

This comment has been minimized.

Copy link
Collaborator Author

@p5pRT p5pRT commented Jun 28, 2016

From @dolmen

Le Dim 24 Aoû 2014 13​:55​:26, dolmen a écrit :

# == 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.