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

warnings::register regressions introduced in 5.10 #9631

Closed
p5pRT opened this issue Jan 20, 2009 · 17 comments
Closed

warnings::register regressions introduced in 5.10 #9631

p5pRT opened this issue Jan 20, 2009 · 17 comments

Comments

@p5pRT
Copy link

p5pRT commented Jan 20, 2009

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

Searchable as RT62522$

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2009

From @ribasushi

Created by rabbit@rabbit.us

After upgrading to 5.10 warnings​::register related warning suppression
does not work as expected in all cases (i.e. as it did in 5.8). Please
find a complete and well documented 16 point test suite attached to this
message (or at http​://rabbit.us/diff/5.10_lexwarn_register.tar.bz2)

It passes under 5.8 but breaks in 4 places under 5.10​:

Failures 5 & 6

Let's have Module S which inherits from module C.

In module C we have​:

use warnings​::register;

....

sub work {
  ...
  warnings​::warnif ('stuff happened');
  ...
}

in module S we have​:

sub start_work {
  ...
  no warnings 'C';
  C->work;
}

Now if a user invokes S->start_work under 5.8 there will be no warning
as expected. Not so under 5.10

Failure 12

Same as above, but class S is generated on the fly via a string eval
(eval '...');

Failure 15

Same as 12, but instead of no warnings 'C', even an unqualified
no warnings doesn't work

Perl Info

Flags:
    category=library
    severity=medium

Site configuration information for perl 5.10.0:

Configured by Debian Project at Thu Jan  1 12:43:38 UTC 2009.

Summary of my perl5 (revision 5 version 10 subversion 0) configuration:
  Platform:
    osname=linux, osvers=2.6.26-1-686, archname=i486-linux-gnu-thread-multi
    uname='linux rebekka 2.6.26-1-686 #1 smp mon dec 15 18:15:07 utc
2008 i686 gnulinux '
    config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN
-Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr
-Dprivlib=/usr/share/perl/5.10 -Darchlib=/usr/lib/perl/5.10
-Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5
-Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local
-Dsitelib=/usr/local/share/perl/5.10.0
-Dsitearch=/usr/local/lib/perl/5.10.0 -Dman1dir=/usr/share/man/man1
-Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1
-Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl
-Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio
-Uusenm -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib
-Dlibperl=libperl.so.5.10.0 -Dd_dosuid -des'
    hint=recommended, useposix=true, d_sigaction=define
    useithreads=define, usemultiplicity=define
    useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef
    use64bitint=undef, use64bitall=undef, uselongdouble=undef
    usemymalloc=n, bincompat5005=undef
  Compiler:
    cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN
-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64',
    optimize='-O2 -g',
    cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing
-pipe -I/usr/local/include'
    ccversion='', gccversion='4.3.2', gccosandvers=''
    intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=12
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=4, prototype=define
  Linker and Libraries:
    ld='cc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /lib /usr/lib /usr/lib64
    libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
    perllibs=-ldl -lm -lpthread -lc -lcrypt
    libc=/lib/libc-2.7.so, so=so, useshrplib=true, libperl=libperl.so.5.10.0
    gnulibc_version='2.7'
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
    cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib'

Locally applied patches:



@INC for perl 5.10.0:
    /home/rabbit/devel/utils/perl
    /etc/perl
    /usr/local/lib/perl/5.10.0
    /usr/local/share/perl/5.10.0
    /usr/lib/perl5
    /usr/share/perl5
    /usr/lib/perl/5.10
    /usr/share/perl/5.10
    /usr/local/lib/site_perl
    .


Environment for perl 5.10.0:
    HOME=/home/rabbit
    LANG=en_US.UTF-8
    LANGUAGE (unset)
    LC_ADDRESS=en_US.UTF-8
    LC_COLLATE=en_US.UTF-8
    LC_CTYPE=en_US.UTF-8
    LC_IDENTIFICATION=en_US.UTF-8
    LC_MESSAGES=en_US.UTF-8
    LC_MONETARY=en_US.UTF-8
    LC_NAME=en_US.UTF-8
    LC_NUMERIC=en_US.UTF-8
    LC_TELEPHONE=en_US.UTF-8
    LC_TIME=en_US.UTF-8
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)

