зеркало из https://github.com/github/ruby.git
Add keyrest to ruby2_keywords parameters [Bug #18011]
This commit is contained in:
Родитель
731315bf55
Коммит
4c3140d60f
13
iseq.c
13
iseq.c
|
@ -3116,9 +3116,18 @@ rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
|
|||
rb_ary_push(args, a);
|
||||
}
|
||||
}
|
||||
if (body->param.flags.has_kwrest) {
|
||||
if (body->param.flags.has_kwrest || body->param.flags.ruby2_keywords) {
|
||||
ID param;
|
||||
CONST_ID(keyrest, "keyrest");
|
||||
rb_ary_push(args, PARAM(keyword->rest_start, keyrest));
|
||||
PARAM_TYPE(keyrest);
|
||||
if (body->param.flags.has_kwrest &&
|
||||
rb_id2str(param = PARAM_ID(keyword->rest_start))) {
|
||||
rb_ary_push(a, ID2SYM(param));
|
||||
}
|
||||
else if (body->param.flags.ruby2_keywords) {
|
||||
rb_ary_push(a, ID2SYM(idPow));
|
||||
}
|
||||
rb_ary_push(args, a);
|
||||
}
|
||||
if (body->param.flags.has_block) {
|
||||
CONST_ID(block, "block");
|
||||
|
|
7
proc.c
7
proc.c
|
@ -3097,7 +3097,12 @@ method_inspect(VALUE method)
|
|||
}
|
||||
}
|
||||
else if (kind == keyrest) {
|
||||
rb_str_catf(str, "**%"PRIsVALUE, name);
|
||||
if (name != ID2SYM(idPow)) {
|
||||
rb_str_catf(str, "**%"PRIsVALUE, name);
|
||||
}
|
||||
else if (i > 0) {
|
||||
rb_str_set_len(str, RSTRING_LEN(str) - 2);
|
||||
}
|
||||
}
|
||||
else if (kind == block) {
|
||||
if (name == ID2SYM('&')) {
|
||||
|
|
|
@ -578,7 +578,7 @@ class TestMethod < Test::Unit::TestCase
|
|||
assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:keyreq, :e], [:key, :f], [:keyrest, :o]], method(:mk8).parameters)
|
||||
assert_equal([[:nokey]], method(:mnk).parameters)
|
||||
# pending
|
||||
assert_equal([[:rest, :*], [:block, :&]], method(:mf).parameters)
|
||||
assert_equal([[:rest, :*], [:keyrest, :**], [:block, :&]], method(:mf).parameters)
|
||||
end
|
||||
|
||||
def test_unbound_parameters
|
||||
|
@ -604,7 +604,7 @@ class TestMethod < Test::Unit::TestCase
|
|||
assert_equal([[:req, :a], [:opt, :b], [:rest, :c], [:req, :d], [:keyreq, :e], [:key, :f], [:keyrest, :o]], self.class.instance_method(:mk8).parameters)
|
||||
assert_equal([[:nokey]], self.class.instance_method(:mnk).parameters)
|
||||
# pending
|
||||
assert_equal([[:rest, :*], [:block, :&]], self.class.instance_method(:mf).parameters)
|
||||
assert_equal([[:rest, :*], [:keyrest, :**], [:block, :&]], self.class.instance_method(:mf).parameters)
|
||||
end
|
||||
|
||||
def test_bmethod_bound_parameters
|
||||
|
|
|
@ -1638,7 +1638,8 @@ eom
|
|||
assert_equal(-1, obj.method(:foo).arity)
|
||||
parameters = obj.method(:foo).parameters
|
||||
assert_equal(:rest, parameters.dig(0, 0))
|
||||
assert_equal(:block, parameters.dig(1, 0))
|
||||
assert_equal(:keyrest, parameters.dig(1, 0))
|
||||
assert_equal(:block, parameters.dig(2, 0))
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче