This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
better handle freeing of code blocks in /(?{...})/
[perl5.git] / t / op / closure.t
index 82e65c5..9d3de7f 100644 (file)
@@ -8,8 +8,8 @@
 
 BEGIN {
     chdir 't' if -d 't';
-    @INC = '../lib';
     require './test.pl';
+    set_up_inc('../lib');
 }
 
 use Config;
@@ -671,20 +671,6 @@ $r = \$x
         "don't copy a stale lexical; create a fresh undef one instead");
 }
 
-# [perl #63540] Don’t treat sub { if(){.....}; "constant" } as a constant
-
-BEGIN {
-  my $x = 7;
-  *baz = sub() { if($x){ () = "tralala"; blonk() }; 0 }
-}
-{
-  my $blonk_was_called;
-  *blonk = sub { ++$blonk_was_called };
-  my $ret = baz();
-  is($ret, 0, 'RT #63540');
-  is($blonk_was_called, 1, 'RT #63540');
-}
-
 # test PL_cv_has_eval.  Any anon sub that could conceivably contain an
 # eval, should be marked as cloneable
 
@@ -747,7 +733,7 @@ is $closure_test::s2->()(), '10 cubes',
        };
     };
     $s1->();
-    undef &$s1; # frees $s2s prototype, causing the $s3 proto to have its
+    undef &$s1; # frees $s2's prototype, causing the $s3 proto to have its
                 # CvOUTSIDE point to $s1
     ::is $s2->()(), 3, 'cloning closure proto whose CvOUTSIDE has changed';
 }
@@ -815,4 +801,14 @@ SKIP: {
         'closures in source filters do not interfere with pad names';
 }
 
+sub {
+    my $f;
+    sub test_ref_to_unavailable {
+       my $ref = \$f;
+        $$ref = 7;
+        is $f, 7, 'taking a ref to unavailable var should not copy it';
+    }
+};
+test_ref_to_unavailable();
+
 done_testing();