summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-09 14:09:58 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-02-09 14:09:58 +0000
commit63abedabf81d682db1a3063562c6141821e2023d (patch)
treeed4ca7145777ab91b3a3c33dd4693fb55ffb9465
parent1a45a3a797cd7c1996098cd210d9926e0cd80e4d (diff)
compile.c: popped hash
* compile.c (compile_array): skip creating new hash if preceeding elements are popped all. [ruby-core:85486] [Bug #14459] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@62333 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--compile.c14
-rw-r--r--test/ruby/test_optimization.rb5
2 files changed, 15 insertions, 4 deletions
diff --git a/compile.c b/compile.c
index b559703015..5bca0dca99 100644
--- a/compile.c
+++ b/compile.c
@@ -3761,14 +3761,20 @@ compile_array(rb_iseq_t *iseq, LINK_ANCHOR *const ret, const NODE *const node_ro
case COMPILE_ARRAY_TYPE_HASH:
if (i > 0) {
if (first) {
- ADD_INSN1(anchor, line, newhash, INT2FIX(i));
+ if (!popped) {
+ ADD_INSN1(anchor, line, newhash, INT2FIX(i));
+ }
APPEND_LIST(ret, anchor);
}
else {
- ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
- ADD_INSN(ret, line, swap);
+ if (!popped) {
+ ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE));
+ ADD_INSN(ret, line, swap);
+ }
APPEND_LIST(ret, anchor);
- ADD_SEND(ret, line, id_core_hash_merge_ptr, INT2FIX(i + 1));
+ if (!popped) {
+ ADD_SEND(ret, line, id_core_hash_merge_ptr, INT2FIX(i + 1));
+ }
}
}
if (kw) {
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index ac3440a665..6e463e1863 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -709,6 +709,11 @@ class TestRubyOptimization < Test::Unit::TestCase
bug = '[ruby-core:84340] [Bug #14201]'
eval("{**(bug = nil; {})};42")
assert_nil(bug)
+
+ bug = '[ruby-core:85486] [Bug #14459]'
+ h = {}
+ assert_equal(bug, eval('{ok: 42, **h}; bug'))
+ assert_equal(:ok, eval('{ok: bug = :ok, **h}; bug'))
end
def test_overwritten_blockparam