summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog7
-rw-r--r--compile.c11
-rw-r--r--parse.y36
-rw-r--r--test/ruby/test_syntax.rb7
4 files changed, 44 insertions, 17 deletions
diff --git a/ChangeLog b/ChangeLog
index 2309ca26ec..40cd8b747a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Fri Jan 9 11:13:01 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * parse.y (assocs, assoc): eliminate splatting empty literal
+ hashes. [ruby-core:67446] [Bug #10719]
+
+ * compile.c (compile_array_): supprt splatted hash in hash type.
+
Fri Jan 9 10:57:09 2015 Vit Ondruch <vondruch@redhat.com>
* configure.in (RUBY_SETJMP_TYPE): Remove superfluous semicolon
diff --git a/compile.c b/compile.c
index d69dab6f4b..b573168b85 100644
--- a/compile.c
+++ b/compile.c
@@ -2467,11 +2467,14 @@ compile_array_(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE* node_root,
rb_bug("compile_array: This node is not NODE_ARRAY, but %s", ruby_node_name(nd_type(node)));
}
- if (type == COMPILE_ARRAY_TYPE_HASH && !node->nd_head) {
- opt_p = 0;
+ if (type != COMPILE_ARRAY_TYPE_ARRAY && !node->nd_head) {
kw = node->nd_next;
- node = kw->nd_next;
- kw = kw->nd_head;
+ node = 0;
+ if (kw) {
+ opt_p = 0;
+ node = kw->nd_next;
+ kw = kw->nd_head;
+ }
break;
}
if (opt_p && nd_type(node->nd_head) != NODE_LIT) {
diff --git a/parse.y b/parse.y
index 1a12001dec..4821e08b1e 100644
--- a/parse.y
+++ b/parse.y
@@ -2405,7 +2405,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);
%*/
@@ -2413,7 +2413,7 @@ aref_args : none
| assocs trailer
{
/*%%%*/
- $$ = NEW_LIST(new_hash($1));
+ $$ = $1 ? NEW_LIST(new_hash($1)) : 0;
/*%
$$ = arg_add_assocs(arg_new(), $1);
%*/
@@ -2443,7 +2443,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);
%*/
@@ -2451,7 +2451,7 @@ opt_call_args : none
| assocs ','
{
/*%%%*/
- $$ = NEW_LIST(new_hash($1));
+ $$ = $1 ? NEW_LIST(new_hash($1)) : 0;
/*%
$$ = arg_add_assocs(arg_new(), $1);
%*/
@@ -2478,7 +2478,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);
@@ -2488,7 +2488,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);
@@ -5039,13 +5039,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);
%*/
@@ -5083,7 +5089,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);
%*/
diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb
index eb63e3dfa7..86c1090c30 100644
--- a/test/ruby/test_syntax.rb
+++ b/test/ruby/test_syntax.rb
@@ -136,6 +136,13 @@ class TestSyntax < Test::Unit::TestCase
assert_equal([1, 2], a, bug10315)
end
+ def test_keyword_empty_splat
+ assert_separately([], <<-'end;')
+ bug10719 = '[ruby-core:67446] [Bug #10719]'
+ assert_valid_syntax("foo(a: 1, **{})", bug10719)
+ end;
+ end
+
def test_keyword_self_reference
bug9593 = '[ruby-core:61299] [Bug #9593]'
o = Object.new