forked from schacon/perl
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move prototype parsing related warnings from the 'syntax' top level w…
…arnings category to a new 'illegalproto' subcategory. Two warnings can be emitted when parsing a prototype - Illegal character in prototype for %s : %s Prototype after '%c' for %s : %s The first one is emitted when any invalid character is found, the latter when further prototype-type stuff is found after a slurpy entry (i.e. valid character but in such a place as to be a no-op, and therefore likely a bug). These warnings are distinct from those emitted when a sub is overwritten by one with a different prototype, and when calls are made to subroutines with prototypes - those are in the pre-existing sub-category 'prototype'. Since modules such as signatures.pm and Web::Simple only need to disable the warnings during parsing, I chose to add a new category containing only these. Moving these warnings into the 'prototype' sub-category would have forced authors to disable more warnings than they intended, and the entire raison d'etre of this patch is to allow the specific warnings involved to be disabled. In order to maintain compatibility with existing code, the new location needed to be a sub-category of 'syntax' - this means that no warnings 'syntax'; will continue to work as expected - even in cases like Web::Simple where all subcategories extant prior to this patch are re-enabled (this is another reason why a move into the 'protoype' category would not achieve the desired goal). The category name 'illegalproto' was chosen because the most common warning to encounter is the "Illegal character" one, and therefore 'illegalproto' while minorly inaccurate by ignoring the (relatively recent and unknown) second warning is an easy name to spot on an initial skim of perllexwarn and will behave as expected by also disabling the case of an unusual prototype that happens to look like a normal one. This patch updates pod/perllexwarn.pod, perldiag.pod and perl5113delta.pod to document the new category, toke.c and warnings.pl to create and implement the new category, and a new test t/op/protowarn.t that verifies the new behaviour in a number of cases. It also includes the files generated by regen.pl that are found in the repo - notably warnings.h and lib/warnings.pm.
- Loading branch information
1 parent
9b5fd1d
commit 197afce
Showing
8 changed files
with
147 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#!./perl | ||
|
||
BEGIN { | ||
chdir 't' if -d 't'; | ||
@INC = qw(. ../lib); | ||
} | ||
|
||
use strict; | ||
use warnings; | ||
|
||
BEGIN { | ||
require 'test.pl'; | ||
plan( tests => 12 ); | ||
} | ||
|
||
use vars qw{ @warnings $sub $warn }; | ||
|
||
BEGIN { | ||
$warn = 'Illegal character in prototype'; | ||
} | ||
|
||
sub one_warning_ok { | ||
cmp_ok(scalar(@warnings), '==', 1, 'One warning'); | ||
cmp_ok(substr($warnings[0],0,length($warn)),'eq',$warn,'warning message'); | ||
@warnings = (); | ||
} | ||
|
||
sub no_warnings_ok { | ||
cmp_ok(scalar(@warnings), '==', 0, 'No warnings'); | ||
@warnings = (); | ||
} | ||
|
||
BEGIN { | ||
$SIG{'__WARN__'} = sub { push @warnings, @_ }; | ||
$| = 1; | ||
} | ||
|
||
BEGIN { @warnings = () } | ||
|
||
$sub = sub (x) { }; | ||
|
||
BEGIN { | ||
one_warning_ok; | ||
} | ||
|
||
{ | ||
no warnings 'syntax'; | ||
$sub = sub (x) { }; | ||
} | ||
|
||
BEGIN { | ||
no_warnings_ok; | ||
} | ||
|
||
{ | ||
no warnings 'illegalproto'; | ||
$sub = sub (x) { }; | ||
} | ||
|
||
BEGIN { | ||
no_warnings_ok; | ||
} | ||
|
||
{ | ||
no warnings 'syntax'; | ||
use warnings 'illegalproto'; | ||
$sub = sub (x) { }; | ||
} | ||
|
||
BEGIN { | ||
one_warning_ok; | ||
} | ||
|
||
BEGIN { | ||
$warn = q{Prototype after '@' for}; | ||
} | ||
|
||
$sub = sub (@$) { }; | ||
|
||
BEGIN { | ||
one_warning_ok; | ||
} | ||
|
||
{ | ||
no warnings 'syntax'; | ||
$sub = sub (@$) { }; | ||
} | ||
|
||
BEGIN { | ||
no_warnings_ok; | ||
} | ||
|
||
{ | ||
no warnings 'illegalproto'; | ||
$sub = sub (@$) { }; | ||
} | ||
|
||
BEGIN { | ||
no_warnings_ok; | ||
} | ||
|
||
{ | ||
no warnings 'syntax'; | ||
use warnings 'illegalproto'; | ||
$sub = sub (@$) { }; | ||
} | ||
|
||
BEGIN { | ||
one_warning_ok; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters