Skip to content

Commit

Permalink
Issue deprecation warnings on subsequent use VERSION declarations
Browse files Browse the repository at this point in the history
  • Loading branch information
leonerd committed Feb 16, 2024
1 parent 72037da commit 8699b68
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions op.c
Original file line number Diff line number Diff line change
Expand Up @@ -8030,6 +8030,11 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg)
/* 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");

/* OK lets at least warn */
// TODO: do we set a sunset version?
ck_warner(packWARN(WARN_DEPRECATED),
"use VERSION while another use VERSION is in scope is now deprecated");
}

/* If a version >= 5.11.0 is requested, strictures are on by default! */
Expand Down
24 changes: 24 additions & 0 deletions pod/perldiag.pod
Original file line number Diff line number Diff line change
Expand Up @@ -7852,6 +7852,30 @@ even if it requests a later version.
subsequent one that calls for a Perl version of at least 5.39 while the first
is visible.

=item use VERSION while another use VERSION is in scope is now deprecated

(W deprecated) Once you have a C<use VERSION> statement in scope, any other
C<use VERSION> statement is now deprecated, due to the increasing complexity
of swapping from one prevalent version to another.

It is suggested that you do not try to mix multiple different version
declarations within the same file as it leads to complex behaviours about the
visibiity of features and builtin functions, as well as confusing human
readers.

If it is essential to have different C<use VERSION> declarations in different
regions of the same file, you should surround each one by its own enclosing
scope so the two do not mix.

{
use v5.20;
...
}
{
use v5.36;
...
}

=item Use \x{...} for more than two hex characters in regex; marked by
S<<-- HERE> in m/%s/

Expand Down
6 changes: 6 additions & 0 deletions t/lib/warnings/op
Original file line number Diff line number Diff line change
Expand Up @@ -2157,3 +2157,9 @@ c
a
d
b
########
use warnings;
use v5.12;
use v5.20;
EXPECT
use VERSION while another use VERSION is in scope is now deprecated at - line 3.
1 change: 1 addition & 0 deletions t/lib/warnings/pp_ctl
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ EXPECT
use warnings;
eval 'use 5.006; use 5.10.0';
EXPECT
use VERSION while another use VERSION is in scope is now deprecated at (eval 1) line 1.
########
# SKIP ? !$Config{default_inc_includes_dot}
# NAME check warning for do with no . in @INC
Expand Down

0 comments on commit 8699b68

Please sign in to comment.