develooper Front page | perl.perl5.porters | Postings from July 2016

[perl #128765] Custom warnings categories are disabled by anypreceding `no warnings 'category'`

Thread Next
From:
Father Chrysostomos via RT
Date:
July 28, 2016 19:48
Subject:
[perl #128765] Custom warnings categories are disabled by anypreceding `no warnings 'category'`
Message ID:
rt-4.0.18-18131-1469735279-201.128765-15-0@perl.org
On Thu Jul 28 10:24:51 2016, the.rob.dixon@gmail.com wrote:
> This is a bug report for perl from the.rob.dixon@gmail.com,
> generated with the help of perlbug 1.40 running under perl 5.24.0.
> 
> 
> -----------------------------------------------------------------
> [Please describe your issue here]
> 
> With this module in file My/Warnings.pm
> 
> package My::Warnings;
> 
> use warnings::register;
> 
> sub test {
>     warnings::warnif 'This is my warning';
> }
> 
> 1;
> 
> and this code in main.pl
> 
> use strict;
> use feature 'switch';
> 
> use warnings 'all';
> 
> use My::Warnings;
> 
> print undef;           # uninitialized warning
> 
> given (1) { }          # experimental warning
> 
> My::Warnings::test();  # custom My::Warnings warning
> 
> I get all three warnings output. However, changing it to
> 
> use warnings 'all';
> no warnings 'experimental';
> 
> the custom category is disabled as well as the explicitly-mentioned
> "experimental" category.

Some time ago I suspected we had a problem like this, but I never got around to looking into it (or maybe I started and then forgot).

Internally perl uses a bitfield of warning categories and every time a category gets registered the bitfield grows.  Additionally, it will skip the bitfield altogether for all warnings and no warnings, respectively.

In your original example, ‘use warnings 'all'’ uses the special ‘all warnings’ value, and everything works.

Adding ‘no warnings 'experimental'’ switches to bitfield-mode, and when the new category is registered, and the bitfield gets bigger, the new bit just ends up as 0 by default.

It seems that we need a bit that records the default value for newly-registered warnings.  When a special value (such as ‘all warnings’) is converted into a bitfield, that new bit will get the appropriate value, as currently happens with categories already registered.  When new categories are registered, they can copy that bit.

(BTW, I’m not volunteering to do any of this.  But then again I might do it.)

-- 

Father Chrysostomos


---
via perlbug:  queue: perl5 status: new
https://rt.perl.org/Ticket/Display.html?id=128765

Thread Next


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