KEMBAR78
Error in Style/ArrayIntersect when checking call to intersection with an implicit self receiver · Issue #14572 · rubocop/rubocop · GitHub
Skip to content

Error in Style/ArrayIntersect when checking call to intersection with an implicit self receiver #14572

@reidab

Description

@reidab

The Style/ArrayIntersect seems to blow up when checking code without an explicit receiver for the intersection method, in this case on a method that's implemented on an Array subclass.


Expected behavior

No error.

Actual behavior

An error occurred:

An error occurred while Style/ArrayIntersect cop was inspecting /Users/reidab/code/thedyrt/api/app/lib/fail.rb:8:5.
/Users/reidab/.rbenv/versions/3.3.9/lib/ruby/gems/3.3.0/gems/rubocop-1.81.1/lib/rubocop/cop/style/array_intersect.rb:148:in `on_send': undefined method `source' for nil (NoMethodError)

          replacement = "#{bang}#{receiver.source}#{dot}intersect?(#{argument.source})"
                                          ^^^^^^^

Steps to reproduce the problem

Attempt to check something like this

class SpecialArray < Array
  def intersection(other)
    # some custom intersection logic
    self & other
  end

  def intersect?(other)
    !intersection(other).empty?
  end
end

RuboCop version

1.81.1 (using Parser 3.3.9.0, Prism 1.5.1, rubocop-ast 1.47.1, analyzing as Ruby 3.3, running on ruby 3.3.9) [arm64-darwin25]
  - rubocop-factory_bot 2.27.1
  - rubocop-performance 1.26.0
  - rubocop-rails 2.33.3
  - rubocop-rake 0.7.1
  - rubocop-rspec 3.7.0
  - rubocop-rspec_rails 2.31.0
  - rubocop-sorbet 0.10.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions