Skip to content

Commit 927928b

Browse files
committed
[PRISM] Fix anonymous keyword arguments
Fixes ruby/prism#2256.
1 parent 4220bdb commit 927928b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

prism_compile.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
#define PM_SPECIAL_CONSTANT_FLAG ((pm_constant_id_t)(1 << 31))
6161
#define PM_CONSTANT_AND ((pm_constant_id_t)(idAnd | PM_SPECIAL_CONSTANT_FLAG))
6262
#define PM_CONSTANT_MULT ((pm_constant_id_t)(idMULT | PM_SPECIAL_CONSTANT_FLAG))
63+
#define PM_CONSTANT_POW ((pm_constant_id_t)(idPow | PM_SPECIAL_CONSTANT_FLAG))
6364

6465
rb_iseq_t *
6566
pm_iseq_new_with_opt(pm_scope_node_t *scope_node, pm_parser_t *parser, VALUE name, VALUE path, VALUE realpath,
@@ -1025,7 +1026,13 @@ pm_arg_compile_keyword_hash_node(pm_keyword_hash_node_t *node, rb_iseq_t *iseq,
10251026
}
10261027

10271028
pm_assoc_splat_node_t *assoc_splat = (pm_assoc_splat_node_t *)cur_node;
1028-
PM_COMPILE(assoc_splat->value);
1029+
if (assoc_splat->value != NULL) {
1030+
PM_COMPILE(assoc_splat->value);
1031+
}
1032+
else {
1033+
pm_local_index_t index = pm_lookup_local_index(iseq, scope_node, PM_CONSTANT_POW, 0);
1034+
ADD_GETLOCAL(ret, &dummy_line_node, index.index, index.level);
1035+
}
10291036

10301037
if (len > 1) {
10311038
ADD_SEND(ret, &dummy_line_node, id_core_hash_merge_kwd, INT2FIX(2));
@@ -6589,7 +6596,8 @@ pm_compile_node(rb_iseq_t *iseq, const pm_node_t *node, LINK_ANCHOR *const ret,
65896596
pm_insert_local_index(constant_id, local_index, index_lookup_table, local_table_for_iseq, scope_node);
65906597
}
65916598
else {
6592-
local_table_for_iseq->ids[local_index] = idPow;
6599+
local_table_for_iseq->ids[local_index] = PM_CONSTANT_POW;
6600+
st_insert(index_lookup_table, PM_CONSTANT_POW, local_index);
65936601
}
65946602
local_index++;
65956603
break;

test/ruby/test_compile_prism.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -825,6 +825,14 @@ def test_AssocSplatNode
825825
assert_prism_eval("foo = { a: 1 }; { **foo }")
826826
assert_prism_eval("foo = { a: 1 }; bar = foo; { **foo, b: 2, **bar, c: 3 }")
827827
assert_prism_eval("foo = { a: 1 }; { b: 2, **foo, c: 3}")
828+
829+
# Test anonymous AssocSplatNode
830+
assert_prism_eval(<<~RUBY)
831+
o = Object.new
832+
def o.bar(**) = Hash(**)
833+
834+
o.bar(hello: "world")
835+
RUBY
828836
end
829837

830838
def test_HashNode

0 commit comments

Comments
 (0)