Skip to content

Fix Ruby 3.3 SyntaxError caused by anonymous keyword argument forwarding#215

Merged
mperham merged 1 commit intomperham:mainfrom
cfe86:fix-anonymous-keyword-rest-parameter-is-also-used-within-block-syntax-error
Dec 21, 2025
Merged

Fix Ruby 3.3 SyntaxError caused by anonymous keyword argument forwarding#215
mperham merged 1 commit intomperham:mainfrom
cfe86:fix-anonymous-keyword-rest-parameter-is-also-used-within-block-syntax-error

Conversation

@cfe86
Copy link
Contributor

@cfe86 cfe86 commented Dec 20, 2025

Summary

Ruby 3.3 raises a SyntaxError when anonymous keyword rest parameters (**) are forwarded.
connection_pool was still forwarding anonymous keyword arguments in several places, which causes the gem to fail on Ruby 3.3.

This PR updates those method signatures to use named keyword rest parameters (**kwargs) and forwards them explicitly.

Impact

  • No behavior changes
  • No public API changes
  • Ruby 3.0–3.3 compatible
  • Fixes a parse-time SyntaxError on Ruby 3.3

Testing

Verified locally on Ruby 3.3. Before this change, loading bundle exec rake assets:precompile raised errors such as:

.../connection_pool-3.0.2/lib/connection_pool.rb:65: anonymous keyword rest parameter is also used within block (SyntaxError)

After the fix, the code compiles and loads correctly.

@mperham
Copy link
Owner

mperham commented Dec 20, 2025

Why was CI passing with 3.3?

@cfe86
Copy link
Contributor Author

cfe86 commented Dec 20, 2025

@mperham honestly I’m not entirely sure why CI didn’t catch this. I ran into it while updating factory_bot 6.5.5 → 6.5.6, which indirectly upgraded connection_pool (2.5.5 → 3.0.2), and immediately hit:

.../connection_pool-3.0.2/lib/connection_pool.rb:65: anonymous keyword rest parameter is also used within block (SyntaxError)

After digging a bit, it turns out Ruby 3.3 raises a parse-time SyntaxError when anonymous keyword rest parameters (**) are forwarded.

My best guess is that the affected methods/files are lazily loaded, and the Ruby 3.3 CI doesn’t end up requiring them, so the file never gets parsed in CI. I didn’t verify the exact test coverage, but locally the error reproduces reliably as soon as the file is required.

@mperham mperham merged commit 8ba2715 into mperham:main Dec 21, 2025
6 checks passed
@cfe86
Copy link
Contributor Author

cfe86 commented Dec 21, 2025

@mperham thanks for merging! Did a few more tests. For what it's worth. Seems to be a ruby 3.3.0 only problem: https://bugs.ruby-lang.org/issues/20090

Example

def test(**)
  [1].each do
    puts(**)
  end
end

test(a: 1)

def bar(*)
  [1].each do
    puts(*)
  end
end

bar('1')

Ruby 3.3.0:

ruby test.rb
test.rb: 
test.rb:3: anonymous keyword rest parameter is also used within block (SyntaxError)
test.rb:11: anonymous rest parameter is also used within block

Ruby 3.3.1

ruby test.rb
{:a=>1}
1

@mperham
Copy link
Owner

mperham commented Dec 21, 2025

That explains it, thanks.

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