summaryrefslogtreecommitdiff
path: root/insns.def
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-06 07:00:19 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-08-06 07:00:19 +0000
commit9537e8ffe5b7a0e6a2a791e1886509dc98b6d3f9 (patch)
tree4dc30bb86d4131f70c137831c116771783e5fc5b /insns.def
parent3dd941b234ab6df52f72bb32e401f6669ef972c7 (diff)
* 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 'insns.def')
-rw-r--r--insns.def23
1 files changed, 22 insertions, 1 deletions
diff --git a/insns.def b/insns.def
index 7b17b42579..b616368992 100644
--- a/insns.def
+++ b/insns.def
@@ -1032,13 +1032,34 @@ invokesuper
int num = caller_setup_args(th, GET_CFP(), flag,
(int)op_argc, blockiseq, &blockptr);
VALUE recv, klass;
+ rb_control_frame_t *cfp = GET_CFP();
+ rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(th);
ID id;
const rb_method_entry_t *me;
rb_iseq_t *ip;
flag = VM_CALL_SUPER_BIT | VM_CALL_FCALL_BIT;
- recv = GET_SELF();
+ recv = Qundef;
+ while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
+ 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)) {
+ recv = cfp->self;
+ break;
+ }
+ cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
+ }
+ 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();