super_in_instance_eval_fix.diff

Shugo Maeda, 11/25/2009 05:55 PM

Download (2.03 KB)

View differences:

insns.def
1014 1014
    ID id;
1015 1015
    VALUE flag = VM_CALL_SUPER_BIT | VM_CALL_FCALL_BIT;
1016 1016
    const rb_method_entry_t *me;
1017
    rb_control_frame_t *cfp = GET_CFP();
1018
    rb_control_frame_t *end_cfp = RUBY_VM_END_CONTROL_FRAME(th);
1019
    VALUE *lfp = GET_LFP();
1020
    VALUE *dfp = GET_DFP();
1017 1021

  
1018
    recv = GET_SELF();
1022
    recv = Qundef;
1023
    while (RUBY_VM_VALID_CONTROL_FRAME_P(cfp, end_cfp)) {
1024
	if ((cfp->dfp == lfp && cfp->iseq->type == ISEQ_TYPE_METHOD) ||
1025
	    (cfp->me && cfp->me->def->type == VM_METHOD_TYPE_BMETHOD)) {
1026
	    recv = cfp->self;
1027
	    break;
1028
	}
1029
	cfp = RUBY_VM_PREVIOUS_CONTROL_FRAME(cfp);
1030
    }
1031
    if (recv == Qundef) {
1032
	rb_raise(rb_eNoMethodError, "super called outside of method");
1033
    }
1019 1034
    vm_search_superclass(GET_CFP(), GET_ISEQ(), recv, TOPN(num), &id, &klass);
1020 1035
    me = rb_method_entry(klass, id);
1021 1036

  
test/ruby/test_eval.rb
415 415
    assert_raise(ArgumentError) {eval("__ENCODING__".encode("utf-32be"))}
416 416
    assert_raise(ArgumentError) {eval("__ENCODING__".encode("utf-32le"))}
417 417
  end
418

  
419
  def test_super_in_instance_eval
420
    super_class = Class.new {
421
      def foo
422
        return [:super, self]
423
      end
424
    }
425
    sub_class = Class.new(super_class) {
426
      def foo
427
        x = Object.new
428
        x.instance_eval do
429
          super()
430
        end
431
      end
432
    }
433
    obj = sub_class.new
434
    assert_equal [:super, obj], obj.foo
435
  end
436

  
437
  def test_super_in_instance_eval_with_define_method
438
    super_class = Class.new {
439
      def foo
440
        return [:super, self]
441
      end
442
    }
443
    sub_class = Class.new(super_class) {
444
      define_method(:foo) do
445
        x = Object.new
446
        x.instance_eval do
447
          super()
448
        end
449
      end
450
    }
451
    obj = sub_class.new
452
    assert_equal [:super, obj], obj.foo
453
  end
418 454
end