=head1 TITLE variable usage warnings =head1 VERSION Maintainer: Steve Fink <[EMAIL PROTECTED]> for now Date: 2 Aug 2000 Version: 1 Mailing List: [EMAIL PROTECTED] Number: 12 =head1 ABSTRACT "VARIABLE used only once: possible typo" should be replaced with warnings on uses of uninitialized variables (including lexicals). =head1 DESCRIPTION Perl6 should distinguish between uses and assignments to variables, and warn only when a variable is used without being assigned. 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 purpose described in this RFC 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.) 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>".