Skip to content

Performance/RedundantBlockCall produces invalid code #448

Closed
@TastyPi

Description

@TastyPi
class RubocopIssue
  def self.around(&around_block)
    define_method(:around) do |&test_block|
      around_block.call { super(&test_block) }
    end
  end
end

gets turned into

class RubocopIssue
  def self.around(&around_block)
    define_method(:around) do |&test_block|
      yield { super(&test_block) }
    end
  end
end

which is a syntax error:

syntax error, unexpected '{' (SyntaxError)
      yield { super(&test_block) }
            ^

Expected behavior

rubocop-performance should only produce valid code

Actual behavior

rubocop-performance produced a syntax error

Steps to reproduce the problem

Run rubocop-performance on the example above

RuboCop version

1.62.1 (using Parser 3.3.0.5, rubocop-ast 1.31.2, running on ruby 3.2.2) +server [x86_64-linux]

  • rubocop-capybara 2.20.0
  • rubocop-i18n 1.14.4
  • rubocop-minitest 0.35.0
  • rubocop-performance 1.20.2
  • rubocop-rails 2.24.0
  • rubocop-rake 0.6.0
  • rubocop-thread_safety 0.5.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions