summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authornormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-17 00:54:13 +0000
committernormal <normal@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-17 00:54:13 +0000
commitfcf6fa8781fe236a9761ad5d75fa1b87f1afeea2 (patch)
treef0f172234f2556eee22e11e59b8e99f6068d6cc8 /test
parent61a8e7ebf76a1564df17ea4de4fe4ce21dba28f8 (diff)
compile.c: skip opt_* insns for fstr args with block given
* compile.c (iseq_compile_each): only emit opt_str_freeze, opt_aref_with, and opt_aset_with insn when no block is given [Bug #10557] [ruby-core:66595] * test/ruby/test_optimization.rb (test_block_given_aset_aref): new test for bug thanks to Bartosz Kopinski. (test_string_freeze): additional assertion for object_id git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/ruby/test_optimization.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb
index 129f62a0ff..4a5484e43d 100644
--- a/test/ruby/test_optimization.rb
+++ b/test/ruby/test_optimization.rb
@@ -118,6 +118,7 @@ class TestRubyOptimization < Test::Unit::TestCase
def test_string_freeze
assert_equal "foo", "foo".freeze
+ assert_equal "foo".freeze.object_id, "foo".freeze.object_id
assert_redefine_method('String', 'freeze', 'assert_nil "foo".freeze')
end
@@ -253,4 +254,39 @@ class TestRubyOptimization < Test::Unit::TestCase
EOF
assert_equal(123, delay { 123 }.call, bug6901)
end
+
+ class Bug10557
+ def [](_)
+ block_given?
+ end
+
+ def []=(_, _)
+ block_given?
+ end
+ end
+
+ def test_block_given_aset_aref
+ bug10557 = '[ruby-core:66595]'
+ assert_equal(true, Bug10557.new.[](nil){}, bug10557)
+ assert_equal(true, Bug10557.new.[](0){}, bug10557)
+ assert_equal(true, Bug10557.new.[](false){}, bug10557)
+ assert_equal(true, Bug10557.new.[](''){}, bug10557)
+ assert_equal(true, Bug10557.new.[]=(nil, 1){}, bug10557)
+ assert_equal(true, Bug10557.new.[]=(0, 1){}, bug10557)
+ assert_equal(true, Bug10557.new.[]=(false, 1){}, bug10557)
+ assert_equal(true, Bug10557.new.[]=('', 1){}, bug10557)
+ end
+
+ def test_string_freeze_block
+ assert_separately([], <<-"end;")# do
+ class String
+ undef freeze
+ def freeze
+ block_given?
+ end
+ end
+ assert_equal(true, "block".freeze {})
+ assert_equal(false, "block".freeze)
+ end;
+ end
end