[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]

Re: [ID 20000122.001] Incorrect scoping of if(){}else{}



On Sat, 22 Jan 2000 10:14:05 PST, Larry Wall wrote:
>That being said, I'm not sure we should remove the warning, since the
>outer block is implicit, and the presence of such a redeclaration is in
>all likelihood an error.  I imagine it was an error that caused the
>problem to be noticed in the first place, no?
>
>But the message is still slightly false.

I recall my original reasoning was that people wouldn't be declaring a
lexical in the conditional if they didn't expect to use the same
lexical in both branches of the conditional/loop.  But I guess
we should allow for people doing things such as:

    while (my $x = foo()) {
        my $x = bar($x);
    }
    continue {
        print $x;
    }

and the like.

So here's a patch.


Sarathy
gsar@ActiveState.com
-----------------------------------8<-----------------------------------
Change 4847 by gsar@auger on 2000/01/23 04:47:25

	don't warn about masked lexical in C<if (my $x = 1) { my $x; }>,
	C<while (my $x = foo()) { my $x = bar(); }> etc.

Affected files ...

... //depot/perl/op.c#241 edit

Differences ...

==== //depot/perl/op.c#241 (text) ====
Index: perl/op.c
--- perl/op.c.~1~	Sat Jan 22 20:56:09 2000
+++ perl/op.c	Sat Jan 22 20:56:09 2000
@@ -2008,12 +2008,11 @@
     int retval = PL_savestack_ix;
 
     SAVEI32(PL_comppad_name_floor);
-    if (full) {
-	if ((PL_comppad_name_fill = AvFILLp(PL_comppad_name)) > 0)
-	    PL_comppad_name_floor = PL_comppad_name_fill;
-	else
-	    PL_comppad_name_floor = 0;
-    }
+    PL_comppad_name_floor = AvFILLp(PL_comppad_name);
+    if (full)
+	PL_comppad_name_fill = PL_comppad_name_floor;
+    if (PL_comppad_name_floor < 0)
+	PL_comppad_name_floor = 0;
     SAVEI32(PL_min_intro_pending);
     SAVEI32(PL_max_intro_pending);
     PL_min_intro_pending = 0;
@@ -2028,8 +2027,6 @@
         PL_compiling.cop_warnings = newSVsv(PL_compiling.cop_warnings) ;
         SAVEFREESV(PL_compiling.cop_warnings) ;
     }
-
-
     return retval;
 }
 
End of Patch.


References to:
Larry Wall <larry@wall.org>

[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index][Thread Index][Top&Search][Original]