mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 04:24:23 +00:00
Fix inconsistent evaluation of keyword splat (#10959)
[Bug #20180] Backports #9624.
This commit is contained in:
parent
d0327a7224
commit
40251ed0df
@ -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;
|
||||
|
||||
@ -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])
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user