Perl-Critic / PPI

53 stars 44 forks source link

Operator Classified As Cast #94

Closed thaljef closed 10 years ago

thaljef commented 10 years ago

In the following expression, the * operator is misclassified as a cast:

my $v = $opts{r}*$g;

Parse tree (PPI version 1.219_001)

                    PPI::Document604
                      PPI::Statement::Variable
[    1,   1,   1 ]     PPI::Token::Word     'my'
[    1,   4,   4 ]     PPI::Token::Symbol   '$v'
[    1,   7,   7 ]     PPI::Token::Operator     '='
[    1,   9,   9 ]     PPI::Token::Symbol   '$opts'
                        PPI::Structure::Subscript   { ... }
                          PPI::Statement::Expression
[    1,  15,  15 ]         PPI::Token::Word     'r'
[    1,  17,  17 ]     PPI::Token::Cast     '*'     <------------------- WRONG !!!
[    1,  18,  18 ]     PPI::Token::Symbol   '$g'
[    1,  20,  20 ]     PPI::Token::Structure    ';'

NB: Adding whitespace after the * operator produces the correct result.

This was originally reported as Perl-Critic/Perl-Critic#604

wchristian commented 10 years ago

Balls. Thanks, i'll try and figure out how to fix that.

adamkennedy commented 10 years ago

This is one of those cases where i wish I'd written a more generic operator vs operand context thingy. On Nov 5, 2014 6:49 PM, "Christian Walde" notifications@github.com wrote:

Balls. Thanks, i'll try and figure out how to fix that.

— Reply to this email directly or view it on GitHub https://github.com/adamkennedy/PPI/issues/94#issuecomment-61919666.

wchristian commented 10 years ago

Ok, i think i fixed this.

@adamkennedy : Can you please look at the commit to verify that the change looks sane for this issue?

Further, can you please make another issue elaborating on what you mean with operator/operand context/method?

@thaljef : This issue has been present since roughly 2006. As such, i hope you don't mind if this fix will be released with 1.222, and 1.220 to be released unchanged from the dev release.

thaljef commented 10 years ago

i hope you don't mind if this fix will be released with 1.222

@wchristian: No problem.

wchristian commented 10 years ago

Related: https://rt.cpan.org/Ticket/Display.html?id=41733