зеркало из https://github.com/github/ruby.git
compile.c: unnamed keyword rest check
* compile.c (iseq_set_arguments): set arg_keyword_check from nd_cflag, which is set by parser. internal ID is used for unnamed keyword rest argument, which should be separated from no keyword check. * iseq.c (rb_iseq_parameters): if no keyword check, keyword rest is present. * parse.y (new_args_tail_gen): set keywords check to nd_cflag, which equals to that keyword rest is not present. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44420 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
05ae2b730d
Коммит
27682eefa4
13
ChangeLog
13
ChangeLog
|
@ -1,3 +1,16 @@
|
|||
Wed Dec 25 22:44:14 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* compile.c (iseq_set_arguments): set arg_keyword_check from
|
||||
nd_cflag, which is set by parser. internal ID is used for
|
||||
unnamed keyword rest argument, which should be separated from no
|
||||
keyword check.
|
||||
|
||||
* iseq.c (rb_iseq_parameters): if no keyword check, keyword rest is
|
||||
present.
|
||||
|
||||
* parse.y (new_args_tail_gen): set keywords check to nd_cflag, which
|
||||
equals to that keyword rest is not present.
|
||||
|
||||
Wed Dec 25 22:32:19 2013 Zachary Scott <e@zzak.io>
|
||||
|
||||
* lib/abbrev.rb: [DOC] rdoc format patch by Giorgos Tsiftsis [Bug #9146]
|
||||
|
|
|
@ -1203,7 +1203,7 @@ iseq_set_arguments(rb_iseq_t *iseq, LINK_ANCHOR *optargs, NODE *node_args)
|
|||
node = node->nd_next;
|
||||
i += 1;
|
||||
}
|
||||
iseq->arg_keyword_check = (args->kw_rest_arg->nd_vid & ID_SCOPE_MASK) == ID_JUNK;
|
||||
iseq->arg_keyword_check = args->kw_rest_arg->nd_cflag;
|
||||
iseq->arg_keywords = i;
|
||||
iseq->arg_keyword_required = r;
|
||||
iseq->arg_keyword_table = ALLOC_N(ID, i);
|
||||
|
|
6
iseq.c
6
iseq.c
|
@ -2015,8 +2015,10 @@ rb_iseq_parameters(const rb_iseq_t *iseq, int is_proc)
|
|||
}
|
||||
rb_ary_push(args, a);
|
||||
}
|
||||
CONST_ID(keyrest, "keyrest");
|
||||
rb_ary_push(args, PARAM(iseq->arg_keyword, keyrest));
|
||||
if (!iseq->arg_keyword_check) {
|
||||
CONST_ID(keyrest, "keyrest");
|
||||
rb_ary_push(args, PARAM(iseq->arg_keyword, keyrest));
|
||||
}
|
||||
}
|
||||
if (iseq->arg_block != -1) {
|
||||
CONST_ID(block, "block");
|
||||
|
|
7
parse.y
7
parse.y
|
@ -9485,6 +9485,7 @@ new_args_tail_gen(struct parser_params *parser, NODE *k, ID kr, ID b)
|
|||
struct rb_args_info *args;
|
||||
NODE *kw_rest_arg = 0;
|
||||
NODE *node;
|
||||
int check = 0;
|
||||
|
||||
args = ALLOC(struct rb_args_info);
|
||||
MEMZERO(args, struct rb_args_info, 1);
|
||||
|
@ -9492,10 +9493,14 @@ new_args_tail_gen(struct parser_params *parser, NODE *k, ID kr, ID b)
|
|||
|
||||
args->block_arg = b;
|
||||
args->kw_args = k;
|
||||
if (k && !kr) kr = internal_id();
|
||||
if (k && !kr) {
|
||||
check = 1;
|
||||
kr = internal_id();
|
||||
}
|
||||
if (kr) {
|
||||
arg_var(kr);
|
||||
kw_rest_arg = NEW_DVAR(kr);
|
||||
kw_rest_arg->nd_cflag = check;
|
||||
}
|
||||
args->kw_rest_arg = kw_rest_arg;
|
||||
|
||||
|
|
|
@ -117,6 +117,15 @@ class TestKeywordArguments < Test::Unit::TestCase
|
|||
assert_equal([1, 2, [3, 4], 5, :key, {str: "bar"}, nil], f9(1, 2, 3, 4, 5, str: "bar"))
|
||||
end
|
||||
|
||||
def f10(a: 1, **)
|
||||
a
|
||||
end
|
||||
|
||||
def test_f10
|
||||
assert_equal(42, f10(a: 42))
|
||||
assert_equal(1, f10(b: 42))
|
||||
end
|
||||
|
||||
def test_method_parameters
|
||||
assert_equal([[:key, :str], [:key, :num]], method(:f1).parameters);
|
||||
assert_equal([[:req, :x], [:key, :str], [:key, :num]], method(:f2).parameters);
|
||||
|
|
Загрузка…
Ссылка в новой задаче