Skip to content

Commit

Permalink
Make downgrading a use VERSION past v5.11 fatal
Browse files Browse the repository at this point in the history
In Perl 5.36 we made this a deprecation warning, due to be removed in
5.40. Now it is being removed.

This removal means that the three shadow hints bits used to implement
implicit vs explicit strict hints can be reclaimed at a later date, for
use in other features.
  • Loading branch information
leonerd committed Feb 10, 2024
1 parent 0c67902 commit 4210e23
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 47 deletions.
12 changes: 1 addition & 11 deletions lib/strict.t
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
chdir 't' if -d 't';
@INC = ( '.', '../lib' );

our $local_tests = 7;
our $local_tests = 5;
require "../t/lib/common.pl";

eval qq(use strict 'garbage');
Expand All @@ -18,16 +18,6 @@ like($@, qr/^Unknown 'strict' tag\(s\) 'foo bar'/);
eval qq(no strict qw(foo bar));
like($@, qr/^Unknown 'strict' tag\(s\) 'foo bar'/);

{
my $warnings = "";
local $SIG{__WARN__} = sub { $warnings .= $_[0] };
eval 'use v5.12; use v5.10; ${"c"}';
is($@, '', 'use v5.10 disables implicit strict refs');
like($warnings,
qr/^Downgrading a use VERSION declaration to below v5.11 is deprecated, and will become fatal in Perl 5.40 at /,
'use v5.10 after use v5.12 provokes deprecation warning');
}

eval 'use strict; use v5.10; ${"c"}';
like($@,
qr/^Can't use string \("c"\) as a SCALAR ref while "strict refs" in use/,
Expand Down
13 changes: 9 additions & 4 deletions op.c
Original file line number Diff line number Diff line change
Expand Up @@ -8018,6 +8018,15 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg)

U16 shortver = S_extract_shortver(aTHX_ use_version);

if (shortver && PL_prevailing_version) {
/* use VERSION while another use VERSION is in scope
* This should provoke at least a warning, if not an outright error
*/
/* downgrading from >= 5.11 to < 5.11 is now fatal */
if (PL_prevailing_version >= SHORTVER(5, 11) && shortver < SHORTVER(5, 11))
croak("Downgrading a use VERSION declaration to below v5.11 is not permitted");
}

/* If a version >= 5.11.0 is requested, strictures are on by default! */
if (shortver >= SHORTVER(5, 11)) {
if (!(PL_hints & HINT_EXPLICIT_STRICT_REFS))
Expand All @@ -8034,10 +8043,6 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg)
}
/* otherwise they are off */
else {
if(PL_prevailing_version >= SHORTVER(5, 11))
deprecate_fatal_in(WARN_DEPRECATED__VERSION_DOWNGRADE, "5.40",
"Downgrading a use VERSION declaration to below v5.11");

if (!(PL_hints & HINT_EXPLICIT_STRICT_REFS))
PL_hints &= ~HINT_STRICT_REFS;
if (!(PL_hints & HINT_EXPLICIT_STRICT_SUBS))
Expand Down
16 changes: 8 additions & 8 deletions pod/perldiag.pod
Original file line number Diff line number Diff line change
Expand Up @@ -2225,14 +2225,14 @@ somehow called on another platform. This should not happen.

(P) The internal handling of magical variables has been cursed.

=item Downgrading a use VERSION declaration to below v5.11 is deprecated

(S deprecated::version_downgrade) This warning is emitted on a
C<use VERSION> statement that requests a version below v5.11 (when the
effects of C<use strict> would be disabled), after a previous
declaration of one having a larger number (which would have enabled
these effects). Because of a change to the way that C<use VERSION>
interacts with the strictness flags, this is no longer supported.
=item Downgrading a use VERSION declaration to below v5.11 is not permitted

(F) A C<use VERSION> statement that requests a version below v5.11
(when the effects of C<use strict> would be disabled) has been found
after a previous declaration of one having a larger number (which would
have enabled these effects). Because of a change to the way that
C<use VERSION> interacts with the strictness flags, this is no longer
supported.

=item (Do you need to predeclare %s?)

Expand Down
14 changes: 1 addition & 13 deletions t/comp/use.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BEGIN {
$INC{"feature.pm"} = 1; # so we don't attempt to load feature.pm
}

print "1..88\n";
print "1..85\n";

# Can't require test.pl, as we're testing the use/require mechanism here.

Expand Down Expand Up @@ -149,14 +149,6 @@ like $@, qr/^Can't use string/,
eval 'use strict "subs"; use 5.012; ${"foo"} = "bar"';
like $@, qr/^Can't use string/,
'explicit use strict "subs" does not stop ver decl from enabling refs';
{
my $warnings = "";
local $SIG{__WARN__} = sub { $warnings .= $_[0] };
eval 'use 5.012; use 5.01; ${"foo"} = "bar"';
is $@, "", 'use 5.01 overrides implicit strict from prev ver decl';
like $warnings, qr/^Downgrading a use VERSION declaration to below v5.11 is deprecated, and will become fatal in Perl 5.40 at /,
'use 5.01 after use 5.012 provokes deprecation warning';
}
eval 'no strict "subs"; use 5.012; ${"foo"} = "bar"';
ok $@, 'no strict subs allows ver decl to enable refs';
eval 'no strict "subs"; use 5.012; $nonexistent_pack_var';
Expand All @@ -177,10 +169,6 @@ ok $@, 'no strict vars allows ver decl to enable subs';
$result = eval 'use 5.39.0; my $t = true; $t eq "1"';
is ($@, "", 'builtin funcs available after use 5.39.0');
ok ($result, 'imported true is eq "1"');

eval 'use 5.39.0; use 5.36.0; my $t = true;';
like ($@, qr/^Bareword "true" not allowed while "strict subs" in use at /,
'builtin funcs are removed by use 5.36.0');
}

{ use test_use } # check that subparse saves pending tokens
Expand Down
6 changes: 6 additions & 0 deletions t/lib/croak/op
Original file line number Diff line number Diff line change
Expand Up @@ -308,3 +308,9 @@ sub xx {
EXPECT
Missing comma after first argument to return at - line 2, near "5;"
Execution of - aborted due to compilation errors.
########
# use VERSION across the 5.11 boundary
use 5.012;
use 5.010;
EXPECT
Downgrading a use VERSION declaration to below v5.11 is not permitted at - line 3.
19 changes: 8 additions & 11 deletions t/lib/feature/implicit
Original file line number Diff line number Diff line change
Expand Up @@ -62,37 +62,34 @@ EXPECT
# lower version after higher version
sub evalbytes { print "evalbytes sub\n" }
sub say { print "say sub\n" }
use 5;
say "no";
use 5.015;
evalbytes "say 'yes'";
use 5.014;
evalbytes;
use 5;
say "no"
EXPECT
Downgrading a use VERSION declaration to below v5.11 is deprecated, and will become fatal in Perl 5.40 at - line 8.
say sub
yes
evalbytes sub
say sub
########
# Implicit unicode_string feature
use v5.14;
use v5.8.8;
my $sharp_s = chr utf8::unicode_to_native(0xdf);
print 'ss' =~ /$sharp_s/i ? "ok\n" : "nok\n";
use v5.8.8;
use v5.14;
print 'ss' =~ /$sharp_s/i ? "ok\n" : "nok\n";
EXPECT
Downgrading a use VERSION declaration to below v5.11 is deprecated, and will become fatal in Perl 5.40 at - line 5.
ok
nok
ok
########
# Implicit unicode_eval feature
use v5.15;
require '../../t/charset_tools.pl';
my $long_s = byte_utf8a_to_utf8n("\xc5\xbf");
print eval "use utf8; q|$long_s|" eq $long_s ? "ok\n" : "nok\n";
use v5.8.8;
print eval "use utf8; q|$long_s|" eq "\x{17f}" ? "ok\n" : "nok\n";
use v5.15;
print eval "use utf8; q|$long_s|" eq $long_s ? "ok\n" : "nok\n";
EXPECT
Downgrading a use VERSION declaration to below v5.11 is deprecated, and will become fatal in Perl 5.40 at - line 6.
ok
ok

0 comments on commit 4210e23

Please sign in to comment.