summaryrefslogtreecommitdiff
path: root/t/op
diff options
context:
space:
mode:
authorFather Chrysostomos <sprout@cpan.org>2014-11-01 07:07:36 -0700
committerFather Chrysostomos <sprout@cpan.org>2014-11-13 04:49:38 -0800
commit0ac016fc68a8b6f210ddacb62494e53da203c571 (patch)
tree25a223ed56d7a4b515fc209a97e6ca9d3c88cc36 /t/op
parent0b2df18fd3736ebdac552d596b8976109f9f4643 (diff)
downloadperl-0ac016fc68a8b6f210ddacb62494e53da203c571.tar.gz
Deprecate inlining sub(){$x} if $x is changed elsewhere
With the new PadnameLVALUE flag, we can detect cases where an outer lexical is used multiple times in lvalue context. If the subroutine contains just a lexical variable and nothing else, deprecate this behaviour, so we can change it not to break the closure pattern at some future date. Future commits will fix those cases where the subroutine contains more than just a lexical variable, without a deprecation cycle. Adding this code to op_const_sv doesn’t really make sense. More to the point, having S_cv_clone_pad call op_const_sv doesn’t make sense, but changing that (moving this code directly to S_cv_clone_pad) will require other refactorings to avoid breaking some cases of constant (real constant) inlining, such as sub(){$x++ if 0; 3}, which cur- rently gets inlined.
Diffstat (limited to 't/op')
-rw-r--r--t/op/const-optree.t7
1 files changed, 6 insertions, 1 deletions
diff --git a/t/op/const-optree.t b/t/op/const-optree.t
index 3807b2ea97..aab6fdcfd3 100644
--- a/t/op/const-optree.t
+++ b/t/op/const-optree.t
@@ -8,7 +8,7 @@ BEGIN {
require './test.pl';
@INC = '../lib';
}
-plan 6;
+plan 7;
# [perl #63540] Don’t treat sub { if(){.....}; "constant" } as a constant
@@ -26,6 +26,8 @@ BEGIN {
# [perl #79908]
{
+ my $w;
+ local $SIG{__WARN__} = sub {$w .= shift};
my $x = 5;
*_79908 = sub (){$x};
$x = 7;
@@ -35,6 +37,9 @@ BEGIN {
}
isnt eval '\_79908', \$x, 'sub(){$x} returns a copy';
ok eval '\_79908 != \_79908', 'sub(){$x} returns a copy each time';
+ like $w, qr/Constants from lexical variables potentially modified (?x:
+ )elsewhere are deprecated at /,
+ 'deprecation warning for sub(){$x}';
# Test another thing that was broken by $x inlinement
my $y;