Skip to content

Fix Style/MethodCallWithArgsParentheses cop error on complex numbers#14146

Merged
koic merged 1 commit into
rubocop:masterfrom
viralpraxis:fix-style-method-call-with-args-parentheses-with-complex-numbers
May 2, 2025
Merged

Fix Style/MethodCallWithArgsParentheses cop error on complex numbers#14146
koic merged 1 commit into
rubocop:masterfrom
viralpraxis:fix-style-method-call-with-args-parentheses-with-complex-numbers

Conversation

@viralpraxis

Copy link
Copy Markdown
Contributor

EnforcedStyle: omit_parentheses

undefined method `sign?' for an instance of RuboCop::AST::Node
     # ./lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb:226:in `unary_literal?'
     # ./lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb:201:in `ambiguous_literal?'
     # ./lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb:146:in `block in call_with_ambiguous_arguments?'

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

`EnforcedStyle: omit_parentheses`

```bash
undefined method `sign?' for an instance of RuboCop::AST::Node
     # ./lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb:226:in `unary_literal?'
     # ./lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb:201:in `ambiguous_literal?'
     # ./lib/rubocop/cop/style/method_call_with_args_parentheses/omit_parentheses.rb:146:in `block in call_with_ambiguous_arguments?'
```
koic added a commit to koic/rubocop-ast that referenced this pull request May 2, 2025
This PR supports `RuboCop::AST::ComplexNode`.

The `complex` type is categorized as a `numeric` type,
so it should be handled transparently alongside `int`, `float`, and `rational`.

```ruby
int: :numeric,
float: :numeric,
rational: :numeric,
complex: :numeric,
```

https://github.com/rubocop/rubocop-ast/blob/v1.44.1/lib/rubocop/ast/node.rb#L106-L109

This eliminates the need for redundant branching, such as in rubocop/rubocop#14146.
@koic

koic commented May 2, 2025

Copy link
Copy Markdown
Member

It's likely that the implementation condition can be reverted in the future with rubocop/rubocop-ast#379, but this looks like a reasonable workaround for now.

@koic
koic merged commit f40d2e3 into rubocop:master May 2, 2025
viralpraxis added a commit to viralpraxis/rubocop that referenced this pull request May 3, 2025
For some reason I didn't check that signless complex numbers work well with this cop.

In that case `(node.complex_type? && node.source.match?(/\A[+-]/))` would be `false`
and we'd still try to send non-existend `sign?` message.
@viralpraxis
viralpraxis deleted the fix-style-method-call-with-args-parentheses-with-complex-numbers branch May 4, 2025 18:48
bbatsov pushed a commit that referenced this pull request May 4, 2025
For some reason I didn't check that signless complex numbers work well with this cop.

In that case `(node.complex_type? && node.source.match?(/\A[+-]/))` would be `false`
and we'd still try to send non-existend `sign?` message.
koic added a commit to koic/rubocop-ast that referenced this pull request Jul 16, 2025
This PR supports `RuboCop::AST::ComplexNode`.

The `complex` type is categorized as a `numeric` type,
so it should be handled transparently alongside `int`, `float`, and `rational`.

```ruby
int: :numeric,
float: :numeric,
rational: :numeric,
complex: :numeric,
```

https://github.com/rubocop/rubocop-ast/blob/v1.44.1/lib/rubocop/ast/node.rb#L106-L109

This eliminates the need for redundant branching, such as in rubocop/rubocop#14146.
koic added a commit to koic/rubocop-ast that referenced this pull request Jul 16, 2025
This PR supports `RuboCop::AST::ComplexNode`.

The `complex` type is categorized as a `numeric` type,
so it should be handled transparently alongside `int`, `float`, and `rational`.

```ruby
int: :numeric,
float: :numeric,
rational: :numeric,
complex: :numeric,
```

https://github.com/rubocop/rubocop-ast/blob/v1.44.1/lib/rubocop/ast/node.rb#L106-L109

This eliminates the need for redundant branching, such as in rubocop/rubocop#14146.
marcandre pushed a commit to rubocop/rubocop-ast that referenced this pull request Jul 16, 2025
This PR supports `RuboCop::AST::ComplexNode`.

The `complex` type is categorized as a `numeric` type,
so it should be handled transparently alongside `int`, `float`, and `rational`.

```ruby
int: :numeric,
float: :numeric,
rational: :numeric,
complex: :numeric,
```

https://github.com/rubocop/rubocop-ast/blob/v1.44.1/lib/rubocop/ast/node.rb#L106-L109

This eliminates the need for redundant branching, such as in rubocop/rubocop#14146.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants