Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Perl-Critic CPAN distribution.

Report information
The Basics
Id: 82965
Status: open
Priority: 0/
Queue: Perl-Critic

People
Owner: Nobody in particular
Requestors: victor [...] vsespb.ru
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: (no value)
Fixed in: (no value)



Subject: -1 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead
I have something like my $data = 'file content'; my ($pos_start, $pos_end) = (0, length($data)-1); obviously "-1" should be allowed here. btw my $data = 'file content'; my $len = length($data); my ($pos_start, $pos_end) = (0, $len -1); works without warning.
Subject: Re: [rt.cpan.org #82965] -1 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead
Date: Fri, 25 Jan 2013 23:00:32 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <elliotjs [...] cpan.org>
On 1/25/13 5:31 PM, Victor Efimov via RT wrote: Show quoted text
> I have something like > > my $data = 'file content'; > my ($pos_start, $pos_end) = (0, length($data)-1); > > obviously "-1" should be allowed here.
"-1" is not an allowed value, purposely. On the other hand, subtracting "1" is allowed. Put a space between the minus and the digit and PPI will parse the two separately. Show quoted text
> ppidump '(0, length($data)-1);'
PPI::Document PPI::Statement PPI::Structure::List ( ... ) PPI::Statement::Expression [ 1, 2, 2 ] PPI::Token::Number '0' [ 1, 3, 3 ] PPI::Token::Operator ',' [ 1, 5, 5 ] PPI::Token::Word 'length' PPI::Structure::List ( ... ) PPI::Statement::Expression [ 1, 12, 12 ] PPI::Token::Symbol '$data' [ 1, 18, 18 ] PPI::Token::Number '-1' [ 1, 21, 21 ] PPI::Token::Structure ';' Show quoted text
> ppidump '(0, length($data) - 1);'
PPI::Document PPI::Statement PPI::Structure::List ( ... ) PPI::Statement::Expression [ 1, 2, 2 ] PPI::Token::Number '0' [ 1, 3, 3 ] PPI::Token::Operator ',' [ 1, 5, 5 ] PPI::Token::Word 'length' PPI::Structure::List ( ... ) PPI::Statement::Expression [ 1, 12, 12 ] PPI::Token::Symbol '$data' [ 1, 18, 18 ] PPI::Token::Operator '-' [ 1, 20, 20 ] PPI::Token::Number '1' [ 1, 22, 22 ] PPI::Token::Structure ';'
ok, that helped. thanks! On Sat Jan 26 09:00:44 2013, ELLIOTJS wrote: Show quoted text
> On 1/25/13 5:31 PM, Victor Efimov via RT wrote:
> > I have something like > > > > my $data = 'file content'; > > my ($pos_start, $pos_end) = (0, length($data)-1); > > > > obviously "-1" should be allowed here.
> > "-1" is not an allowed value, purposely. > > On the other hand, subtracting "1" is allowed. > > Put a space between the minus and the digit and PPI will parse the two > separately. >
> > ppidump '(0, length($data)-1);'
> PPI::Document > PPI::Statement > PPI::Structure::List ( ... ) > PPI::Statement::Expression > [ 1, 2, 2 ] PPI::Token::Number '0' > [ 1, 3, 3 ] PPI::Token::Operator ',' > [ 1, 5, 5 ] PPI::Token::Word 'length' > PPI::Structure::List ( ... ) > PPI::Statement::Expression > [ 1, 12, 12 ] PPI::Token::Symbol '$data' > [ 1, 18, 18 ] PPI::Token::Number '-1' > [ 1, 21, 21 ] PPI::Token::Structure ';' > > >
> > ppidump '(0, length($data) - 1);'
> PPI::Document > PPI::Statement > PPI::Structure::List ( ... ) > PPI::Statement::Expression > [ 1, 2, 2 ] PPI::Token::Number '0' > [ 1, 3, 3 ] PPI::Token::Operator ',' > [ 1, 5, 5 ] PPI::Token::Word 'length' > PPI::Structure::List ( ... ) > PPI::Statement::Expression > [ 1, 12, 12 ] PPI::Token::Symbol '$data' > [ 1, 18, 18 ] PPI::Token::Operator '-' > [ 1, 20, 20 ] PPI::Token::Number '1' > [ 1, 22, 22 ] PPI::Token::Structure ';'
Subject: Re: [rt.cpan.org #82965] -1 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead
Date: Tue, 29 Jan 2013 11:42:00 -0800
To: bug-Perl-Critic [...] rt.cpan.org
From: Jeffrey Ryan Thalhammer <jeff [...] imaginative-software.com>
On Jan 25, 2013, at 9:00 PM, Elliot Shank via RT wrote: Show quoted text
> "-1" is not an allowed value, purposely.
Elliot: can you remind me why that is? Show quoted text
> On the other hand, subtracting "1" is allowed. > > Put a space between the minus and the digit and PPI will parse the two separately.
Hmm, that seems a bit specious to me. Mathematically they are identical, and whitespace is not supposed to be significant. It doesn't seem right that PPI parses them differently. -Jeff
Subject: Re: [rt.cpan.org #82965] -1 is not one of the allowed literal values (0, 1, 2). Use the Readonly or Const::Fast module or the "constant" pragma instead
Date: Tue, 29 Jan 2013 21:47:11 -0600
To: bug-Perl-Critic [...] rt.cpan.org
From: Elliot Shank <elliotjs [...] cpan.org>
On 1/29/13 6:00 PM, Jeffrey Thalhammer via RT wrote: Show quoted text
> Hmm, that seems a bit specious to me. Mathematically they are > identical, and whitespace is not supposed to be significant. It > doesn't seem right that PPI parses them differently.
Net result may be the same, but there's definitely a difference between a constant and a unary operator applied to a constant.
It's odd that -1 isn't allowed when perl's builtin index() is documented to return -1 for match failure - and as far as I know, there is no standard symbolic constant to use instead. (If you look through perlfunc there are a few other cases where -1 is used as a return value, with code examples to match.)
On Tue Jan 29 22:47:15 2013, ELLIOTJS wrote: Show quoted text
> On 1/29/13 6:00 PM, Jeffrey Thalhammer via RT wrote:
> > Hmm, that seems a bit specious to me. Mathematically they are > > identical, and whitespace is not supposed to be significant. It > > doesn't seem right that PPI parses them differently.
> > Net result may be the same, but there's definitely a difference > between a constant and a unary operator applied to a constant.
length($foo)-1 is not lexed by perl as a constant, it is lexed as a unary operator followed by a constant, as perl is expecting an operator after a term (usually, examples otherwise are generally considered warts). PPI is most certainly wrong here. Leon