[perl #117095] state var init getting skipped
authorDavid Mitchell <davem@iabyn.com>
Tue, 12 Mar 2013 13:23:46 +0000 (13:23 +0000)
committerDavid Mitchell <davem@iabyn.com>
Tue, 12 Mar 2013 13:23:46 +0000 (13:23 +0000)
Add test case for this bug, which was actually fixed 6 months ago with
ad9e6ae10fb581c6c053b862286f8e187063c3ab.

t/op/state.t

index 31eb2d2..327ddf5 100644 (file)
@@ -9,7 +9,7 @@ BEGIN {
 
 use strict;
 
-plan tests => 131;
+plan tests => 132;
 
 # Before loading feature.pm, test it with CORE::
 ok eval 'CORE::state $x = 1;', 'CORE::state outside of feature.pm scope';
@@ -405,6 +405,17 @@ foreach my $forbidden (<DATA>) {
 }
 
 
+# [perl #117095] state var initialisation getting skipped
+# the 'if 0' code below causes a call to op_free at compile-time,
+# which used to inadvertently mark the state var as initialised.
+
+{
+    state $f = 1;
+    foo($f) if 0; # this calls op_free on padmy($f)
+    ok(defined $f, 'state init not skipped');
+}
+
+
 __DATA__
 state ($a) = 1;
 (state $a) = 1;