From f560609d66502101264706877577220e3ebf5a38 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Mon, 2 Sep 2019 08:21:30 -0700 Subject: Merge pull request #2418 from jeremyevans/array-empty-kwsplat Ignore empty keyword splats in arrays --- compile.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index 774acedf99..ad9998250d 100644 --- a/compile.c +++ b/compile.c @@ -4025,8 +4025,21 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro else { if (!popped || kw) { switch (type) { - case COMPILE_ARRAY_TYPE_ARRAY: - ADD_INSN1(anchor, line, newarray, INT2FIX(i)); + case COMPILE_ARRAY_TYPE_ARRAY: { + const NODE *check_node = node_root; + + /* Find last node in array, and if it is a keyword argument, then set + flag to check and remove empty keyword arguments hash from array */ + while(check_node->nd_next) { + check_node = check_node->nd_next; + } + if (nd_type(check_node->nd_head) == NODE_HASH && check_node->nd_head->nd_brace == 0) { + ADD_INSN1(anchor, line, newarraykwsplat, INT2FIX(i)); + } + else { + ADD_INSN1(anchor, line, newarray, INT2FIX(i)); + } + if (first) { first = 0; @@ -4037,6 +4050,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro APPEND_LIST(ret, anchor); break; + } case COMPILE_ARRAY_TYPE_HASH: if (i > 0) { if (first) { -- cgit v1.2.3