#15663·rubocop

Style/RedundantFetchBlock autocorrect adds an argument to splatted fetch calls

Author: mehuljariwalaCreated Sep 5, 2026Updated Sep 5, 2026

Before submitting

  • I searched existing issues and PRs for this splatted-argument case.
  • Reproduced against current master (RuboCop 1.90.0).

Issue type

Incorrect autocorrect

Cop name

Style/RedundantFetchBlock

Steps to reproduce

Run rubocop --only Style/RedundantFetchBlock -A on:

ruby
args = [:missing, :default]
hash = {}
hash.fetch(*args) { 5 }

The original call returns 5 (Ruby warns that the block supersedes the default argument). RuboCop replaces the final line with hash.fetch(*args, 5), which raises ArgumentError: wrong number of arguments (given 3, expected 1..2).

The same correction is offered for hash&.fetch(*args) { 5 }.

Expected behavior

Leave a splatted argument unchanged when its runtime arity is unknown. A single splat AST node does not guarantee that fetch receives only a key.

Actual behavior

The cop treats the splat as one argument and appends another default argument. Two new no-offense specs fail on current master and pass when the node matcher excludes splats.

RuboCop version

1.90.0 (using Parser 3.3.12.0, rubocop-ast 1.50.0, analyzing as Ruby 2.7, running on ruby 4.0.6) +Rubydex [arm64-darwin25]
  - rubocop-performance 1.27.0
  - rubocop-rake 0.7.1
  - rubocop-rspec 3.10.2

Prepared with OpenAI Codex assistance; the runtime behavior and regression tests were executed locally.