# New Ticket Created by  "Yehoshua Sapir" 
# Please include the string:  [perl #42300]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=42300 >



--- t/pmc/sub.t	2007-04-04 17:20:12.000000000 +0300
+++ t/pmc/sub.new.t	2007-04-04 17:22:18.000000000 +0300
@@ -7,7 +7,7 @@
 use lib qw( . lib ../lib ../../lib );
 
 use Test::More;
-use Parrot::Test tests => 61;
+use Parrot::Test tests => 62;
 use Parrot::Config;
 
 =head1 NAME
@@ -1379,6 +1379,57 @@
 parrot;Foo;Bar
 OUTPUT
 
+pir_output_is( <<'CODE', <<'OUTPUT', 'newclosure/clone Sub lex creation' );
+.sub main :main
+    $P1 = new .String
+    $P1 = 'ok'
+    $P2 = new .String
+    $P2 = 'not ok'
+    
+    # if 'not ok' is printed, it means that the lexical environment
+    # for the first closure in each pair, (where "out" = "ok")
+    # was overwritten by the lexical environment created for the
+    # second closure (where "out" = "not ok")
+    
+    $P10 = makefoo_newclosure($P1)
+    $P20 = makefoo_newclosure($P2)
+    $P10()
+    
+    $P10 = makebar_clone($P1)
+    $P20 = makebar_clone($P2)
+    $P10()
+.end
+
+.sub makefoo_newclosure
+    .param pmc out
+    .lex 'out', out
+    .const .Sub s = 'foo'
+    $P0 = newclosure s
+    .return($P0)
+.end
+
+.sub makebar_clone
+    .param pmc out
+    .lex 'out', out
+    .const .Sub s = 'foo'
+    $P0 = clone s
+    .return($P0)
+.end
+
+.sub foo :outer(makefoo_newclosure)
+    $P0 = find_lex 'out'
+    say $P0
+.end
+
+.sub bar :outer(makebar_clone)
+    $P0 = find_lex 'out'
+    say $P0
+.end
+CODE
+ok
+ok
+OUTPUT
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4

Reply via email to