Skip to content

Commit 2d705ed

Browse files
committed
warnings.pm - support deprecated::smartmatch category
Currently we seem to lack a way to have a subcategory under deprecated. It seems reasonable to me that people might want to disable a specific subcategory warning while leaving the rest in place. This patch allows that. Note that both no warnings "deprecated"; and no warnings "deprecated::smartmatch"; work to disable the warning. Really this needs tests, but this will shut up autodie warnings, so we can do the tests for this later. Also we should go through and enumerate all the deprecated subcategories and switch to using them. Deprecated warnings shouldn't be "all or nothing". Again, I think that should happen after this is merged.
1 parent ffdab98 commit 2d705ed

File tree

5 files changed

+39
-23
lines changed

5 files changed

+39
-23
lines changed

lib/warnings.pm

Lines changed: 12 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pod/perldiag.pod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2645,7 +2645,7 @@ L<perlfunc/getsockopt>.
26452645

26462646
=item given is deprecated
26472647

2648-
(D deprecated) C<given> depends on smartmatch, which is deprecated. It
2648+
(D deprecated::smartmatch) C<given> depends on smartmatch, which is deprecated. It
26492649
will be removed in Perl 5.42. See the explanation under
26502650
L<perlsyn/Experimental Details on given and when>.
26512651

@@ -6039,7 +6039,7 @@ for the smart match.
60396039

60406040
=item Smartmatch is deprecated
60416041

6042-
(D deprecated) This warning is emitted if you
6042+
(D deprecated::smartmatch) This warning is emitted if you
60436043
use the smartmatch (C<~~>) operator. This is a deprecated
60446044
feature. Particularly, its behavior is noticed for being
60456045
unnecessarily complex and unintuitive, and it will be removed
@@ -8025,7 +8025,7 @@ So put in parentheses to say what you really mean.
80258025

80268026
=item when is deprecated
80278027

8028-
(D deprecated) C<when> depends on smartmatch, which is
8028+
(D deprecated::smartmatch) C<when> depends on smartmatch, which is
80298029
deprecated. Additionally, it has several special cases that may
80308030
not be immediately obvious, and it will be removed in Perl 5.42.
80318031
See the explanation

regen/warnings.pl

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,9 @@ BEGIN
7474
'debugging' => [ 5.008, DEFAULT_ON],
7575
'malloc' => [ 5.008, DEFAULT_ON],
7676
}],
77-
'deprecated' => [ 5.008, DEFAULT_ON],
77+
'deprecated' => [ 5.008, DEFAULT_ON, {
78+
'deprecated::smartmatch' => [ 5.037009, DEFAULT_ON],
79+
}],
7880
'void' => [ 5.008, DEFAULT_OFF],
7981
'recursion' => [ 5.008, DEFAULT_OFF],
8082
'redefine' => [ 5.008, DEFAULT_OFF],
@@ -204,12 +206,12 @@ sub valueWalk
204206
die "Value associated with key '$k' is not an ARRAY reference"
205207
if !ref $v || ref $v ne 'ARRAY' ;
206208

207-
my ($ver, $rest) = @{ $v } ;
209+
my ($ver, $rest, $rest2) = @{ $v } ;
210+
my $ref = ref $rest ? $rest : $rest2;
208211
push @{ $v_list->{$ver} }, $k;
209212

210-
if (ref $rest)
211-
{ valueWalk ($rest, $v_list) }
212-
213+
if (ref $ref)
214+
{ valueWalk ($ref, $v_list) }
213215
}
214216
}
215217

@@ -265,11 +267,12 @@ sub walk
265267
die "Value associated with key '$k' is not an ARRAY reference"
266268
if !ref $v || ref $v ne 'ARRAY' ;
267269

268-
my ($ver, $rest) = @{ $v } ;
269-
if (ref $rest)
270-
{ push (@{ $CATEGORIES{$k} }, walk ($rest)) }
271-
elsif ($rest == DEFAULT_ON)
270+
my ($ver, $rest, $rest2) = @{ $v } ;
271+
my $ref = ref $rest ? $rest : $rest2;
272+
if (!ref $rest and $rest == DEFAULT_ON)
272273
{ push @DEFAULTS, $NAME_TO_VALUE{uc $k} }
274+
if (ref $ref)
275+
{ push (@{ $CATEGORIES{$k} }, walk ($ref)) }
273276

274277
push @list, @{ $CATEGORIES{$k} } ;
275278
}
@@ -334,12 +337,13 @@ sub warningsTree
334337
$offset = ' ' x ($max + 1) ;
335338
}
336339

337-
my ($ver, $rest) = @{ $v } ;
338-
if (ref $rest)
340+
my ($ver, $rest, $rest2) = @{ $v } ;
341+
my $ref = ref $rest ? $rest : $rest2;
342+
if (ref $ref)
339343
{
340344
my $bar = @keys ? "|" : " ";
341345
$rv .= " -" . "-" x ($max - length $k ) . "+\n" ;
342-
$rv .= warningsTree ($rest, $prefix . $bar . $offset )
346+
$rv .= warningsTree ($ref, $prefix . $bar . $offset )
343347
}
344348
else
345349
{ $rv .= "\n" }

toke.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6638,7 +6638,7 @@ yyl_tilde(pTHX_ char *s)
66386638
TOKEN(0);
66396639
s += 2;
66406640
Perl_ck_warner_d(aTHX_
6641-
packWARN(WARN_DEPRECATED),
6641+
packWARN(WARN_DEPRECATED__SMARTMATCH),
66426642
"Smartmatch is deprecated");
66436643
NCEop(OP_SMARTMATCH);
66446644
}
@@ -8179,7 +8179,7 @@ yyl_word_or_keyword(pTHX_ char *s, STRLEN len, I32 key, I32 orig_keyword, struct
81798179

81808180
case KEY_given:
81818181
pl_yylval.ival = CopLINE(PL_curcop);
8182-
Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED),
8182+
Perl_ck_warner_d(aTHX_ packWARN(WARN_DEPRECATED__SMARTMATCH),
81838183
"given is deprecated");
81848184
OPERATOR(KW_GIVEN);
81858185

@@ -8702,7 +8702,7 @@ yyl_word_or_keyword(pTHX_ char *s, STRLEN len, I32 key, I32 orig_keyword, struct
87028702
return REPORT(0);
87038703
pl_yylval.ival = CopLINE(PL_curcop);
87048704
Perl_ck_warner_d(aTHX_
8705-
packWARN(WARN_DEPRECATED),
8705+
packWARN(WARN_DEPRECATED__SMARTMATCH),
87068706
"when is deprecated");
87078707
OPERATOR(KW_WHEN);
87088708

warnings.h

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)