New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Wrong error for undef constant name #9836
Comments
From @nwc10Created by @nwc10$ ./perl -Ilib -we 'use constant undef, 1' However, given that the code for constant looks like this: if ( $multiple ) { foreach my $name ( keys %$constants ) { it seems clear that the intent is that the error should be I can see two fixes. One is paranoid, one is fast. The paranoid fix is to duplicate that C<defined $name> clause into $constants->{+shift} = undef; This is paranoid because it copes with someone passing in a tied hash that The "fast" version is simply to move the check. This gets it out of the loop, Nicholas Clark Perl Info
|
@xdg - Status changed from 'new' to 'open' |
From zefram@fysh.orgAttached patch fixes bug #68640. -zefram |
From zefram@fysh.orgInline Patchdiff --git a/dist/constant/lib/constant.pm b/dist/constant/lib/constant.pm
index a51ee7f..3ee1a6f 100644
--- a/dist/constant/lib/constant.pm
+++ b/dist/constant/lib/constant.pm
@@ -4,7 +4,7 @@ use strict;
use warnings::register;
use vars qw($VERSION %declared);
-$VERSION = '1.19';
+$VERSION = '1.20';
#=======================================================================
@@ -60,15 +60,14 @@ sub import {
}
$constants = shift;
} else {
- $constants->{+shift} = undef;
- }
-
- foreach my $name ( keys %$constants ) {
- unless (defined $name) {
+ unless (defined $_[0]) {
require Carp;
Carp::croak("Can't use undef as constant name");
}
+ $constants->{+shift} = undef;
+ }
+ foreach my $name ( keys %$constants ) {
# Normal constant name
if ($name =~ $normal_constant_name and !$forbidden{$name}) {
# Everything is okay
diff --git a/dist/constant/t/constant.t b/dist/constant/t/constant.t
index a42b7d2..85a9355 100644
--- a/dist/constant/t/constant.t
+++ b/dist/constant/t/constant.t
@@ -9,7 +9,7 @@ END { @warnings && print STDERR join "\n- ", "accumulated warnings:", @warnings
use strict;
-use Test::More tests => 95;
+use Test::More tests => 96;
my $TB = Test::More->builder;
BEGIN { use_ok('constant'); }
@@ -341,3 +341,9 @@ $kloong = 'schlozhauer';
is ($@, '');
is_deeply (\@value, []);
}
+
+{
+ local $SIG{'__WARN__'} = sub { die "WARNING: $_[0]" };
+ eval 'use constant undef, 5; 1';
+ like $@, qr/\ACan't use undef as constant name at /;
+} |
From @rgarcia2009/12/14 Zefram <zefram@fysh.org>:
Thanks, applied to bleadperl. cc:ing Sébastien for the CPAN release. |
@rgs - Status changed from 'open' to 'resolved' |
From @maddingueRafael Garcia-Suarez wrote:
With apologies for the delay, constant 0.20 is now uploaded on the -- Close the world, txEn eht nepO. |
Migrated from rt.perl.org#68640 (status was 'resolved')
Searchable as RT68640$
The text was updated successfully, but these errors were encountered: