Skip to content

Crash in Style/ExplicitBlockArgument #8825

@ghiculescu

Description

@ghiculescu

Expected behavior

Style/ExplicitBlockArgument not to crash on the code below.

Actual behavior

Style/ExplicitBlockArgument is crashing on a file that just contains this code:

if @foo
  render "partial", prop: @bar do
    yield
  end
end

Here's the backtrace:

An error occurred while Style/ExplicitBlockArgument cop was inspecting test.rb:3:4.
undefined method `arguments?' for nil:NilClass
/Users/alex/.rvm/gems/ruby-2.7.1/gems/rubocop-0.92.0/lib/rubocop/cop/style/explicit_block_argument.rb:80:in `add_block_argument'
/Users/alex/.rvm/gems/ruby-2.7.1/gems/rubocop-0.92.0/lib/rubocop/cop/style/explicit_block_argument.rb:66:in `block (2 levels) in on_yield'
/Users/alex/.rvm/gems/ruby-2.7.1/gems/rubocop-0.92.0/lib/rubocop/cop/base.rb:333:in `correct'
/Users/alex/.rvm/gems/ruby-2.7.1/gems/rubocop-0.92.0/lib/rubocop/cop/base.rb:126:in `add_offense'
/Users/alex/.rvm/gems/ruby-2.7.1/gems/rubocop-0.92.0/lib/rubocop/cop/style/explicit_block_argument.rb:60:in `block in on_yield'
/Users/alex/.rvm/gems/ruby-2.7.1/gems/rubocop-0.92.0/lib/rubocop/cop/style/explicit_block_argument.rb:57:in `yielding_block?'
/Users/alex/.rvm/gems/ruby-2.7.1/gems/rubocop-0.92.0/lib/rubocop/cop/style/explicit_block_argument.rb:57:in `on_yield'
/Users/alex/.rvm/gems/ruby-2.7.1/gems/rubocop-0.92.0/lib/rubocop/cop/commissioner.rb:99:in `block (2 levels) in trigger_responding_cops'
/Users/alex/.rvm/gems/ruby-2.7.1/gems/rubocop-0.92.0/lib/rubocop/cop/commissioner.rb:152:in `with_cop_error_handling'
/Users/alex/.rvm/gems/ruby-2.7.1/gems/rubocop-0.92.0/lib/rubocop/cop/commissioner.rb:98:in `block in trigger_responding_cops'

The actual error came up when running haml_lint. But I think it's a rubocop error, because you can replicate in a ruby file.

For the record, this works fine:

def method
  if @foo
    render("partial", prop: @bar) do
      yield
    end
  end
end

RuboCop version

$ [bundle exec] rubocop -V
0.92.0 (using Parser 2.7.1.5, rubocop-ast 0.7.1, running on ruby 2.7.1 x86_64-darwin19)

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy