ruby-changes:49214
From: nobu <ko1@a...>
Date: Tue, 19 Dec 2017 09:46:03 +0900 (JST)
Subject: [ruby-changes:49214] nobu:r61329 (trunk): compile.c: side effect in splat
nobu 2017-12-19 09:45:55 +0900 (Tue, 19 Dec 2017) New Revision: 61329 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=61329 Log: 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@r...> Modified files: trunk/compile.c trunk/test/ruby/test_optimization.rb Index: test/ruby/test_optimization.rb =================================================================== --- test/ruby/test_optimization.rb (revision 61328) +++ test/ruby/test_optimization.rb (revision 61329) @@ -702,4 +702,10 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L702 } END end + + def test_side_effect_in_popped_splat + bug = '[ruby-core:84340] [Bug #14201]' + eval("{**(bug = nil; {})};42") + assert_nil(bug) + end end Index: compile.c =================================================================== --- compile.c (revision 61328) +++ compile.c (revision 61329) @@ -3619,7 +3619,7 @@ compile_array(rb_iseq_t *iseq, LINK_ANCH https://github.com/ruby/ruby/blob/trunk/compile.c#L3619 } } 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_ANCH https://github.com/ruby/ruby/blob/trunk/compile.c#L3660 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 https://github.com/ruby/ruby/blob/trunk/compile.c#L6271 } 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) { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/