Change 28496 by [EMAIL PROTECTED] on 2006/07/06 15:49:30
Add a new warning, "State variable %s will be reinitialized"
Affected files ...
... //depot/perl/op.c#832 edit
... //depot/perl/pod/perldiag.pod#445 edit
... //depot/perl/t/lib/warnings/op#30 edit
Differences ...
==== //depot/perl/op.c#832 (text) ====
Index: perl/op.c
--- perl/op.c#831~28489~ 2006-07-05 14:00:31.000000000 -0700
+++ perl/op.c 2006-07-06 08:49:30.000000000 -0700
@@ -3800,10 +3800,16 @@
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)
==== //depot/perl/pod/perldiag.pod#445 (text) ====
Index: perl/pod/perldiag.pod
--- perl/pod/perldiag.pod#444~28491~ 2006-07-06 06:36:57.000000000 -0700
+++ perl/pod/perldiag.pod 2006-07-06 08:49:30.000000000 -0700
@@ -3745,6 +3745,16 @@
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
==== //depot/perl/t/lib/warnings/op#30 (text) ====
Index: perl/t/lib/warnings/op
--- perl/t/lib/warnings/op#29~27402~ 2006-03-07 08:49:58.000000000 -0800
+++ perl/t/lib/warnings/op 2006-07-06 08:49:30.000000000 -0700
@@ -1081,3 +1081,20 @@
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.
End of Patch.