This and other RFCs are available on the web at
  http://dev.perl.org/rfc/

=head1 TITLE

variable usage warnings

=head1 VERSION

  Maintainer: Steve Fink <[EMAIL PROTECTED]>
  Date: 2 Aug 2000
  Last Modified: 19 Sep 2000
  Mailing List: [EMAIL PROTECTED]
  Number: 12
  Version: 2
  Status: Developing

=head1 ABSTRACT

"VARIABLE used only once: possible typo" should be replaced with
warnings on uses of uninitialized variables (including lexicals).

=head1 CHANGES

v2: Separated "definitions without uses" from "uses without
definitions" (def-use and use-def chains).

=head1 DESCRIPTION

Perl6 should distinguish between uses and assignments to variables,
and warn only when a variable is used without being assigned, or
assigned to without being used. In perl5 the complete program

 $x = 3

complains, but

 $x = 3; $x = 3

does not, nor does

 my $x = 3

nor

 use vars qw($x $y); $x = $z; $y = $z;

It would be more useful to have a complaint for both lexical and
package variables, and only when a variable is used without ever being
assigned to (or having its reference taken).

The warning for the use of an unassigned variable should be "use of
uninitialized variable C<$x>". This message is too close to the
existing "use of uninitialized value", but that message is badly
phrased anyway, so it will change to "use of undefined value" to
better reflect its actual meaning. (The two are related; "use of
undefined value" can be thought of as encompassing the runtime
counterpart to the compile-time "use of uninitialized variable"
proposed here.) The assignment of a variable which is never used will
result in "variable C<$x> defined but never used".

Note that if you currently depend on lexical variables having
undefined values, you would need to change C<my $x> to
C<my $x = undef>. This is a good thing.

=head1 IMPLEMENTATION

I have no idea how difficult this would be to implement. You just need
to distinguish between lvalue and rvalue uses of a variable, I guess?
But hey, this is a language RFC, not an internals RFC. :-) There's
also the question of whether to properly track uses and definitions so
that C<$::z = $x; $x = 3> is a warning, as well as
C<$x = 3 if f(); print $x>. Though the latter would require renaming
the warning to "possible use of uninitialized variable C<$x>".

=head1 CONTRIBUTORS

Glenn Linderman <[EMAIL PROTECTED]> - definitions without uses

=head1 REFERENCES

None.

Reply via email to