Fix inconsistent evaluation of keyword splat (#10959)

[Bug #20180]

Backports #9624.
This commit is contained in:
Peter Zhu 2024-06-10 19:05:58 -04:00 committed by GitHub
parent d0327a7224
commit 40251ed0df
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 21 additions and 1 deletions

View File

@ -4826,7 +4826,12 @@ compile_array_1(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node)
}
else {
CHECK(COMPILE_(ret, "array element", node, FALSE));
ADD_INSN1(ret, node, newarray, INT2FIX(1));
if (keyword_node_p(node)) {
ADD_INSN1(ret, node, newarraykwsplat, INT2FIX(1));
}
else {
ADD_INSN1(ret, node, newarray, INT2FIX(1));
}
}
return 1;

View File

@ -233,6 +233,7 @@ class TestSyntax < Test::Unit::TestCase
def test_array_kwsplat_hash
kw = {}
h = {a: 1}
a = []
assert_equal([], [**{}])
assert_equal([], [**kw])
assert_equal([h], [**h])
@ -247,6 +248,20 @@ class TestSyntax < Test::Unit::TestCase
assert_equal([1, kw], [1, kw])
assert_equal([1, h], [1, h])
assert_equal([], [*a, **{}])
assert_equal([], [*a, **kw])
assert_equal([h], [*a, **h])
assert_equal([{}], [*a, {}])
assert_equal([kw], [*a, kw])
assert_equal([h], [*a, h])
assert_equal([1], [1, *a, **{}])
assert_equal([1], [1, *a, **kw])
assert_equal([1, h], [1, *a, **h])
assert_equal([1, {}], [1, *a, {}])
assert_equal([1, kw], [1, *a, kw])
assert_equal([1, h], [1, *a, h])
assert_equal([], [**kw, **kw])
assert_equal([], [**kw, **{}, **kw])
assert_equal([1], [1, **kw, **{}, **kw])