summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-19 00:45:55 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-19 00:45:55 +0000
commit5c3f9641c0475b6ec2e26c8e6df921abf47856ca (patch)
treeb018ad01a51abbec91a4e65fc4ded887236b9c49
parent494b3aeaea5cad15ead14853ec7eab1833651642 (diff)
compile.c: side effect in splat
* compile.c (compile_array): splat which may have side effects should be compiled even if the result will be popped. [ruby-core:84340] [Bug #14201] From: Nobuyoshi Nakada <nobu@ruby-lang.org> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61329 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--compile.c7
-rw-r--r--test/ruby/test_optimization.rb6
2 files changed, 11 insertions, 2 deletions
diff --git a/compile.c b/compile.c
index 37f024b3cc..addf3be596 100644
--- a/compile.c
+++ b/compile.c
@@ -3619,7 +3619,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro
}
}
else {
- if (!popped) {
+ if (!popped || kw) {
switch (type) {
case COMPILE_ARRAY_TYPE_ARRAY:
ADD_INSN1(anchor, line, newarray, INT2FIX(i));
@@ -3660,6 +3660,9 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro
APPEND_LIST(ret, anchor);
break;
}
+ if (popped) {
+ ADD_INSN(ret, line, pop);
+ }
}
else {
/* popped */
@@ -6268,7 +6271,7 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *node, in
}
case NODE_HASH:{
DECL_ANCHOR(list);
- int type = node->nd_head ? nd_type(node->nd_head) : NODE_ZARRAY;
+ enum node_type type = node->nd_head ? nd_type(node->nd_head) : NODE_ZARRAY;
INIT_ANCHOR(list);
switch (type) {
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index 0d049c3b88..160f439b36 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -702,4 +702,10 @@ class TestRubyOptimization < Test::Unit::TestCase
}
END
end
+
+ def test_side_effect_in_popped_splat
+ bug = '[ruby-core:84340] [Bug #14201]'
+ eval("{**(bug = nil; {})};42")
+ assert_nil(bug)
+ end
end