mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
compile.c: zsuper keyword args
* compile.c (iseq_compile_each): pass keyword arguments to zsuper, with current values. [ruby-core:53114] [Bug #8008] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39627 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8a6898394c
commit
221f2a1d8a
3 changed files with 42 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
Thu Mar 7 14:21:37 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* compile.c (iseq_compile_each): pass keyword arguments to zsuper,
|
||||
with current values. [ruby-core:53114] [Bug #8008]
|
||||
|
||||
Thu Mar 7 12:53:47 2013 Eric Hodel <drbrain@segment7.net>
|
||||
|
||||
* lib/rubygems/commands/setup_command.rb: Install .pem files.
|
||||
|
|
16
compile.c
16
compile.c
|
@ -4472,6 +4472,22 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
|
|||
argc = post_len + post_start;
|
||||
}
|
||||
}
|
||||
|
||||
if (liseq->arg_keyword > 0) {
|
||||
int local_size = liseq->local_size;
|
||||
int idx = local_size - liseq->arg_keyword;
|
||||
argc++;
|
||||
ADD_INSN1(args, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
|
||||
ADD_INSN2(args, line, getlocal, INT2FIX(idx), INT2FIX(lvar_level));
|
||||
ADD_SEND (args, line, ID2SYM(rb_intern("dup")), INT2FIX(0));
|
||||
for (i = 0; i < liseq->arg_keywords; ++i) {
|
||||
ID id = liseq->arg_keyword_table[i];
|
||||
idx = local_size - get_local_var_idx(liseq, id);
|
||||
ADD_INSN1(args, line, putobject, ID2SYM(id));
|
||||
ADD_INSN2(args, line, getlocal, INT2FIX(idx), INT2FIX(lvar_level));
|
||||
}
|
||||
ADD_SEND(args, line, ID2SYM(id_core_hash_merge_ptr), INT2FIX(i * 2 + 1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ class TestSuper < Test::Unit::TestCase
|
|||
def double(a, b) [a,b] end
|
||||
def array(*a) a end
|
||||
def optional(a = 0) a end
|
||||
def keyword(**a) a end
|
||||
end
|
||||
class Single1 < Base
|
||||
def single(*) super end
|
||||
|
@ -50,6 +51,18 @@ class TestSuper < Test::Unit::TestCase
|
|||
class Optional5 < Base
|
||||
def array(a = 1, b = 2, *) super end
|
||||
end
|
||||
class Keyword1 < Base
|
||||
def keyword(foo: "keyword1") super end
|
||||
end
|
||||
class Keyword2 < Base
|
||||
def keyword(foo: "keyword2")
|
||||
foo = "changed1"
|
||||
x = super
|
||||
foo = "changed2"
|
||||
y = super
|
||||
[x, y]
|
||||
end
|
||||
end
|
||||
|
||||
def test_single1
|
||||
assert_equal(1, Single1.new.single(1))
|
||||
|
@ -112,6 +125,14 @@ class TestSuper < Test::Unit::TestCase
|
|||
assert_equal([9, 8], Optional5.new.array(9, 8))
|
||||
assert_equal([9, 8, 7], Optional5.new.array(9, 8, 7))
|
||||
end
|
||||
def test_keyword1
|
||||
assert_equal({foo: "keyword1"}, Keyword1.new.keyword)
|
||||
bug8008 = '[ruby-core:53114] [Bug #8008]'
|
||||
assert_equal({foo: bug8008}, Keyword1.new.keyword(foo: bug8008))
|
||||
end
|
||||
def test_keyword2
|
||||
assert_equal([{foo: "changed1"}, {foo: "changed2"}], Keyword2.new.keyword)
|
||||
end
|
||||
|
||||
class A
|
||||
def tt(aa)
|
||||
|
|
Loading…
Reference in a new issue