diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-08-06 07:00:19 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-08-06 07:00:19 +0000 |
commit | 9537e8ffe5b7a0e6a2a791e1886509dc98b6d3f9 (patch) | |
tree | 4dc30bb86d4131f70c137831c116771783e5fc5b /test | |
parent | 3dd941b234ab6df52f72bb32e401f6669ef972c7 (diff) | |
download | ruby-9537e8ffe5b7a0e6a2a791e1886509dc98b6d3f9.tar.gz |
* internal.h, class.c, eval.c, insns.def: find the appropriate
receiver for super called in instance_eval. If such a receiver is
not found, raise NoMethodError. [ruby-dev:39772] [Bug #2402]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36640 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_super.rb | 80 |
1 files changed, 77 insertions, 3 deletions
diff --git a/test/ruby/test_super.rb b/test/ruby/test_super.rb index 1d3f2c6fb7..8494745fed 100644 --- a/test/ruby/test_super.rb +++ b/test/ruby/test_super.rb @@ -132,9 +132,9 @@ class TestSuper < Test::Unit::TestCase assert_equal("A#tt", a.tt(12), "[ruby-core:3856]") e = assert_raise(RuntimeError, "[ruby-core:24244]") { lambda { - Class.new do - define_method(:a) {super}.call - end + Class.new { + define_method(:a) {super} + }.new.a }.call } assert_match(/implicit argument passing of super from method defined by define_method/, e.message) @@ -248,4 +248,78 @@ class TestSuper < Test::Unit::TestCase assert_equal([:Base, :Override, :A, :Override, :B], DoubleInclude2::B.new.foo) end + + def test_super_in_instance_eval + super_class = Class.new { + def foo + return [:super, self] + end + } + sub_class = Class.new(super_class) { + def foo + x = Object.new + x.instance_eval do + super() + end + end + } + obj = sub_class.new + assert_equal [:super, obj], obj.foo + end + + def test_super_in_instance_eval_with_define_method + super_class = Class.new { + def foo + return [:super, self] + end + } + sub_class = Class.new(super_class) { + define_method(:foo) do + x = Object.new + x.instance_eval do + super() + end + end + } + obj = sub_class.new + assert_equal [:super, obj], obj.foo + end + + def test_super_in_orphan_block + super_class = Class.new { + def foo + return [:super, self] + end + } + sub_class = Class.new(super_class) { + def foo + x = Object.new + lambda { super() } + end + } + obj = sub_class.new + assert_raise(NoMethodError) do + obj.foo.call + end + end + + def test_super_in_orphan_block_with_instance_eval + super_class = Class.new { + def foo + return [:super, self] + end + } + sub_class = Class.new(super_class) { + def foo + x = Object.new + x.instance_eval do + lambda { super() } + end + end + } + obj = sub_class.new + assert_raise(NoMethodError) do + obj.foo.call + end + end end |