Skip to content

Deprecate smartmatch #20337

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

Merged
merged 5 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/Safe/t/safeops.t
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ dor $x // $y
dorassign $x //= $y
once SKIP {use feature 'state'; state $foo = 42;}
say SKIP {use feature 'say'; say "foo";}
smartmatch no warnings 'experimental::smartmatch'; $x ~~ $y
smartmatch no warnings 'deprecated'; $x ~~ $y
aeach SKIP each @t
akeys SKIP keys @t
avalues SKIP values @t
Expand Down
10 changes: 5 additions & 5 deletions lib/B/Deparse.t
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ my $c = [];
my $d = \[];
####
# SKIP ?$] < 5.010 && "smartmatch and given/when not implemented on this Perl version"
# CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
# CONTEXT use feature ':5.10'; no warnings 'deprecated';
# implicit smartmatch in given/when
given ('foo') {
when ('bar') { continue; }
Expand Down Expand Up @@ -1624,7 +1624,7 @@ my @a;
$a[0] = 1;
####
# feature features without feature
# CONTEXT no warnings 'experimental::smartmatch';
# CONTEXT no warnings 'deprecated';
CORE::state $x;
CORE::say $x;
CORE::given ($x) {
Expand All @@ -1640,7 +1640,7 @@ CORE::evalbytes '';
() = CORE::fc $x;
####
# feature features when feature has been disabled by use VERSION
# CONTEXT no warnings 'experimental::smartmatch';
# CONTEXT no warnings 'deprecated';
use feature (sprintf(":%vd", $^V));
use 1;
CORE::say $_;
Expand Down Expand Up @@ -1670,7 +1670,7 @@ CORE::evalbytes '';
() = CORE::__SUB__;
####
# (the above test with CONTEXT, and the output is equivalent but different)
# CONTEXT use feature ':5.10'; no warnings 'experimental::smartmatch';
# CONTEXT use feature ':5.10'; no warnings 'deprecated';
# feature features when feature has been disabled by use VERSION
use feature (sprintf(":%vd", $^V));
use 1;
Expand Down Expand Up @@ -1704,7 +1704,7 @@ CORE::evalbytes '';
####
# SKIP ?$] < 5.017004 && "lexical subs not implemented on this Perl version"
# lexical subroutines and keywords of the same name
# CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental';
# CONTEXT use feature 'lexical_subs', 'switch'; no warnings 'experimental'; no warnings 'deprecated';
my sub default;
my sub else;
my sub elsif;
Expand Down
3 changes: 3 additions & 0 deletions lib/feature.pm

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions lib/overload.t
Original file line number Diff line number Diff line change
Expand Up @@ -1910,7 +1910,7 @@ foreach my $op (qw(<=> == != < <= > >=)) {


for my $sub (keys %subs) {
no warnings 'experimental::smartmatch';
no warnings 'deprecated';
my $term = $subs{$sub};
my $t = sprintf $term, '$_[0][0]';
my $e ="sub { \$funcs .= '($sub)'; my \$r; if (\$use_int) {"
Expand Down Expand Up @@ -1952,7 +1952,7 @@ foreach my $op (qw(<=> == != < <= > >=)) {
? "-\$_[0][0]"
: "$_[3](\$_[0][0])";
my $r;
no warnings 'experimental::smartmatch';
no warnings 'deprecated';
if ($use_int) {
use integer; $r = eval $e;
}
Expand Down Expand Up @@ -1999,7 +1999,7 @@ foreach my $op (qw(<=> == != < <= > >=)) {
$use_int = ($int ne '');
my $plain = $tainted_val;
my $plain_term = $int . sprintf $sub_term, '$plain';
my $exp = do {no warnings 'experimental::smartmatch'; eval $plain_term };
my $exp = do {no warnings 'deprecated'; eval $plain_term };
diag("eval of plain_term <$plain_term> gave <$@>") if $@;
SKIP: {
is_if_taint_supported(tainted($exp), $exp_taint,
Expand Down Expand Up @@ -2029,7 +2029,7 @@ foreach my $op (qw(<=> == != < <= > >=)) {

my $res_term = $int . sprintf $sub_term, $var;
my $desc = "<$res_term> $ov_pkg" ;
my $res = do { no warnings 'experimental::smartmatch'; eval $res_term };
my $res = do { no warnings 'deprecated'; eval $res_term };
diag("eval of res_term $desc gave <$@>") if $@;
# uniquely, the inc/dec ops return the original
# ref rather than a copy, so stringify it to
Expand Down
138 changes: 67 additions & 71 deletions lib/warnings.pm

Large diffs are not rendered by default.

30 changes: 14 additions & 16 deletions pod/perldiag.pod
Original file line number Diff line number Diff line change
Expand Up @@ -2643,11 +2643,10 @@ C<getpwnam> operator returned an invalid UIC.
forget to check the return value of your socket() call? See
L<perlfunc/getsockopt>.

=item given is experimental
=item given is deprecated

(S experimental::smartmatch) C<given> depends on smartmatch, which
is experimental, so its behavior may change or even be removed
in any future release of perl. See the explanation under
(D deprecated) C<given> depends on smartmatch, which is deprecated. It
will be removed in Perl 5.42. See the explanation under
L<perlsyn/Experimental Details on given and when>.

=item Global symbol "%s" requires explicit package name (did you forget to
Expand Down Expand Up @@ -6038,14 +6037,13 @@ so there can't be any left to fill later parameters.
overload it: Perl refuses to use the object's underlying structure
for the smart match.

=item Smartmatch is experimental
=item Smartmatch is deprecated

(S experimental::smartmatch) This warning is emitted if you
use the smartmatch (C<~~>) operator. This is currently an experimental
feature, and its details are subject to change in future releases of
Perl. Particularly, its current behavior is noticed for being
unnecessarily complex and unintuitive, and is very likely to be
overhauled.
(D deprecated) This warning is emitted if you
use the smartmatch (C<~~>) operator. This is a deprecated
feature. Particularly, its behavior is noticed for being
unnecessarily complex and unintuitive, and it will be removed
in Perl 5.42.

=item Sorry, hash keys must be smaller than 2**31 bytes

Expand Down Expand Up @@ -8025,12 +8023,12 @@ but in actual fact, you got

So put in parentheses to say what you really mean.

=item when is experimental
=item when is deprecated

(S experimental::smartmatch) C<when> depends on smartmatch, which is
experimental. Additionally, it has several special cases that may
not be immediately obvious, and their behavior may change or
even be removed in any future release of perl. See the explanation
(D deprecated) C<when> depends on smartmatch, which is
deprecated. Additionally, it has several special cases that may
not be immediately obvious, and it will be removed in Perl 5.42.
See the explanation
under L<perlsyn/Experimental Details on given and when>.

=item Wide character in %s
Expand Down
6 changes: 5 additions & 1 deletion pod/perlexperiment.pod
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@ Introduced in Perl 5.10.0

Modified in Perl 5.10.1, 5.12.0

Deprecated in 5.38.0

Will be removed in 5.42.0

Using this feature triggers warnings in the category
C<experimental::smartmatch>.
C<deprecated>.

The ticket for this experiment is
L<[perl #13173]|https://github.com/Perl/perl5/issues/13173>.
Expand Down
3 changes: 3 additions & 0 deletions regen/feature.pl
Original file line number Diff line number Diff line change
Expand Up @@ -605,6 +605,9 @@ =head2 The 'switch' feature
See L<perlsyn/"Switch Statements"> for details.

This feature is available starting with Perl 5.10.
It is deprecated starting with Perl 5.38, and using
C<given>, C<when> or smartmatch will throw a warning.
It will be removed in Perl 5.42.

=head2 The 'unicode_strings' feature

Expand Down
3 changes: 2 additions & 1 deletion regen/warnings.pl
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ BEGIN

my %NAME_TO_VALUE; # ('NAME' => index_number, ....);

# the experiments were successful,
# the experiments were successful (or abandonned),
# so no warning bit is needed anymore
my %NO_BIT_FOR = map { ( uc $_ => 1, $_ => 1 ) } qw(
experimental::lexical_subs
Expand All @@ -181,6 +181,7 @@ BEGIN
experimental::alpha_assertions
experimental::script_run
experimental::isa
experimental::smartmatch
);

###########################################################################
Expand Down
4 changes: 1 addition & 3 deletions t/lib/croak/pp_ctl
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,12 @@ no warnings 'deprecated';
goto f;
CORE::given(1){f:}
EXPECT
given is experimental at - line 3.
Can't "goto" into a "given" block at - line 3.
########
# NAME goto from given topic expression
no warnings 'deprecated';
CORE::given(goto f){f:}
EXPECT
given is experimental at - line 2.
Can't "goto" into a "given" block at - line 2.
########
# NAME goto into expression
Expand All @@ -41,7 +39,7 @@ EXPECT
Can't find label foo at - line 3.
########
# NAME when outside given
use 5.01; no warnings 'experimental::smartmatch';
use 5.01; no warnings 'deprecated';
when(undef){}
EXPECT
Can't "when" outside a topicalizer at - line 2.
Expand Down
30 changes: 15 additions & 15 deletions t/lib/feature/switch
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,28 @@ Check the lexical scoping of the switch keywords.

__END__
# No switch; given should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
use warnings; no warnings 'deprecated';
print STDOUT given;
EXPECT
Unquoted string "given" may clash with future reserved word at - line 3.
given
########
# No switch; when should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
use warnings; no warnings 'deprecated';
print STDOUT when;
EXPECT
Unquoted string "when" may clash with future reserved word at - line 3.
when
########
# No switch; default should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
use warnings; no warnings 'deprecated';
print STDOUT default;
EXPECT
Unquoted string "default" may clash with future reserved word at - line 3.
default
########
# No switch; break should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
use warnings; no warnings 'deprecated';
print STDOUT break;
EXPECT
Unquoted string "break" may clash with future reserved word at - line 3.
Expand All @@ -36,19 +36,19 @@ EXPECT
Can't "continue" outside a when block at - line 2.
########
# Use switch; so given is a keyword
use feature 'switch'; no warnings 'experimental::smartmatch';
use feature 'switch'; no warnings 'deprecated';
given("okay\n") { print }
EXPECT
okay
########
# Use switch; so when is a keyword
use feature 'switch'; no warnings 'experimental::smartmatch';
use feature 'switch'; no warnings 'deprecated';
given(1) { when(1) { print "okay" } }
EXPECT
okay
########
# Use switch; so default is a keyword
use feature 'switch'; no warnings 'experimental::smartmatch';
use feature 'switch'; no warnings 'deprecated';
given(1) { default { print "okay" } }
EXPECT
okay
Expand All @@ -60,7 +60,7 @@ EXPECT
Can't "break" outside a given block at - line 3.
########
# switch out of scope; given should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
use warnings; no warnings 'deprecated';
{ use feature 'switch';
given (1) {print "Okay here\n";}
}
Expand All @@ -71,7 +71,7 @@ Okay here
given
########
# switch out of scope; when should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
use warnings; no warnings 'deprecated';
{ use feature 'switch';
given (1) { when(1) {print "Okay here\n";} }
}
Expand All @@ -82,7 +82,7 @@ Okay here
when
########
# switch out of scope; default should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
use warnings; no warnings 'deprecated';
{ use feature 'switch';
given (1) { default {print "Okay here\n";} }
}
Expand All @@ -93,7 +93,7 @@ Okay here
default
########
# switch out of scope; break should be a bareword.
use warnings; no warnings 'experimental::smartmatch';
use warnings; no warnings 'deprecated';
{ use feature 'switch';
given (1) { break }
}
Expand All @@ -103,7 +103,7 @@ Unquoted string "break" may clash with future reserved word at - line 6.
break
########
# C<no feature 'switch'> should work
use warnings; no warnings 'experimental::smartmatch';
use warnings; no warnings 'deprecated';
use feature 'switch';
given (1) { when(1) {print "Okay here\n";} }
no feature 'switch';
Expand All @@ -114,7 +114,7 @@ Okay here
when
########
# C<no feature> should work too
use warnings; no warnings 'experimental::smartmatch';
use warnings; no warnings 'deprecated';
use feature 'switch';
given (1) { when(1) {print "Okay here\n";} }
no feature;
Expand All @@ -125,14 +125,14 @@ Okay here
when
########
# Without the feature, no 'Unambiguous use of' warning:
use warnings; no warnings 'experimental::smartmatch';
use warnings; no warnings 'deprecated';
@break = ($break = "break");
print ${break}, ${break[0]};
EXPECT
breakbreak
########
# With the feature, we get an 'Unambiguous use of' warning:
use warnings; no warnings 'experimental::smartmatch';
use warnings; no warnings 'deprecated';
use feature 'switch';
@break = ($break = "break");
print ${break}, ${break[0]};
Expand Down
2 changes: 1 addition & 1 deletion t/lib/warnings/9uninit
Original file line number Diff line number Diff line change
Expand Up @@ -1943,7 +1943,7 @@ $v = 1 + prototype $fn;
EXPECT
Use of uninitialized value in addition (+) at - line 4.
########
use warnings 'uninitialized'; no warnings 'experimental::smartmatch';
use warnings 'uninitialized'; no warnings 'deprecated';
my $v;
my $fn = sub {};
$v = 1 + (1 ~~ $fn);
Expand Down
2 changes: 1 addition & 1 deletion t/lib/warnings/op
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ OPTION fatal
Can't use an array as a reference at - line 3.
########
# op.c
use warnings 'void' ; no warnings 'experimental::smartmatch'; close STDIN ;
use warnings 'void' ; no warnings 'deprecated'; close STDIN ;
#line 2
1 x 3 ; # OP_REPEAT (folded)
(1) x 3 ; # OP_REPEAT
Expand Down
4 changes: 3 additions & 1 deletion t/op/cmpchain.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,28 @@ BEGIN {
}

use feature "isa";
no warnings qw(experimental::smartmatch);

my @cheqop = qw(== != eq ne);
my @nceqop = qw(<=> cmp ~~);
my @chrelop = qw(< > <= >= lt gt le ge);
my @ncrelop = qw(isa);

foreach my $c0 (@nceqop) {
no warnings qw(deprecated);
foreach my $c1 (@nceqop) {
is eval("sub { \$a $c0 \$b $c1 \$c }"), undef,
"$c0 $c1 non-associative";
}
}
foreach my $c (@nceqop) {
no warnings qw(deprecated);
foreach my $e (@cheqop) {
is eval("sub { \$a $c \$b $e \$c }"), undef, "$c $e non-associative";
is eval("sub { \$a $e \$b $c \$c }"), undef, "$e $c non-associative";
}
}
foreach my $c (@nceqop) {
no warnings qw(deprecated);
foreach my $e0 (@cheqop) {
foreach my $e1 (@cheqop) {
is eval("sub { \$a $c \$b $e0 \$c $e1 \$d }"), undef,
Expand Down
Loading