From f4c52b483cb4794e3e0e526a084cdbd32da8086c Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 9 Apr 2013 06:26:15 +0000 Subject: compile.c: append keyword hash to splat * compile.c (iseq_compile_each): append keyword hash to argument array to splat if needed. [ruby-core:54094] [Bug #8236] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40205 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ compile.c | 5 +++++ test/ruby/test_keyword.rb | 21 +++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/ChangeLog b/ChangeLog index 54df69600f..a897e661b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Apr 9 15:26:12 2013 Nobuyoshi Nakada + + * compile.c (iseq_compile_each): append keyword hash to argument array + to splat if needed. [ruby-core:54094] [Bug #8236] + Tue Apr 9 10:02:39 2013 Nobuyoshi Nakada * lib/mkmf.rb (timestamp_file): gather timestamp files in one diff --git a/compile.c b/compile.c index 65d01220e7..1f5915cd0d 100644 --- a/compile.c +++ b/compile.c @@ -4499,6 +4499,11 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) ADD_INSN2(args, line, getlocal, INT2FIX(idx), INT2FIX(lvar_level)); } ADD_SEND(args, line, ID2SYM(id_core_hash_merge_ptr), INT2FIX(i * 2 + 1)); + if (liseq->arg_rest != -1) { + ADD_INSN1(args, line, newarray, INT2FIX(1)); + ADD_INSN (args, line, concatarray); + --argc; + } } } } diff --git a/test/ruby/test_keyword.rb b/test/ruby/test_keyword.rb index dc20c6d7fd..c9a9ed0a07 100644 --- a/test/ruby/test_keyword.rb +++ b/test/ruby/test_keyword.rb @@ -327,4 +327,25 @@ class TestKeywordArguments < Test::Unit::TestCase assert_raise(ArgumentError, bug8139) {b.call(c: bug8139)} assert_raise(ArgumentError, bug8139) {b.call} end + + def test_super_with_keyword + bug8236 = '[ruby-core:54094] [Bug #8236]' + base = Class.new do + def foo(*args) + args + end + end + a = Class.new(base) do + def foo(arg, bar: 'x') + super + end + end + b = Class.new(base) do + def foo(*args, bar: 'x') + super + end + end + assert_equal([42, {:bar=>"x"}], a.new.foo(42), bug8236) + assert_equal([42, {:bar=>"x"}], b.new.foo(42), bug8236) + end end -- cgit v1.2.3