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

Behavior difference in warning for overriding constant v.s. non-constant subroutines #13818

Open
p5pRT opened this issue May 10, 2014 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented May 10, 2014

Migrated from rt.perl.org#121841 (status was 'open')

Searchable as RT121841$

@p5pRT
Copy link
Author

p5pRT commented May 10, 2014

From @avar

Created by @avar

perlsub/Constant-Functions notes that even the -w flag you'll get a
warning if you clobber a constant subroutine, however when not under
-w oddly this warning only kicks in if you override the subroutine to
a *different* value, unlike the standard warning for clobbered
subroutines​:

  1. $ ./perl -e 'sub x () {1} sub x () {1}'
  2. $ ./perl -e 'sub x () {1} sub x () {2}'
  2. Constant subroutine x redefined at -e line 1.
  3. $ ./perl -we 'sub x () {1} sub x () {1}'
  3. Constant subroutine x redefined at -e line 1.
  4. $ ./perl -we 'sub x () {1} sub x () {2}'
  4. Constant subroutine x redefined at -e line 1.
  5. $ ./perl -e 'sub y {1} sub y {1}'
  5. $ ./perl -e 'sub y {1} sub y {2}'
  6. $ ./perl -we 'sub y {1} sub y {1}'
  6. Subroutine y redefined at -e line 1.
  7. $ ./perl -we 'sub y {1} sub y {2}'
  7. Subroutine y redefined at -e line 1.

I think it makes sense that if we're going to warn about #2 we should
also warn about #1 just like we warn about #1 if the -w flag is added,
see example #3.

If something's overriding a constant subroutine it should probably
know about it sooner than later, since even if the value is the same
*now* it might change in the future.

While trying to come up with an example for that I found another bug,
even when the value is different we don't warn at all about the
clobbering without C<-w> if the value is an inlined lexical​:

  8. $ ONE=1 TWO=1 ./perl -e 'BEGIN { my ($one, $two) = @​$ENV{qw/ONE TWO/}; *one = sub () { $one }; *one = sub () { $two }; }'
  9. $ ONE=1 TWO=2 ./perl -e 'BEGIN { my ($one, $two) = @​$ENV{qw/ONE TWO/}; *one = sub () { $one }; *one = sub () { $two }; }'
  10. $ ONE=1 TWO=1 ./perl -we 'BEGIN { my ($one, $two) = @​$ENV{qw/ONE TWO/}; *one = sub () { $one }; *one = sub () { $two }; }'
  10. Constant subroutine main​::one redefined at -e line 1.
  11. $ ONE=1 TWO=2 ./perl -we 'BEGIN { my ($one, $two) = @​$ENV{qw/ONE TWO/}; *one = sub () { $one }; *one = sub () { $two }; }'
  11. Constant subroutine main​::one redefined at -e line 1.

I think #8 and #9 sohuld warn just like #10 and #11 do.

Perl Info

Flags:
    category=core
    severity=low

Site configuration information for perl 5.19.12:

Configured by avar at Tue May  6 20:15:43 UTC 2014.

Summary of my perl5 (revision 5 version 19 subversion 12) configuration:
  Local Commit: c79b1a42f39835c5c6d9cd75f5827999e08f7233
  Ancestor: bd67a7ab132c11881802158345a5fc2cf0d95611
  Platform:
    osname=linux, osvers=3.2.0-4-amd64, archname=x86_64-linux-thread-multi
    uname='linux u.nix.is 3.2.0-4-amd64 #1 smp debian 3.2.35-2 x86_64 gnulinux '
    config_args='-DDEBUGGING=both -Doptimize=-ggdb3 -Dusethreads -Dprefix=/home/avar/perl5/installed -Dusedevel -des'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    use64bitint=define, use64bitall=define, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64',
    optimize='-ggdb3',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBUGGING -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include'
    ccversion='', gccversion='4.2.1 Compatible Debian Clang 3.3 (branches/release_33)', 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/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 -ldb -ldl -lm -lcrypt -lutil -lpthread -lc
    perllibs=-lnsl -ldl -lm -lcrypt -lutil -lpthread -lc
    libc=libc-2.18.so, so=so, useshrplib=false, libperl=libperl.a
    gnulibc_version='2.18'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -ggdb3 -L/usr/local/lib -fstack-protector'

Locally applied patches:
    c79b1a42f39835c5c6d9cd75f5827999e08f7233


@INC for perl 5.19.12:
    lib
    /home/avar/perl5/installed/lib/site_perl/5.19.12/x86_64-linux-thread-multi
    /home/avar/perl5/installed/lib/site_perl/5.19.12
    /home/avar/perl5/installed/lib/5.19.12/x86_64-linux-thread-multi
    /home/avar/perl5/installed/lib/5.19.12
    .


Environment for perl 5.19.12:
    HOME=/home/avar
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/avar/local/bin:/home/v-perlbrew/perl5/perlbrew/perls/perl-5.19.6/bin:/home/v-perlbrew/perl5/perlbrew/bin:/home/v-perlbrew/perl5/perlbrew/perls/current/bin:/home/avar/local/bin:/home/avar/g/misc-scripts:/home/avar/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
    PERLDOC=-MPod::Text::Ansi
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Sep 7, 2014

From @cpansprout

On Sat May 10 02​:24​:53 2014, avar wrote​:

1. $ ./perl -e 'sub x () {1} sub x () {1}'
2. $ ./perl -e 'sub x () {1} sub x () {2}'
2. Constant subroutine x redefined at -e line 1.
3. $ ./perl -we 'sub x () {1} sub x () {1}'
3. Constant subroutine x redefined at -e line 1.
4. $ ./perl -we 'sub x () {1} sub x () {2}'
4. Constant subroutine x redefined at -e line 1.
5. $ ./perl -e 'sub y {1} sub y {1}'
5. $ ./perl -e 'sub y {1} sub y {2}'
6. $ ./perl -we 'sub y {1} sub y {1}'
6. Subroutine y redefined at -e line 1.
7. $ ./perl -we 'sub y {1} sub y {2}'
7. Subroutine y redefined at -e line 1.

I think it makes sense that if we're going to warn about #2 we should
also warn about #1 just like we warn about #1 if the -w flag is added,
see example #3.

If we do change this, we need to make sure that different CVs deriving from the same ‘use constant’ constant need to be exempt from the warning, since the fact that there are two separate CVs is a side effect of the implementation, not a feature per se. I.e., this should not warn​:

package Foo;

require Exporter;
@​ISA = Exporter;
@​EXPORT_OK = "foo";
use constant "foo" => "oof";
$INC{"Foo.pm"}++;

package main;

use Foo "foo";
$_ = &foo;
use Foo "foo"; # this should not warn

--

Father Chrysostomos

@p5pRT
Copy link
Author

p5pRT commented Sep 7, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants