Skip to content

Fixes #6564. Passing **kw to def with no args should work#6623

Merged
enebo merged 4 commits intojruby:masterfrom
enebo:fix_kwrest_args
Mar 24, 2021
Merged

Fixes #6564. Passing **kw to def with no args should work#6623
enebo merged 4 commits intojruby:masterfrom
enebo:fix_kwrest_args

Conversation

@enebo
Copy link
Member

@enebo enebo commented Mar 17, 2021

This fixes the problem reported in #6564.

It introduces a problem by not passing:

def bar(a)
  puts "BAR #{a}"
end

a = {}
bar(**a)

In Ruby 2.6 this will receive the empty hash as parameter 'a' in 'bar'. In Ruby 3.0 this will be an arity mismatch. I opted to break 2.6 compatibility because bar(**{}, **{}) will arity error (which is inconsistent) and 3.0 corrects this inconsistency. I am comfortable with encouraging people to not expect this behaviour. Anyone doing this will need to update their library/application anyways.

The mechanics of the fix is to look at any **a passed at the callsite and if it is empty we will not pass it along. If it is not empty we do. This is option number 2 in #6564. Not ideal in that we add some more interpreted logic for callsites with **a and it will generate more bytecode as well. It is ideal in that it did not require us to rewrite all keyword argument processing. Later work (like the other two options discussed in the issue) can eventually end up removing this.

As a note of other futures:

  1. if_else in IRBuilder probably can be reused as a helper in other places.
  2. I am thinking about making a new instruction java_call which will allow arbitrary Java calls but can then probably eliminate multiple RuntimeHelperInstr. This is a potentially a big hole in wanting to display against receivers and making static calls. The operations will be the same as RuntimeHelperInstr.

@enebo enebo added this to the JRuby 9.3.0.0 milestone Mar 17, 2021
and the kwargs rest check was duplicated...no more.
@enebo enebo changed the title Fixes #6564 Fixes #6564. Passing **kw to def with no args should work Mar 19, 2021
@enebo enebo merged commit 2b7236c into jruby:master Mar 24, 2021
@enebo enebo deleted the fix_kwrest_args branch March 4, 2025 18:33
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.

1 participant