summaryrefslogtreecommitdiff
path: root/parse.y
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-17 13:25:14 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-17 13:25:14 +0000
commit6170db409b52e1048f68fe6a883f40e0ab72be62 (patch)
tree76ee0353d3fedd90b5427fa32789219649885499 /parse.y
parentb66b645230542bf2a1a782d80a7426947a9a273f (diff)
merge revision(s) 49193: [Backport #10719]
* parse.y (assocs, assoc): eliminate splatting empty literal hashes. [ruby-core:67446] [Bug #10719] * compile.c (compile_array_): supprt splatted hash in hash type. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@49302 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'parse.y')
-rw-r--r--parse.y36
1 files changed, 23 insertions, 13 deletions
diff --git a/parse.y b/parse.y
index fe73627fa0..b8a7c6f864 100644
--- a/parse.y
+++ b/parse.y
@@ -2396,7 +2396,7 @@ aref_args : none
| args ',' assocs trailer
{
/*%%%*/
- $$ = arg_append($1, new_hash($3));
+ $$ = $3 ? arg_append($1, new_hash($3)) : $1;
/*%
$$ = arg_add_assocs($1, $3);
%*/
@@ -2404,7 +2404,7 @@ aref_args : none
| assocs trailer
{
/*%%%*/
- $$ = NEW_LIST(new_hash($1));
+ $$ = $1 ? NEW_LIST(new_hash($1)) : 0;
/*%
$$ = arg_add_assocs(arg_new(), $1);
%*/
@@ -2434,7 +2434,7 @@ opt_call_args : none
| args ',' assocs ','
{
/*%%%*/
- $$ = arg_append($1, new_hash($3));
+ $$ = $3 ? arg_append($1, new_hash($3)) : $1;
/*%
$$ = arg_add_assocs($1, $3);
%*/
@@ -2442,7 +2442,7 @@ opt_call_args : none
| assocs ','
{
/*%%%*/
- $$ = NEW_LIST(new_hash($1));
+ $$ = $1 ? NEW_LIST(new_hash($1)) : 0;
/*%
$$ = arg_add_assocs(arg_new(), $1);
%*/
@@ -2469,7 +2469,7 @@ call_args : command
| assocs opt_block_arg
{
/*%%%*/
- $$ = NEW_LIST(new_hash($1));
+ $$ = NEW_LIST($1 ? new_hash($1) : 0);
$$ = arg_blk_pass($$, $2);
/*%
$$ = arg_add_assocs(arg_new(), $1);
@@ -2479,7 +2479,7 @@ call_args : command
| args ',' assocs opt_block_arg
{
/*%%%*/
- $$ = arg_append($1, new_hash($3));
+ $$ = $3 ? arg_append($1, new_hash($3)) : $1;
$$ = arg_blk_pass($$, $4);
/*%
$$ = arg_add_optblock(arg_add_assocs($1, $3), $4);
@@ -5030,13 +5030,19 @@ assocs : assoc
/*%%%*/
NODE *assocs = $1;
NODE *tail = $3;
- if (assocs->nd_head &&
- !tail->nd_head && nd_type(tail->nd_next) == NODE_ARRAY &&
- nd_type(tail->nd_next->nd_head) == NODE_HASH) {
- /* DSTAR */
- tail = tail->nd_next->nd_head->nd_head;
+ if (!assocs) {
+ assocs = tail;
}
- $$ = list_concat(assocs, tail);
+ else if (tail) {
+ if (assocs->nd_head &&
+ !tail->nd_head && nd_type(tail->nd_next) == NODE_ARRAY &&
+ nd_type(tail->nd_next->nd_head) == NODE_HASH) {
+ /* DSTAR */
+ tail = tail->nd_next->nd_head->nd_head;
+ }
+ assocs = list_concat(assocs, tail);
+ }
+ $$ = assocs;
/*%
$$ = rb_ary_push($1, $3);
%*/
@@ -5074,7 +5080,11 @@ assoc : arg_value tASSOC arg_value
| tDSTAR arg_value
{
/*%%%*/
- $$ = list_append(NEW_LIST(0), $2);
+ if (nd_type($2) == NODE_HASH &&
+ !($2->nd_head && $2->nd_head->nd_alen))
+ $$ = 0;
+ else
+ $$ = list_append(NEW_LIST(0), $2);
/*%
$$ = dispatch1(assoc_splat, $2);
%*/