diff options
| author | Alan Wu <XrXr@users.noreply.github.com> | 2025-01-04 11:41:00 -0500 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2025-02-13 17:37:38 -0800 |
| commit | 73690b520da4c3ab680ddc477cacaeaeed75d558 (patch) | |
| tree | 5ea0279287fa18ae07b103107f719fd8417d88ab | |
| parent | cefa630bce3aea8317f09fe73c6439f67c42bb69 (diff) | |
YJIT: Fix crash when yielding keyword arguments
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.
| -rw-r--r-- | test/ruby/test_yjit.rb | 8 | ||||
| -rw-r--r-- | yjit/src/codegen.rs | 4 |
2 files changed, 10 insertions, 2 deletions
diff --git a/test/ruby/test_yjit.rb b/test/ruby/test_yjit.rb index 0c8ed691d0..0e476588f4 100644 --- a/test/ruby/test_yjit.rb +++ b/test/ruby/test_yjit.rb @@ -1742,6 +1742,14 @@ class TestYJIT < Test::Unit::TestCase 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 diff --git a/yjit/src/codegen.rs b/yjit/src/codegen.rs index 37ddbce0bb..d04da48c6a 100644 --- a/yjit/src/codegen.rs +++ b/yjit/src/codegen.rs @@ -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; } } |
