Phoenix.pm: davem@fdisolutions.com: Re: Whither 5.6.3?
Scott Walters
scott at illogics.org
Sat Jan 31 22:55:10 CST 2004
my $x if 0;
This form created a lexical variable that never re-initializes. It
keeps its value across subroutine calls, like a C 'static'.
For example:
perl -e 'sub foo { my $x if 0; print $x, "\n"; $x = shift; } foo(10); foo(20); foo(40);'
Looks like they're getting ready to nuke the "feature".
-scott
----- Forwarded message from Dave Mitchell <davem at fdisolutions.com> -----
ID: <20040201015900.GD20819 at fdisolutions.com>
List: contact perl5-porters-help at perl.org; run by ezmlm
Status: No, hits=-4.9 required=8.0 tests=BAYES_00 autolearn=ham version=2.63
post: <mailto:perl5-porters at perl.org>
SMTPD: qpsmtpd/0.26, http://develooper.com/code/qpsmtpd/
Disposition: inline
Type: text/plain; charset=us-ascii
Spam-Index: -9.5
Filter-Rule: None, default is delivery
References: <71B318898201D311845C0008C75DAD1C0A44CA54 at defra1ex2>
Archive: <http://nntp.perl.org/group/perl.perl5.porters/88100>
help: <mailto:perl5-porters-help at perl.org>
Agent: Mutt/1.4.1i
Received: from onion.perl.org (onion.develooper.com [63.251.223.166]) (qmail 11033 invoked by uid 1005); 1 Feb 2004 02:26:16 -0000 (qmail 10904 invoked by uid 76); 1 Feb 2004 02:26:11 -0000
Cc: 'Yitzchak Scott-Thoennes' <sthoenna at efn.org>, perl5-porters at perl.org
Subject: Re: Whither 5.6.3?
unsubscribe: <mailto:perl5-porters-unsubscribe at perl.org>
Spam-Is-Higher-Than: 5
Date: Sun, 1 Feb 2004 01:59:00 +0000
Version: 1.0 SpamAssassin 2.63 (2004-01-11) on x1.develooper.com
Precedence: bulk
To: "mailing list perl5-porters at perl.org perl5-porters at perl.org Orton, Yves" <yves.orton at de.mci.com>,
"Orton, Yves" <yves.orton at de.mci.com>,
'Yitzchak Scott-Thoennes' <sthoenna at efn.org>,
"perl5-porters at perl.org" <71B318898201D311845C0008C75DAD1C0A44CA54 at defra1ex2>
From: Dave Mitchell <davem at fdisolutions.com>
Disclaimer: This disclaimer may not be read without permission
On Thu, Jan 29, 2004 at 05:10:32PM -0000, Orton, Yves wrote:
[discussion of C<my $x if $condition> ]
> Oh, dont get me wrong. Make it a syntax error, or a warning or whatever. I
> only commented becuase I think the meme is wider spread than one might think
> and that it may affect more code than one might think.
>
> But I know that personally Ive been bitten by it and would have loved a
> warning.
The patch below attempts to give such a warning. I'll apply it in a couple
of days if no one objects.
$ ./perl -we 'my $x if $a'
Use of my in conditional deprecated at -e line 1.
If detects and/or/if/unless as simple statements, eg the following all
give the a warning:
my $x if $a;
$a && (my $x = 1);
my ($x, at y) = (1,2,3) unless $a;
$a || (my ($x, at y) = (1,2,3));
but the following doesn't warn:
if ($a && (my $foo = ...)) { print $foo }
This patch threw up quite a lot of problems in the test suite, which is an
indication that there's a *lot* of code out there about to get noisy.
Here is a list of the major ones, along with sample snippets of code
Use of my in conditional deprecated at ../lib/IO/Handle.pm line 497.
Use of my in conditional deprecated at ../lib/IO/Handle.pm line 504.
Use of my in conditional deprecated at ../lib/IO/Handle.pm line 511.
Use of my in conditional deprecated at ../lib/IO/Handle.pm line 518.
Use of my in conditional deprecated at ../lib/IO/Handle.pm line 525.
Use of my in conditional deprecated at ../lib/IO/Handle.pm line 532.
Use of my in conditional deprecated at ../lib/IO/Handle.pm line 607.
my $tell = tell qualify($_[0], caller) if ref($_[0]);
Use of my in conditional deprecated at ../lib/B/Deparse.pm line 1089.
my $nseq = $self->find_scope_st($root->sibling) if ${$root->sibling};
Use of my in conditional deprecated at ../lib/IO/Pipe.pm line 125
my $pid = $me->_doit(1, $fh, @_)
if(@_);
Use of my in conditional deprecated at ../lib/ExtUtils/Liblist/Kid.pm line 230.
Use of my in conditional deprecated at ../lib/ExtUtils/Liblist/Kid.pm line 231.
Use of my in conditional deprecated at ../lib/ExtUtils/Liblist/Kid.pm line 232.
my $VC = 1 if $cc =~ /^cl/i;
my $BC = 1 if $cc =~ /^bcc/i;
my $GC = 1 if $cc =~ /^gcc/i;
Use of my in conditional deprecated at ../lib/ExtUtils/MM_NW5.pm line 35.
Use of my in conditional deprecated at ../lib/ExtUtils/MM_NW5.pm line 36.
Use of my in conditional deprecated at ../lib/ExtUtils/MM_NW5.pm line 37.
my $BORLAND = 1 if $Config{'cc'} =~ /^bcc/i;
my $GCC = 1 if $Config{'cc'} =~ /^gcc/i;
my $DMAKE = 1 if $Config{'make'} =~ /^dmake/i;
Use of my in conditional deprecated at ../lib/ExtUtils/MM_Win95.pm line 10.
Use of my in conditional deprecated at ../lib/ExtUtils/MM_Win95.pm line 11.
my $DMAKE = 1 if $Config{'make'} =~ /^dmake/i;
my $NMAKE = 1 if $Config{'make'} =~ /^nmake/i;
Use of my in conditional deprecated at ../utils/h2xs line 671.
my %const_xsub = map { $_,1 } split(/,+/, $opt_s) if $opt_s;
Use of my in conditional deprecated at ../lib/Net/NNTP.pm line 24.
Use of my in conditional deprecated at ../lib/Net/SMTP.pm line 27.
Use of my in conditional deprecated at ../lib/Net/POP3.pm line 24.
my $host = shift if @_ % 2;
Use of my in conditional deprecated at ../lib/Pod/Parser.pm line 1158.
my ($in_fh, $out_fh) = (gensym, gensym) if ($] < 5.6);
Use of my in conditional deprecated at ../lib/Test/Harness.pm line 466
my @dir_files = _globdir $Files_In_Dir if defined $Files_In_Dir;
> also a warning would be nice for
>
> my $foo=$_ for (1..10);
>
> which doesnt do anything like what it looks like it should do.
I'll worry about that one later!
Dave.
--
Nothing ventured, nothing lost.
--- opcode.pl- Sat Jan 31 23:08:40 2004
+++ opcode.pl Sun Feb 1 00:40:46 2004
@@ -684,8 +684,8 @@
reset symbol reset ck_fun is% S?
lineseq line sequence ck_null @
-nextstate next statement ck_null s;
-dbstate debug next statement ck_null s;
+nextstate next statement ck_state s;
+dbstate debug next statement ck_state s;
unstack iteration finalizer ck_null s0
enter block entry ck_null 0
leave block exit ck_null @
--- op.c- Sat Jan 31 22:57:27 2004
+++ op.c Sun Feb 1 01:36:30 2004
@@ -3305,7 +3305,7 @@
}
}
- return prepend_elem(OP_LINESEQ, (OP*)cop, o);
+ return prepend_elem(OP_LINESEQ, (OP*)cop, CHECKOP(cop->op_type, o));
}
@@ -5938,6 +5938,43 @@
}
OP *
+Perl_ck_state(pTHX_ OP *o)
+{
+ /* **NB** o is actually the sibling of the state op */
+
+ /* warn on C<my $x=1 if foo;> , C<$a && my $x=1;> style statements */
+ OP *kid;
+ if (!o || o->op_type != OP_NULL || !(o->op_flags & OPf_KIDS))
+ return o;
+ kid = cUNOPo->op_first;
+ if (!(kid->op_type == OP_AND || kid->op_type == OP_OR))
+ return o;
+ kid = kUNOP->op_first->op_sibling;
+ if (kid->op_type == OP_SASSIGN)
+ kid = kBINOP->op_first->op_sibling;
+ else if (kid->op_type == OP_AASSIGN)
+ kid = kBINOP->op_first->op_sibling;
+
+ if (kid->op_type == OP_LIST
+ || (kid->op_type == OP_NULL && kid->op_targ == OP_LIST))
+ {
+ kid = kUNOP->op_first;
+ if (kid->op_type == OP_PUSHMARK)
+ kid = kid->op_sibling;
+ }
+ if ((kid->op_type == OP_PADSV || kid->op_type == OP_PADAV
+ || kid->op_type == OP_PADHV)
+ && (kid->op_private & OPpLVAL_INTRO)
+ && (ckWARN(WARN_DEPRECATED)))
+ {
+ Perl_warner(aTHX_ packWARN(WARN_DEPRECATED),
+ "Use of my in conditional deprecated");
+ }
+ return o;
+}
+
+
+OP *
Perl_ck_subr(pTHX_ OP *o)
{
OP *prev = ((cUNOPo->op_first->op_sibling)
--- t/lib/warnings/op- Sat Jan 31 23:27:57 2004
+++ t/lib/warnings/op Sun Feb 1 01:53:18 2004
@@ -1050,3 +1050,60 @@
Useless localization of substr at - line 48.
Useless localization of match position at - line 49.
Useless localization of vec at - line 50.
+########
+# op.c
+use warnings 'deprecated';
+our $a;
+my $x1 if $a;
+my @x2 if $a;
+my %x3 if $a;
+my ($x4) if $a;
+my ($x5, at x6, %x7) if $a;
+my @x8 if ($a+$a);
+my $x9 = 1+$a if $a;
+my ($x10, at x11) = ($a,$a+$a) if $a;
+my ($x12) = 1 if $a;
+my $y1 unless $a;
+my @y2 unless $a;
+my %y3 unless $a;
+my ($y4) unless $a;
+my ($y5, at y6, %y7) unless $a;
+my @y8 unless ($a+$a);
+$a && my $z1;
+$a && my (%z2);
+$a || my @z3;
+$a || my (%z4);
+$a || my (%z4,$z5);
+$a && (my $z6 = 1);
+$a && (my ($z7, at z8) = (1,2,3));
+
+# these shouldn't warn
+our $x if $a;
+our $x unless $a;
+if ($a) { my $w1 }
+if (my $w2) { $a=1 }
+if ($a && (my $w3 = 1)) {$a = 2}
+
+EXPECT
+Use of my in conditional deprecated at - line 4.
+Use of my in conditional deprecated at - line 5.
+Use of my in conditional deprecated at - line 6.
+Use of my in conditional deprecated at - line 7.
+Use of my in conditional deprecated at - line 8.
+Use of my in conditional deprecated at - line 9.
+Use of my in conditional deprecated at - line 10.
+Use of my in conditional deprecated at - line 11.
+Use of my in conditional deprecated at - line 12.
+Use of my in conditional deprecated at - line 13.
+Use of my in conditional deprecated at - line 14.
+Use of my in conditional deprecated at - line 15.
+Use of my in conditional deprecated at - line 16.
+Use of my in conditional deprecated at - line 17.
+Use of my in conditional deprecated at - line 18.
+Use of my in conditional deprecated at - line 19.
+Use of my in conditional deprecated at - line 20.
+Use of my in conditional deprecated at - line 21.
+Use of my in conditional deprecated at - line 22.
+Use of my in conditional deprecated at - line 23.
+Use of my in conditional deprecated at - line 24.
+Use of my in conditional deprecated at - line 25.
--- pod/perldiag.pod- Sat Jan 31 23:47:54 2004
+++ pod/perldiag.pod Sun Feb 1 01:30:07 2004
@@ -4282,6 +4282,24 @@
it already went past any symlink you are presumably trying to look for.
The operation returned C<undef>. Use a filename instead.
+=item Use of my in conditional deprecated
+
+(D deprecated) You used a C<my> declaration within a conditional
+expression of some sort, such as C<my $x=1 if foo> or C<foo && (my $x = 1)>.
+Perl's run-time behaviour in such constructs is currently undefined, but
+typically causes the variable not be be cleared at the end of scope and
+to retain its old value the next time the scope is entered. Some people
+have been making use of this "feature" to implement a type of static
+variable. We intend to change this behaviour in a future release, so
+don't rely on it.
+
+To work around this warning, move the declaration outside the expression,
+eg
+
+ my $x;
+ $x = 1 if foo;
+
+
=item Use of "package" with no arguments is deprecated
(D deprecated) You used the C<package> keyword without specifying a package
----- End forwarded message -----
More information about the Phoenix-pm
mailing list