Subject: | ProhibitReusedNames vs "my" in expression |
Date: | Sat, 29 Jan 2011 08:29:49 +1100 |
To: | bug-Perl-Critic [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
When ProhibitReusedNames searches upwards for an existing lexical it
doesn't seem to see a "my" which is within a list or an expression, per
the failing cases below.
The most typical is probably a "my" in an "if", like
if (my $foo = some_thing()) {
...
}
Index: ProhibitReusedNames.run
===================================================================
--- ProhibitReusedNames.run (revision 4013)
+++ ProhibitReusedNames.run (working copy)
@@ -282,6 +282,40 @@
#-----------------------------------------------------------------------------
+## name variable in list
+## failures 1
+## TODO Descend into lists
+## cut
+
+(my $foo, my $bar) = (1, 2);
+{
+ my $foo = 3;
+}
+
+#-----------------------------------------------------------------------------
+
+## name variable in conditional
+## failures 1
+## TODO Descend into expressions
+## cut
+
+if (my $foo = 1) {
+ my $foo = 2;
+}
+
+#-----------------------------------------------------------------------------
+
+## name variable in expression in conditional
+## failures 1
+## TODO Descend into expressions
+## cut
+
+if (defined (my $foo = 1)) {
+ my $foo = 2;
+}
+
+#-----------------------------------------------------------------------------
+
##############################################################################
# $URL$
# $Date$