summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-22 16:51:08 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-22 16:51:08 +0000
commit51a41dd0569b27b80342aa4bd72e6b2c9f2c482c (patch)
treed044040850385a4247470e240d5357bf92e66939
parentc06924693158a17bad63f0f343c6e951d9b9b8eb (diff)
* insns.def: search up the cf stack for an object that is an instance
of the recipient class. Fixes [ruby-core:47186] * test/ruby/test_super.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--insns.def17
-rw-r--r--test/ruby/test_super.rb12
3 files changed, 27 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index e58ad1dc06..73b938db93 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+Thu Aug 23 01:46:53 2012 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * insns.def: search up the cf stack for an object that is an instance
+ of the recipient class. Fixes [ruby-core:47186]
+
+ * test/ruby/test_super.rb: related test.
+
Wed Aug 22 19:46:24 2012 Tadayoshi Funaba <tadf@dotrb.org>
* ext/date/date_core.c: [ruby-core:47266].
diff --git a/insns.def b/insns.def
index b2f17c5fef..f9e582efb0 100644
--- a/insns.def
+++ b/insns.def
@@ -1034,11 +1034,17 @@ invokesuper
flag = VM_CALL_SUPER_BIT | VM_CALL_FCALL_BIT;
+ klass = GET_CFP()->klass;
+ if (!NIL_P(RCLASS_REFINED_CLASS(klass))) {
+ klass = RCLASS_REFINED_CLASS(klass);
+ }
+
recv = Qundef;
while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
- if ((VM_EP_LEP_P(cfp->ep) && cfp->iseq &&
+ if (((VM_EP_LEP_P(cfp->ep) && cfp->iseq &&
cfp->iseq->type == ISEQ_TYPE_METHOD) ||
- (cfp->me && cfp->me->def->type == VM_METHOD_TYPE_BMETHOD)) {
+ (cfp->me && cfp->me->def->type == VM_METHOD_TYPE_BMETHOD)) &&
+ rb_obj_is_kind_of(cfp->self, klass)) {
recv = cfp->self;
break;
}
@@ -1047,13 +1053,6 @@ invokesuper
if (recv == Qundef) {
rb_raise(rb_eNoMethodError, "super called outside of method");
}
- klass = GET_CFP()->klass;
- if (!NIL_P(RCLASS_REFINED_CLASS(klass))) {
- klass = RCLASS_REFINED_CLASS(klass);
- }
- if (!rb_obj_is_kind_of(recv, klass)) {
- rb_raise(rb_eNoMethodError, "can't find the method for super, which may be called in an orphan block");
- }
vm_search_superclass(GET_CFP(), GET_ISEQ(), TOPN(num), &id, &klass);
ip = GET_ISEQ();
diff --git a/test/ruby/test_super.rb b/test/ruby/test_super.rb
index 8494745fed..7208b362fc 100644
--- a/test/ruby/test_super.rb
+++ b/test/ruby/test_super.rb
@@ -322,4 +322,16 @@ class TestSuper < Test::Unit::TestCase
obj.foo.call
end
end
+
+ def test_yielding_super
+ a = Class.new { def yielder; yield; end }
+ x = Class.new { define_singleton_method(:hello) { 'hi' } }
+ y = Class.new(x) {
+ define_singleton_method(:hello) {
+ m = a.new
+ m.yielder { super() }
+ }
+ }
+ assert_equal 'hi', y.hello
+ end
end