Skip to content

Commit

Permalink
YJIT: Fix crash when yielding keyword arguments
Browse files Browse the repository at this point in the history
Previously, the code for dropping surplus arguments when yielding
into blocks erroneously attempted to drop keyword arguments when there
is in fact no surplus arguments. Fix the condition and test that
supplying the exact number of keyword arguments as require compiles
without fallback.
  • Loading branch information
XrXr committed Jan 4, 2025
1 parent 37356b7 commit c71addc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions test/ruby/test_yjit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1742,6 +1742,14 @@ def each
RUBY
end

def test_yield_kwargs
assert_compiles(<<~RUBY, result: 3, no_send_fallbacks: true)
def req2kws = yield a: 1, b: 2
req2kws { |a:, b:| a + b }
RUBY
end

private

def code_gc_helpers
Expand Down
4 changes: 2 additions & 2 deletions yjit/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8011,14 +8011,14 @@ fn gen_send_iseq(

// Pop surplus positional arguments when yielding
if arg_setup_block {
let extras = argc - required_num - opt_num;
let extras = argc - required_num - opt_num - kw_arg_num;
if extras > 0 {
// Checked earlier. If there are keyword args, then
// the positional arguments are not at the stack top.
assert_eq!(0, kw_arg_num);

asm.stack_pop(extras as usize);
argc = required_num + opt_num;
argc = required_num + opt_num + kw_arg_num;
}
}

Expand Down

0 comments on commit c71addc

Please sign in to comment.