1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

separate hash literal and keyword arguments

* compile.c (compile_array_keyword_arg): separate keyword splat
  inside hash literal from argument list.

* parse.y (rparen): flag hash literal.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59572 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2017-08-11 01:27:24 +00:00
parent 28c02b9e08
commit 03a2862b98
3 changed files with 12 additions and 4 deletions

View file

@ -3053,7 +3053,7 @@ compile_array_keyword_arg(rb_iseq_t *iseq, LINK_ANCHOR *const ret,
assert(nd_type(node) == NODE_ARRAY);
if (!key_node) {
if (flag) *flag |= VM_CALL_KW_SPLAT;
if (flag && !root_node->nd_alen) *flag |= VM_CALL_KW_SPLAT;
return FALSE;
}
else if (nd_type(key_node) == NODE_LIT && RB_TYPE_P(key_node->nd_lit, T_SYMBOL)) {

13
node.c
View file

@ -545,9 +545,16 @@ dump_node(VALUE buf, VALUE indent, int comment, NODE *node)
break;
case NODE_HASH:
ANN("hash constructor");
ANN("format: { [nd_head] }");
ANN("example: { 1 => 2, 3 => 4 }");
if (!node->nd_alen) {
ANN("keyword arguments");
ANN("format: nd_head");
ANN("example: a: 1, b: 2");
}
else {
ANN("hash constructor");
ANN("format: { [nd_head] }");
ANN("example: { 1 => 2, 3 => 4 }");
}
LAST_NODE;
F_NODE(nd_head, "contents");
break;

View file

@ -2546,6 +2546,7 @@ primary : literal
{
/*%%%*/
$$ = new_hash($2);
$$->nd_alen = TRUE;
/*%
$$ = dispatch1(hash, escape_Qundef($2));
%*/