From 3ce45d2161eb6dde6fbb82adde7d421df1d2b5f9 Mon Sep 17 00:00:00 2001 From: "Paul \"LeoNerd\" Evans" Date: Wed, 17 Jan 2024 18:02:00 +0000 Subject: [PATCH] `use VERSION` implies `use builtin :VERSION` --- op.c | 10 ++++++++++ pod/perlfunc.pod | 18 ++++++++++++------ t/comp/use.t | 14 +++++++++++++- 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/op.c b/op.c index 9029126ea5930..5a37ae2fcbe22 100644 --- a/op.c +++ b/op.c @@ -8046,6 +8046,16 @@ Perl_utilize(pTHX_ int aver, I32 floor, OP *version, OP *idop, OP *arg) PL_hints &= ~HINT_STRICT_VARS; } + /* As an optimisation, there's no point scanning for changes of + * visible builtin functions when switching between versions earlier + * than v5.39, when any became visible at all + */ + if ((shortver >= SHORTVER(5, 39)) || (PL_prevailing_version >= SHORTVER(5, 39))) { + prepare_export_lexical(); + import_builtin_bundle(shortver, true); + finish_export_lexical(); + } + PL_prevailing_version = shortver; } diff --git a/pod/perlfunc.pod b/pod/perlfunc.pod index 3364c1fd5eb62..bb2106b3f27ee 100644 --- a/pod/perlfunc.pod +++ b/pod/perlfunc.pod @@ -10161,12 +10161,18 @@ Compare with L|/require VERSION>, which can do a similar check at run time. If the specified Perl version is 5.12 or higher, strictures are enabled -lexically as with L|strict>. Similarly, if the specified -Perl version is 5.35.0 or higher, L are enabled. Later use of -C will override all behavior of a previous C, -possibly removing the C, C, and C added by it. -C does not load the F, F, or -F files. +lexically as with L|strict>. + +If the specified Perl version is 5.35.0 or higher, L are enabled. + +If the specified Perl version is 5.39.0 or higher, builtin functions are +imported lexically as with L|builtin> with a corresponding +version bundle. + +Later use of C will override all behavior of a previous +C, possibly removing the C, C, C and +C effects added by it. C does not load the +F, F, F or F files. In the current implementation, any explicit use of C or C overrides C, even if it comes before it. diff --git a/t/comp/use.t b/t/comp/use.t index 8111b6941f5c4..e6042f16aef6e 100644 --- a/t/comp/use.t +++ b/t/comp/use.t @@ -6,7 +6,7 @@ BEGIN { $INC{"feature.pm"} = 1; # so we don't attempt to load feature.pm } -print "1..85\n"; +print "1..88\n"; # Can't require test.pl, as we're testing the use/require mechanism here. @@ -170,6 +170,18 @@ ok $@, 'no strict vars allows ver decl to enable refs'; eval 'no strict "vars"; use 5.012; ursine_word'; ok $@, 'no strict vars allows ver decl to enable subs'; +# check that "use 5.39.0" and higher imports builtins +{ + my $result; + + $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