summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-13 13:29:23 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-12-13 13:29:23 +0000
commitb71956d12b061613f8ef9dfe3f8a75e56dfa799d (patch)
tree11f455de1e876bfc478efee2052b0c8ed07e4279 /test/ruby
parentf1f609bc22a8aea2de4a3d564147ffb73a9ac211 (diff)
proc.c, vm_method.c: fix super and alias
* proc.c (method_owner): return the class where alias is defined, not the class original method is defined. * vm_method.c (rb_method_entry_make, rb_alias): store the originally defined class in me. [Bug #7993] [Bug #7842] [Bug #9236] * vm_method.c (rb_method_entry_get_without_cache): cache included module but not iclass. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44175 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_method.rb8
-rw-r--r--test/ruby/test_module.rb51
2 files changed, 58 insertions, 1 deletions
diff --git a/test/ruby/test_method.rb b/test/ruby/test_method.rb
index 273f3f83d1..a81d6d3812 100644
--- a/test/ruby/test_method.rb
+++ b/test/ruby/test_method.rb
@@ -365,7 +365,7 @@ class TestMethod < Test::Unit::TestCase
c3 = Class.new(c)
c3.class_eval { alias bar foo }
m3 = c3.new.method(:bar)
- assert_equal("#<Method: #{ c3.inspect }#bar(foo)>", m3.inspect, bug7806)
+ assert_equal("#<Method: #{c3.inspect}(#{c.inspect})#bar(foo)>", m3.inspect, bug7806)
end
def test_callee_top_level
@@ -571,17 +571,23 @@ class TestMethod < Test::Unit::TestCase
def test_alias_owner
bug7613 = '[ruby-core:51105]'
+ bug7993 = '[Bug #7993]'
c = Class.new {
def foo
end
+ prepend Module.new
+ attr_reader :zot
}
x = c.new
class << x
alias bar foo
end
+ assert_equal(c, c.instance_method(:foo).owner)
assert_equal(c, x.method(:foo).owner)
assert_equal(x.singleton_class, x.method(:bar).owner)
assert_not_equal(x.method(:foo), x.method(:bar), bug7613)
+ assert_equal(c, x.method(:zot).owner, bug7993)
+ assert_equal(c, c.instance_method(:zot).owner, bug7993)
end
def test_included
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index edcf271a76..269fb15045 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -1587,6 +1587,57 @@ class TestModule < Test::Unit::TestCase
assert_include(im, mixin, bug8025)
end
+ def test_prepend_super_in_alias
+ bug7842 = '[Bug #7842]'
+
+ p = labeled_module("P") do
+ def m; "P"+super; end
+ end
+ a = labeled_class("A") do
+ def m; "A"; end
+ end
+ b = labeled_class("B", a) do
+ def m; "B"+super; end
+ alias m2 m
+ prepend p
+ alias m3 m
+ end
+ assert_equal("BA", b.new.m2, bug7842)
+ assert_equal("PBA", b.new.m3, bug7842)
+ end
+
+ def test_include_super_in_alias
+ bug9236 = '[Bug #9236]'
+
+ fun = labeled_module("Fun") do
+ def hello
+ orig_hello
+ end
+ end
+
+ m1 = labeled_module("M1") do
+ def hello
+ 'hello!'
+ end
+ end
+
+ m2 = labeled_module("M2") do
+ def hello
+ super
+ end
+ end
+
+ foo = labeled_class("Foo") do
+ include m1
+ include m2
+
+ alias orig_hello hello
+ include fun
+ end
+
+ assert_equal('hello!', foo.new.hello, bug9236)
+ end
+
def test_class_variables
m = Module.new
m.class_variable_set(:@@foo, 1)