Perl-Critic / PPI

53 stars 44 forks source link

modulus and bit-and operators classified as casts #119

Closed moregan closed 6 years ago

moregan commented 9 years ago

Just as with #94 and the '*' operator, the '%' and '&' operators can be parsed as casts if there's no whitespace after them:

ppidump '$o->{tsize}%$o->{ratio}'
                    PPI::Document
                      PPI::Statement
[    1,   1,   1 ]     PPI::Token::Symbol       '$o'
[    1,   3,   3 ]     PPI::Token::Operator     '->'
                        PPI::Structure::Subscript       { ... }
                          PPI::Statement::Expression
[    1,   6,   6 ]         PPI::Token::Word     'tsize'
[    1,  12,  12 ]     PPI::Token::Cast         '%'
[    1,  13,  13 ]     PPI::Token::Symbol       '$o'
[    1,  15,  15 ]     PPI::Token::Operator     '->'
                        PPI::Structure::Subscript       { ... }
                          PPI::Statement::Expression
[    1,  18,  18 ]         PPI::Token::Word     'ratio'

perl -WE 'my $x={a=>7}; my $y={b=>3}; say $x->{a}%$y->{b};'
1

and

ppidump '$o->{tsize}&$o->{ratio}'
                    PPI::Document
                      PPI::Statement
[    1,   1,   1 ]     PPI::Token::Symbol       '$o'
[    1,   3,   3 ]     PPI::Token::Operator     '->'
                        PPI::Structure::Subscript       { ... }
                          PPI::Statement::Expression
[    1,   6,   6 ]         PPI::Token::Word     'tsize'
[    1,  12,  12 ]     PPI::Token::Cast         '&'
[    1,  13,  13 ]     PPI::Token::Symbol       '$o'
[    1,  15,  15 ]     PPI::Token::Operator     '->'
                        PPI::Structure::Subscript       { ... }
                          PPI::Statement::Expression
[    1,  18,  18 ]         PPI::Token::Word     'ratio'

perl -WE 'my $x={a=>7}; my $y={b=>3}; say $x->{a}&$y->{b};'
3
moregan commented 9 years ago

See the regression the fix for #94 introduced: https://github.com/adamkennedy/PPI/issues/134

wchristian commented 9 years ago

I have some preliminary work on this in the branch https://github.com/adamkennedy/PPI/tree/cast_or_op

Amorymeltzer commented 6 years ago

This was fixed, no?

moregan commented 6 years ago

This was fixed, no?

Fixed with https://github.com/adamkennedy/PPI/commit/c276409649bf750ea9d30c585bdee5deaa570376 and released in 1.222