PATH=/home/rabbit/devel/utils:/home/rabbit/bin:/usr/local/bin:/usr/bin:/bin:/usr/games
    PERL5LIB=/home/rabbit/devel/utils/perl
    PERL_BADLANG (unset)
    SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Jan 20, 2009

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2009

From @ribasushi

I am extending this bug with one more test case which now fails both on
5.10 and 5.8. The scenario​:

Class M is a Class​::C3​::Componentised. It loads two components D and W
(in this order, D is first in the MRO). Both packages D and W have a
method component_method(). The one in D is a simple passthrough​:

sub component_method { shift->next​::method (@​_); }

The one in W has a warning statement (with warnings​::register called in
the same namespace of course)​:
sub component_method { warnings​::warnif ('component_work') }

Then this still generates a warning both under 5.8 and 5.10​:
{ no warnings 'W'; M->component_method() }

Full test suite (19 points) attached.

On Tue Jan 20 02​:10​:31 2009, rabbit@​rabbit.us wrote​:

This is a bug report for perl from rabbit@​rabbit.us,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------
[Please enter your report here]

After upgrading to 5.10 warnings​::register related warning suppression
does not work as expected in all cases (i.e. as it did in 5.8). Please
find a complete and well documented 16 point test suite attached to
this
message (or at http​://rabbit.us/diff/5.10_lexwarn_register.tar.bz2)

It passes under 5.8 but breaks in 4 places under 5.10​:

Failures 5 & 6

Let's have Module S which inherits from module C.

In module C we have​:

use warnings​::register;

....

sub work {
...
warnings​::warnif ('stuff happened');
...
}

in module S we have​:

sub start_work {
...
no warnings 'C';
C->work;
}

Now if a user invokes S->start_work under 5.8 there will be no warning
as expected. Not so under 5.10

Failure 12

Same as above, but class S is generated on the fly via a string eval
(eval '...');

Failure 15

Same as 12, but instead of no warnings 'C', even an unqualified
no warnings doesn't work

[Please do not change anything below this line]
-----------------------------------------------------------------
---
Flags​:
category=library
severity=medium
---
Site configuration information for perl 5.10.0​:

Configured by Debian Project at Thu Jan 1 12​:43​:38 UTC 2009.

Summary of my perl5 (revision 5 version 10 subversion 0)
configuration​:
Platform​:
osname=linux, osvers=2.6.26-1-686, archname=i486-linux-gnu-thread-
multi
uname='linux rebekka 2.6.26-1-686 #1 smp mon dec 15 18​:15​:07 utc
2008 i686 gnulinux '
config_args='-Dusethreads -Duselargefiles -Dccflags=-DDEBIAN
-Dcccdlflags=-fPIC -Darchname=i486-linux-gnu -Dprefix=/usr
-Dprivlib=/usr/share/perl/5.10 -Darchlib=/usr/lib/perl/5.10
-Dvendorprefix=/usr -Dvendorlib=/usr/share/perl5
-Dvendorarch=/usr/lib/perl5 -Dsiteprefix=/usr/local
-Dsitelib=/usr/local/share/perl/5.10.0
-Dsitearch=/usr/local/lib/perl/5.10.0 -Dman1dir=/usr/share/man/man1
-Dman3dir=/usr/share/man/man3 -Dsiteman1dir=/usr/local/man/man1
-Dsiteman3dir=/usr/local/man/man3 -Dman1ext=1 -Dman3ext=3perl
-Dpager=/usr/bin/sensible-pager -Uafs -Ud_csh -Ud_ualarm -Uusesfio
-Uusenm -DDEBUGGING=-g -Doptimize=-O2 -Duseshrplib
-Dlibperl=libperl.so.5.10.0 -Dd_dosuid -des'
hint=recommended, useposix=true, d_sigaction=define
useithreads=define, usemultiplicity=define
useperlio=define, d_sfio=undef, uselargefiles=define,
usesocks=undef
use64bitint=undef, use64bitall=undef, uselongdouble=undef
usemymalloc=n, bincompat5005=undef
Compiler​:
cc='cc', ccflags ='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN
-fno-strict-aliasing -pipe -I/usr/local/include -D_LARGEFILE_SOURCE
-D_FILE_OFFSET_BITS=64',
optimize='-O2 -g',
cppflags='-D_REENTRANT -D_GNU_SOURCE -DDEBIAN -fno-strict-aliasing
-pipe -I/usr/local/include'
ccversion='', gccversion='4.3.2', gccosandvers=''
intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
d_longlong=define, longlongsize=8, d_longdbl=define,
longdblsize=12
ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
alignbytes=4, prototype=define
Linker and Libraries​:
ld='cc', ldflags =' -L/usr/local/lib'
libpth=/usr/local/lib /lib /usr/lib /usr/lib64
libs=-lgdbm -lgdbm_compat -ldb -ldl -lm -lpthread -lc -lcrypt
perllibs=-ldl -lm -lpthread -lc -lcrypt
libc=/lib/libc-2.7.so, so=so, useshrplib=true,
libperl=libperl.so.5.10.0
gnulibc_version='2.7'
Dynamic Linking​:
dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E'
cccdlflags='-fPIC', lddlflags='-shared -O2 -g -L/usr/local/lib'

Locally applied patches​:

---
@​INC for perl 5.10.0​:
/home/rabbit/devel/utils/perl
/etc/perl
/usr/local/lib/perl/5.10.0
/usr/local/share/perl/5.10.0
/usr/lib/perl5
/usr/share/perl5
/usr/lib/perl/5.10
/usr/share/perl/5.10
/usr/local/lib/site_perl
.

---
Environment for perl 5.10.0​:
HOME=/home/rabbit
LANG=en_US.UTF-8
LANGUAGE (unset)
LC_ADDRESS=en_US.UTF-8
LC_COLLATE=en_US.UTF-8
LC_CTYPE=en_US.UTF-8
LC_IDENTIFICATION=en_US.UTF-8
LC_MESSAGES=en_US.UTF-8
LC_MONETARY=en_US.UTF-8
LC_NAME=en_US.UTF-8
LC_NUMERIC=en_US.UTF-8
LC_TELEPHONE=en_US.UTF-8
LC_TIME=en_US.UTF-8
LD_LIBRARY_PATH (unset)
LOGDIR (unset)

PATH=/home/rabbit/devel/utils​:/home/rabbit/bin​:/usr/local/bin​:/usr/bin​:/bin​:/usr/games

PERL5LIB=/home/rabbit/devel/utils/perl
PERL\_BADLANG \(unset\)
SHELL=/bin/bash

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2009

@p5pRT
Copy link
Author

p5pRT commented Feb 6, 2009

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

@p5pRT
Copy link
Author

p5pRT commented Feb 14, 2009

From p5p@spam.wizbit.be

On Tue Jan 20 02​:10​:31 2009, rabbit@​rabbit.us wrote​:

This is a bug report for perl from rabbit@​rabbit.us,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------
[Please enter your report here]

After upgrading to 5.10 warnings​::register related warning suppression
does not work as expected in all cases (i.e. as it did in 5.8). Please
find a complete and well documented 16 point test suite attached to
this
message (or at http​://rabbit.us/diff/5.10_lexwarn_register.tar.bz2)

Thanks for the bug report.
Would it be possible to rewrite the situation that fails as stand alone tests
which requires only core modules?

(Your test script seems to require Class​::C3)

Kind regards,

Bram

@p5pRT
Copy link
Author

p5pRT commented Feb 15, 2009

From @ribasushi

On Sat Feb 14 10​:35​:06 2009, animator wrote​:

On Tue Jan 20 02​:10​:31 2009, rabbit@​rabbit.us wrote​:

This is a bug report for perl from rabbit@​rabbit.us,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------
[Please enter your report here]

After upgrading to 5.10 warnings​::register related warning
suppression
does not work as expected in all cases (i.e. as it did in 5.8).
Please
find a complete and well documented 16 point test suite attached to
this
message (or at http​://rabbit.us/diff/5.10_lexwarn_register.tar.bz2)

Thanks for the bug report.
Would it be possible to rewrite the situation that fails as stand
alone tests
which requires only core modules?

(Your test script seems to require Class​::C3)

Kind regards,

Bram

The file uploaded with the initial bug report[1] contains 16 tests which
are dependent on core modules only. The second entry adds a new file[2],
which contains the same 16 tests plus 3 extra ones to show an
_unrelated_ problem when C3 is in effect. I can rewrite the test to use
proper skip blocks if so requested.

[1] http​://rt.perl.org/rt3/Ticket/Attachment/522408/246780
/5.10_lexwarn_register.tar.bz2
[2]
http​://rt.perl.org/rt3/Ticket/Attachment/529454/250658/5.10_lexwarn_register_extended.tar.bz2

@p5pRT
Copy link
Author

p5pRT commented Feb 15, 2009

From @ribasushi

Bram via RT wrote​:

On Tue Jan 20 02​:10​:31 2009, rabbit@​rabbit.us wrote​:

This is a bug report for perl from rabbit@​rabbit.us,
generated with the help of perlbug 1.36 running under perl 5.10.0.

-----------------------------------------------------------------
[Please enter your report here]

After upgrading to 5.10 warnings​::register related warning suppression
does not work as expected in all cases (i.e. as it did in 5.8). Please
find a complete and well documented 16 point test suite attached to
this
message (or at http​://rabbit.us/diff/5.10_lexwarn_register.tar.bz2)

Thanks for the bug report.
Would it be possible to rewrite the situation that fails as stand alone tests
which requires only core modules?

(Your test script seems to require Class​::C3)

The file uploaded with the initial bug report[1] contains 16 tests which are
dependent on core modules only. The second entry adds a new file[2], which
contains the same 16 tests plus 3 extra ones to show an _unrelated_ problem
when C3 is in effect. I can rewrite the test to use proper skip blocks if
so requested.

[1] http​://rt.perl.org/rt3/Ticket/Attachment/522408/246780/5.10_lexwarn_register.tar.bz2
[2] http​://rt.perl.org/rt3/Ticket/Attachment/529454/250658/5.10_lexwarn_register_extended.tar.bz2

@p5pRT
Copy link
Author

p5pRT commented Feb 16, 2009

From p5p@spam.wizbit.be

After upgrading to 5.10 warnings​::register related warning suppression
does not work as expected in all cases (i.e. as it did in 5.8).

Test case​:

#!/usr/bin/perl -l

{
  package P1;

  sub p1 {
  if (warnings​::enabled("substr")) {
  warn "foo";
  }
  }
}

{
  package P2;

  use strict;
  use warnings;
  no warnings 'substr';
  our @​ISA = qw/P1/;

  sub p2 {
  my $self = shift;
  $self->p1();
  }
}

use warnings;
P2->p2();
__END__

$ perl-5.8.9 rt-62522-1.pl
(no output)

$ perl-5.10.0 rt-62522-1.pl
foo at rt-62522-1.pl line 8.

The reason why the output changed is because of​:
- http​://rt.perl.org/rt3/Ticket/Display.html?id=15395 'lexical warnings
and inheritance'
- http​://public.activestate.com/cgi-bin/perlbrowse/p/21167

The summary of that ticket​:

When Carp​::carp/Carp​::cloak/Carp​:* is used then the output can be
'confusing'. That is, Carp will check @​ISA for inheritence while the
warning​::enabled check will not.

Test case​:

(Difference from the previous test case​: removed "no warnings
'substr';" from package P2 and use of Carp​::carp instead of warn)

#!/usr/bin/perl -l

{
  package P1;
  use Carp;

  sub p1 {
  if (warnings​::enabled("substr")) {
  carp "foo";
  }
  }
}

{
  package P2;

  use strict;
  use warnings;
  our @​ISA = qw/P1/;
 
  sub p2 {
  my $self = shift;
  $self->p1();
  }
}

use warnings;
P2->p2();
__END__

$ perl-5.8.9 rt-62522-2.pl
foo at rt-62522-2.pl line 29

This warning is confusing in the sense that adding no warnings
'substr' on line 28 will have no effect on the error message; it has to
be added in package P2; as demonstrated by​:

#!/usr/bin/perl -l

{
  package P1;
  use Carp;

  sub p1 {
  if (warnings​::enabled("substr")) {
  carp "foo";
  }
  }
}

{
  package P2;

  use strict;
  use warnings;
  our @​ISA = qw/P1/;

  sub p2 {
  my $self = shift;
  $self->p1();
  }
}

use warnings;
no warnings 'substr';
P2->p2();
__END__

$ perl589 rt-62522-2.pl
foo at rt-62522-2.pl line 30

The behaviour of 5.10 makes sense but so does the behaviour of 5.8...

The result of this change is that there is no way to disable a warning
in 'package P1' in the 'P2 package'.

Perhaps a better solution is to only return true in warnings​::enabled if
- the warning is enabled in package P2; (and any other packages it
inherits from)
- the warning is enabled in package main;

Any thoughts?

Kind regards,

Bram

@p5pRT
Copy link
Author

p5pRT commented May 30, 2009

From p5p@spam.wizbit.be

On Tue Jan 20 02​:10​:31 2009, rabbit@​rabbit.us wrote​:

-----------------------------------------------------------------
[Please enter your report here]

After upgrading to 5.10 warnings​::register related warning
suppression
does not work as expected in all cases (i.e. as it did in 5.8).
[snip]

(I'm not sure what the best place for the test code is but in the end I
decided to add it all in-line.)

Assume the following test code​:

#!/usr/bin/perl -l

{
#line 1 RT62522.pm
  package RT62522;
  use warnings​::register;
}

{
#line 1 RT62522​::Base.pm
  package RT62522​::Base;

  use strict;
  use warnings;
  use Carp;

  sub new {
  bless {}, $_[0];
  }
  sub some_func {
  if (warnings​::enabled('RT62522')) {
  carp "some error message";
  }
  }
}

{
#line 1 RT62522​::Main.pm
  package RT62522​::Main;

  use strict;
  use warnings;
  our @​ISA = ("RT62522​::Base");

  sub some_func2 {
  my $self = shift;
  $self->some_func();
  }
}

{
#line 1 main
  package main;

  use strict;
  use warnings;

  my $obj = RT62522​::Main->new();
  {
  $obj->some_func2();
  }
}

__END__
Running it​:

$ perl-5.8.8 rt-62522.pl
some error message at main line 8

$ perl-5.10.0 rt-62522.pl
some error message at main line 8

One can very easy conclude from this that disabling the warning can be
done by adding a 'no warnings' before the line '$obj->some_func2()';
so let's try it​:

#!/usr/bin/perl -l

{
#line 1 RT62522.pm
  package RT62522;
  use warnings​::register;
}

{
#line 1 RT62522​::Base.pm
  package RT62522​::Base;

  use strict;
  use warnings;
  use Carp;

  sub new {
  bless {}, $_[0];
  }
  sub some_func {
  if (warnings​::enabled('RT62522')) {
  carp "some error message";
  }
  }
}

{
#line 1 RT62522​::Main.pm
  package RT62522​::Main;

  use strict;
  use warnings;
  our @​ISA = ("RT62522​::Base");

  sub some_func2 {
  my $self = shift;
  $self->some_func();
  }
}

{
#line 1 main
  package main;

  use strict;
  use warnings;

  my $obj = RT62522​::Main->new();
  {
  no warnings;
  $obj->some_func2();
  }
}

__END__

Running it​:

$ perl-5.8.8 rt-62522.pl
some error message at main line 9

$ perl-5.10.0 rt-62522.pl
(no output)

This was the (intended) Change 21167

So, how does one disable the warning on perl-5.8.8? By adding 'no
warnings' in RT62522​::Main the function some_func2.

#!/usr/bin/perl -l

{
#line 1 RT62522.pm
  package RT62522;
  use warnings​::register;
}

{
#line 1 RT62522​::Base.pm
  package RT62522​::Base;

  use strict;
  use warnings;
  use Carp;

  sub new {
  bless {}, $_[0];
  }
  sub some_func {
  if (warnings​::enabled('RT62522')) {
  carp "some error message";
  }
  }
}

{
#line 1 RT62522​::Main.pm
  package RT62522​::Main;

  use strict;
  use warnings;
  our @​ISA = ("RT62522​::Base");

  sub some_func2 {
  my $self = shift;
  no warnings;
  $self->some_func();
  }
}

{
#line 1 main
  package main;

  use strict;
  use warnings;

  my $obj = RT62522​::Main->new();
  {
  $obj->some_func2();
  }
}
__END__

$ perl-5.8.8 rt-62522.pl
(no output)

$ perl-5.10.0 rt-62522.pl
some error message at main line 8

My first idea will silence the warning when​:
- 'no warnings' is added in RT62522​::Main​::some_func2(); OR
- 'no warnings' is added before the call to $obj->some_func2();

Now going one step further​:

What if another call/more inherithance is involved?

Example​:

#!/usr/bin/perl -l

{
#line 1 RT62522.pm
  package RT62522;
  use warnings​::register;
}

{
#line 1 RT62522​::Base.pm
  package RT62522​::Base;

  use strict;
  use warnings;
  use Carp;

  sub new {
  bless {}, $_[0];
  }
  sub some_func {
  if (warnings​::enabled('RT62522')) {
  carp "some error message";
  }
  }
}

{
#line 1 RT62522​::Main.pm
  package RT62522​::Main;

  use strict;
  use warnings;
  our @​ISA = ("RT62522​::Base");

  sub some_func2 {
  my $self = shift;
  $self->some_func();
  }
}

{
#line 1 RT62522​::Sub.pm
  package RT62522​::Sub;

  use strict;
  use warnings;
  our @​ISA = ("RT62522​::Main");

  sub some_func3 {
  my $self = shift;
  $self->some_func2();
  }
}

{
#line 1 main
  package main;

  use strict;
  use warnings;

  my $obj = RT62522​::Sub->new();
  {
  $obj->some_func3();
  }
}

With Idea 1 it is possible to disable the warning in package main and
in package RT62522​::Main.

But should you also be able to disable it in the package RT62522​::Sub?
IMHO Yes.
So with Idea 2 it will only warn if​:
- the immediate caller (RT62522​::Main) has warnings enabled AND
- the original caller (main) has warnings enabled AND
- everything in between of the immediate caller and the original caller
(RT62522​::Sub) has warnings enabled

The downside​: it is impossible to explicetly enable a warning; you can
only disable them.
That is, disable it in RT62522​::Sub​::some_func3 and enable it in
RT62522​::Main​::some_func2();

All this leaves one important question unanswered/untouched... and this
is what stopped me from attaching patches​: what about FATAL warnings?
When/Where should they be enabled or disabled?

Adding use warnings FATAL => 'all' in RT62522​::Main​:

#!/usr/bin/perl -l

{
#line 1 RT62522.pm
  package RT62522;
  use warnings​::register;
}

{
#line 1 RT62522​::Base.pm
  package RT62522​::Base;

  use strict;
  use warnings;
  use Carp;

  sub new {
  bless {}, $_[0];
  }
  sub some_func {
  warnings​::warnif('RT62522', 'some error message');
  }
}

{
#line 1 RT62522​::Main.pm
  package RT62522​::Main;

  use strict;
  use warnings FATAL => 'all';
  our @​ISA = ("RT62522​::Base");

  sub some_func2 {
  my $self = shift;
  $self->some_func();
  }
}

{
#line 1 main
  package main;

  use strict;
  use warnings;

  my $obj = RT62522​::Main->new();
  {
  $obj->some_func2();
  }
  print "the end";
}
__END__

$ perl-5.8.8 rt-62522.pl
some error message at main line 8
(fatal warning)

$ perl-5.10.0 rt-62522.pl
some error message at main line 8
the end

Adding use warnings FATAL => 'all' in main​:

#!/usr/bin/perl -l

{
#line 1 RT62522.pm
  package RT62522;
  use warnings​::register;
}

{
#line 1 RT62522​::Base.pm
  package RT62522​::Base;

  use strict;
  use warnings;
  use Carp;

  sub new {
  bless {}, $_[0];
  }
  sub some_func {
  warnings​::warnif('RT62522', 'some error message');
  }
}

{
#line 1 RT62522​::Main.pm
  package RT62522​::Main;

  use strict;
  use warnings;
  our @​ISA = ("RT62522​::Base");

  sub some_func2 {
  my $self = shift;
  $self->some_func();
  }
}

{
#line 1 main
  package main;

  use strict;
  use warnings;

  my $obj = RT62522​::Main->new();
  {
  use warnings FATAL => 'all';
  $obj->some_func2();
  }
  print "the end";
}
__END__

$ perl-5.8.8 rt-62522.pl
some error message at main line 9
the end

$ perl-5.10.0 rt-62522.pl
some error message at main line 9
(fatal warning)

Where should the FATAL warning be enabled?
- only in RT62522​::Main?
- only in main?
- in RT62522​::Main or in main?
- in RT62522​::Main and in main?
- in RT62522​::Main or in main or in something that is between the call
in main and the call in RT62522​::Main (ie​: RT62522​::Sub)
- in RT62522​::Main and in main and in something that is between the
call in main and the call in RT62522​::Main (ie​: RT62522​::Sub)
- ...?

All that stops me from writing a patch for this is feedback on fatal
warnings...
so if someone can provide it I can easily write the patches...

Best regards,

Bram

@p5pRT
Copy link
Author

p5pRT commented Jan 12, 2010

From p5p@perl.wizbit.be

To summarise the ticket​:

The behaviour in 5.10.x favors the person using the module;
The behaviour in 5.8.x favors the module writer;

Assume to following code​:

- main calls Foo​::Bar​::baz()
- Foo​::Bar inherits from Foo​::Base
- Foo​::Bar​::baz() calls Foo​::Base​::_bazbaz()
- Foo​::Base​::_bazbaz() calls​: warnings​::warnif('substr', 'some warning
message');

On 5.8.x​:
the code warns when Foo​::Bar contains use warnings; (or use warnings
'substr');
=> it does not matter if Foo​::Base or main have warnings enabled
=> to disable the warning one has to modify Foo​::Bar.

On 5.10.x​:
the code warns when main contains use warnings; (or use warnings 'substr');
=> it does not matter if Foo​::Base or Foo​::Bar have warnings enabled
=> to disable the warning one has to modify main.

But​: sometimes we want the 5.8.x behaviour and sometimes we want the
5.10.x behaviour...

The biggest problem with altering this behaviour is backwards-compatibility​:
- a warning that was shown on 5.10.x might not be shown on 5.12.x
- a warning that was shown on 5.8.x might not be shown on 5.12.x

This in itself is a minor issue (IMHO).
BUT​: warnings can also be fatal and that is more serious (IMHO) since
then the code can start doing unexpected things...
(that is​: continue where it used to die)

Assume to following code​:

- main calls Foo​::Bar​::baz()
- Foo​::Bar inherits from Foo​::Base
- Foo​::Bar​::baz() calls Foo​::Base​::_bazbaz()
- Foo​::Base​::_bazbaz() calls​: warnings​::warnif('substr', 'some warning
message');

On 5.8.x​:
the warning is FATAL when Foo​::Bar contains use warnings FATAL => 'all';
=> it does not matter if Foo​::Base or main have warnings enabled

On 5.10.x​:
the warning is FATAL when main contains use warnings FATAL => 'all';
=> it does not matter if Foo​::Base or Foo​::Bar have warnings enabled

Possible solutions​:

1)
Normal warning​: warn when​:
- the warning is enabled in Foo​::Bar and
- the warning is enabled in main

FATAL warning​: die when
- the warning is FATAL in Foo​::Bar and
- the warning is FATAL in main

Downsides​:
- script may stop die'ing when upgraded to 5.12.x
- difficult to make a warning FATAL​: Foo​::Bar() and main have to be modified.

2)
Normal warning​: warn when​:
- the warning is enabled in Foo​::Bar and
- the warning is enabled in main

FATAL warning​: die when
- the warning is FATAL in Foo​::Bar or
- the warning is FATAL in main

Downsides​:
- script may start die'ing when upgraded to 5.12.x
- difficult to make (one particular) warning non FATAL​: If main
contains use warnings FATAL => 'all' then Foo​::Bar can not disable the
warning.

3)
Normal warning​: warn when​:
- the warning is enabled in Foo​::Bar and
- the warning is enabled in main.

FATAL warning​: die when​:
- the warning is enabled in Foo​::Bar and
- the warning is enabled in in main and
(
  - the warning is FATAL in Foo​::Bar or
  - the warning is FATAL in in main
)

Downsides​:
- script may start die'ing when upgraded to 5.12.x (when Foo​::Bar
contains use warnings FATAL => 'all'; )
- script may stop die'ing when upgraded to 5.12.x (when main does not
contain use warnings; )

4) ???

After the backwards-compatibilty question/problem is solved then we
should also consider extending the behaviour of no warnings. (but more
details on that when the first problem is solved).

Best regards,

Bram

@p5pRT
Copy link
Author

p5pRT commented Jan 18, 2010

From @obra

On Tue 12.Jan'10 at 21​:12​:37 +0100, Bram wrote​:

To summarise the ticket​:

The behaviour in 5.10.x favors the person using the module;
The behaviour in 5.8.x favors the module writer;

My inclination is that when we've broken back-compat in a shipped
version of Perl and not followed it up with a bugfix "quickly", there
isn't much we can do to restore the status quo of the previous release
-- especially in a murky situation like this one, where neither
behaviour is clearly wrong.

At this point, I'd count the 5.10.0 regression as the "new" default
behavior to be preserved - it even seems to make more sense to me than
the 5.8 behavior.

It feels weird to me to design library code that uses fatal warnings in
"production" mode, though I'm sure there's code that does it and that
someone has a good reason for doing so.

-Jesse

@p5pRT
Copy link
Author

p5pRT commented Feb 7, 2010

From @obra

Bram,

What would you like to see happen on this before 5.12.0?
I _think_ we're now stuck with the 5.10 default and that it shouldn't
block 5.12. But I'd love a sanity check on that.

-Jesse

On Mon Jan 18 10​:28​:42 2010, jesse wrote​:

On Tue 12.Jan'10 at 21​:12​:37 +0100, Bram wrote​:

To summarise the ticket​:

The behaviour in 5.10.x favors the person using the module;
The behaviour in 5.8.x favors the module writer;

My inclination is that when we've broken back-compat in a shipped
version of Perl and not followed it up with a bugfix "quickly", there
isn't much we can do to restore the status quo of the previous release
-- especially in a murky situation like this one, where neither
behaviour is clearly wrong.

At this point, I'd count the 5.10.0 regression as the "new" default
behavior to be preserved - it even seems to make more sense to me than
the 5.8 behavior.

It feels weird to me to design library code that uses fatal warnings in
"production" mode, though I'm sure there's code that does it and that
someone has a good reason for doing so.

-Jesse

@p5pRT
Copy link
Author

p5pRT commented Feb 9, 2010

From p5p@perl.wizbit.be

Jesse,

As said yesterday on irc​: I'm ok with shipping as is.

The 5.10.x behaviour has limited uses cases (IMHO) but so did the
5.8.x behaviour. (Also​: I'm not a frequent user of warnings​::warnif)

Maybe the change in behaviour should be added in perldelta? (Is there
a 'missing items in perl51000delta' section?)

Best regards,

Bram

Citeren Jesse via RT <perlbug-followup@​perl.org>​:

Bram,

What would you like to see happen on this before 5.12.0?
I _think_ we're now stuck with the 5.10 default and that it shouldn't
block 5.12. But I'd love a sanity check on that.

-Jesse

On Mon Jan 18 10​:28​:42 2010, jesse wrote​:

On Tue 12.Jan'10 at 21​:12​:37 +0100, Bram wrote​:

To summarise the ticket​:

The behaviour in 5.10.x favors the person using the module;
The behaviour in 5.8.x favors the module writer;

My inclination is that when we've broken back-compat in a shipped
version of Perl and not followed it up with a bugfix "quickly", there
isn't much we can do to restore the status quo of the previous release
-- especially in a murky situation like this one, where neither
behaviour is clearly wrong.

At this point, I'd count the 5.10.0 regression as the "new" default
behavior to be preserved - it even seems to make more sense to me than
the 5.8 behavior.

It feels weird to me to design library code that uses fatal warnings in
"production" mode, though I'm sure there's code that does it and that
someone has a good reason for doing so.

-Jesse

@p5pRT
Copy link
Author

p5pRT commented Feb 10, 2010

From @obra

On Tue 9.Feb'10 at 19​:53​:38 +0100, Bram wrote​:

Jesse,

As said yesterday on irc​: I'm ok with shipping as is.

Ah, fantastic. I missed that.

Maybe the change in behaviour should be added in perldelta? (Is
there a 'missing items in perl51000delta' section?)

We can certainly create one. (And amend the perl5100delta.pod at the
same time).

Thanks!

-Jesse

@p5pRT
Copy link
Author

p5pRT commented Feb 11, 2010

From @obra

On Tue Feb 09 21​:12​:16 2010, jesse wrote​:

On Tue 9.Feb'10 at 19​:53​:38 +0100, Bram wrote​:

Jesse,

As said yesterday on irc​: I'm ok with shipping as is.

Ah, fantastic. I missed that.

Updated perl5100delta.pod to note the deprecation in d99e543

@p5pRT
Copy link
Author

p5pRT commented Feb 11, 2010

@obra - Status changed from 'open' to 'resolved'

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

No branches or pull requests

1 participant