curop->op_type == OP_PADHV ||
curop->op_type == OP_PADANY)
{
- if ((left->op_private & OPpLVAL_INTRO) && (curop->op_private & OPpPAD_STATE)) {
- o->op_private |= OPpASSIGN_STATE;
- /* hijacking PADSTALE for uninitialized state variables */
- SvPADSTALE_on(PAD_SVl(curop->op_targ));
+ if (curop->op_private & OPpPAD_STATE) {
+ if (left->op_private & OPpLVAL_INTRO) {
+ o->op_private |= OPpASSIGN_STATE;
+ /* hijacking PADSTALE for uninitialized state variables */
+ SvPADSTALE_on(PAD_SVl(curop->op_targ));
+ }
+ else if (ckWARN(WARN_MISC)) {
+ Perl_warner(aTHX_ packWARN(WARN_MISC), "State variable %s will be reinitialized",
+ PAD_COMPNAME_PV(curop->op_targ));
+ }
}
if (PAD_COMPNAME_GEN(curop->op_targ)
== (STRLEN)PL_generation)
iterate more times than there are characters of input, which is what
happened.) See L<perlfunc/split>.
+=item State variable %s will be reinitialized
+
+(W misc) You're declaring a C<state> variable inside a list. The list
+assignment will be treated by perl as a regular assignment, which means
+that the C<state> variable will be reinitialized each time the statement
+is run. The solution to have it initialized twice is to write the
+assignment on its own line, as in:
+
+ state $var = 42;
+
=item Statement unlikely to be reached
(W exec) You did an exec() with some statement after it other than a
Deprecated use of my() in false conditional at - line 7.
Deprecated use of my() in false conditional at - line 8.
Deprecated use of my() in false conditional at - line 9.
+########
+# op.c
+use feature 'state';
+use warnings 'misc';
+state($x) = 1;
+(state $y) = 2;
+(state $z, my $t) = (3, 4);
+(state $foo, state $bar) = (5, 6);
+no warnings 'misc';
+state($x) = 1;
+(state $y) = 2;
+(state $z, my $t) = (3, 4);
+(state $foo, state $bar) = (5, 6);
+EXPECT
+State variable $z will be reinitialized at - line 6.
+State variable $foo will be reinitialized at - line 7.
+State variable $bar will be reinitialized at - line 7.