From 03a2862b983c7dd6c1b9fd016154191213750ed3 Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 11 Aug 2017 01:27:24 +0000 Subject: [PATCH] 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 --- compile.c | 2 +- node.c | 13 ++++++++++--- parse.y | 1 + 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/compile.c b/compile.c index 99e00b4e6a..170bb99776 100644 --- a/compile.c +++ b/compile.c @@ -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)) { diff --git a/node.c b/node.c index f6d551a106..0222a19af1 100644 --- a/node.c +++ b/node.c @@ -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; diff --git a/parse.y b/parse.y index c12b80cc06..0fb5605345 100644 --- a/parse.y +++ b/parse.y @@ -2546,6 +2546,7 @@ primary : literal { /*%%%*/ $$ = new_hash($2); + $$->nd_alen = TRUE; /*% $$ = dispatch1(hash, escape_Qundef($2)); %*/