Skip to content

Commit

Permalink
Remove experimental warnings from sub :const attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Apr 11, 2024
1 parent b8caf0c commit 1d1580e
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 153 deletions.
1 change: 0 additions & 1 deletion lib/B/Deparse.t
Expand Up @@ -887,7 +887,6 @@ my $f = sub {
} ;
####
# anonconst
# CONTEXT no warnings 'experimental::const_attr';
my $f = sub : const {
123;
}
Expand Down
168 changes: 82 additions & 86 deletions lib/warnings.pm

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions pod/perldiag.pod
Expand Up @@ -2041,13 +2041,6 @@ to define an overloaded constant, or when trying to find the
character name specified in the C<\N{...}> escape. Perhaps you
forgot to load the corresponding L<overload> pragma?

=item :const is experimental

(S experimental::const_attr) The "const" attribute is experimental.
If you want to use the feature, disable the warning with C<no warnings
'experimental::const_attr'>, but know that in doing so you are taking
the risk that your code may break in a future Perl version.

=item :const is not permitted on named subroutines

(F) The "const" attribute causes an anonymous subroutine to be run and
Expand Down
20 changes: 8 additions & 12 deletions pod/perlexperiment.pod
Expand Up @@ -55,18 +55,6 @@ L<[perl #14150]|https://github.com/Perl/perl5/issues/14150>.

See also: L<perlref/Assigning to References>

=item The "const" attribute

Introduced in Perl 5.22.0

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

The ticket for this experiment is
L<[perl #14428]|https://github.com/Perl/perl5/issues/14428>.

See also: L<perlsub/Constant Functions>

=item use re 'strict';

Introduced in Perl 5.22.0
Expand Down Expand Up @@ -372,6 +360,14 @@ Introduced in Perl 5.34.0.

Accepted in Perl 5.40 when not using the optional C<finally> block.

=item The "const" attribute

Introduced in Perl 5.22.0

Accepted in Perl 5.40

See also: L<perlsub/Constant Functions>

=back

=head2 Removed features
Expand Down
10 changes: 5 additions & 5 deletions pod/perlsub.pod
Expand Up @@ -1785,11 +1785,11 @@ aside from where it is declared.
*ALSO_INLINED = sub () { $x };
}

Perl 5.22 also introduces the experimental "const" attribute as an
alternative. (Disable the "experimental::const_attr" warnings if you want
to use it.) When applied to an anonymous subroutine, it forces the sub to
be called when the C<sub> expression is evaluated. The return value is
captured and turned into a constant subroutine:
Perl 5.22 also introduced the "const" attribute as an alternative. It was
initially experimental, but made stable in Perl 5.40. When applied to an
anonymous subroutine, it forces the sub to be called when the C<sub>
expression is evaluated. The return value is captured and turned into a
constant subroutine:

my $x = 54321;
*INLINED = sub : const { $x };
Expand Down
1 change: 1 addition & 0 deletions regen/warnings.pl
Expand Up @@ -194,6 +194,7 @@ BEGIN
experimental::script_run
experimental::isa
experimental::smartmatch
experimental::const_attr
);

###########################################################################
Expand Down
13 changes: 2 additions & 11 deletions t/op/anonconst.t
Expand Up @@ -6,17 +6,6 @@ BEGIN {
set_up_inc("../lib");
}

plan 8;

{
my $w;
local $SIG{__WARN__} = sub { $w .= shift };
eval '+sub : const {}';
like $w, qr/^:const is experimental at /, 'experimental warning';
}

no warnings 'experimental::const_attr';

push @subs, sub :const{$_} for 1..10;
is join(" ", map &$_, @subs), "1 2 3 4 5 6 7 8 9 10",
':const capturing global $_';
Expand Down Expand Up @@ -49,3 +38,5 @@ like $@, qr/^:const is not permitted on named subroutines at /,
eval 'sub baz : const { }';
like $@, qr/^:const is not permitted on named subroutines at /,
':const on named sub';

done_testing;
4 changes: 0 additions & 4 deletions toke.c
Expand Up @@ -12857,10 +12857,6 @@ S_apply_builtin_cv_attribute(pTHX_ CV *cv, OP *o)
else if(memEQs(SvPVX(sv), len, "method"))
CvNOWARN_AMBIGUOUS_on(cv);
else if(memEQs(SvPVX(sv), len, "const")) {
Perl_ck_warner_d(aTHX_
packWARN(WARN_EXPERIMENTAL__CONST_ATTR),
":const is experimental"
);
CvANONCONST_on(cv);
if (!CvANON(cv))
yyerror(":const is not permitted on named subroutines");
Expand Down
52 changes: 25 additions & 27 deletions warnings.h

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

0 comments on commit 1d1580e

Please sign in to comment.