1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

defined: me in cfp

* insns.def (defined): use method entry and id in cfp for proper
  superclass, since klass in iseq is shared by dynamically defined
  methods from the same block.  [ruby-core:45831][Bug #6644]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36369 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2012-07-11 20:11:45 +00:00
parent 2642b69096
commit 35784d1019
3 changed files with 28 additions and 11 deletions

View file

@ -1,3 +1,9 @@
Thu Jul 12 05:11:41 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* insns.def (defined): use method entry and id in cfp for proper
superclass, since klass in iseq is shared by dynamically defined
methods from the same block. [ruby-core:45831][Bug #6644]
Thu Jul 12 01:49:07 2012 NARUSE, Yui <naruse@ruby-lang.org>
* lib/net/http.rb (Net::HTTP#connect): use local_host and local_port
@ -10,7 +16,7 @@ Wed Jul 11 17:36:39 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
Wed Jul 11 12:38:20 2012 NAKAMURA Usaku <usa@ruby-lang.org>
* ext/openssl/ossl_pkey_ec.c (ossl_ec_point_mul): nonstatic initializer
* ext/openssl/ossl_pkey_ec.c (ossl_ec_point_mul): nonstatic initializer
of an aggregate type is a C99ism.
* ext/openssl/ossl_pkey_ec.c (ossl_ec_point_mul): get rid of VC++

View file

@ -826,16 +826,11 @@ defined
}
break;
case DEFINED_ZSUPER:{
rb_iseq_t *iseq = GET_ISEQ();
while (iseq) {
if (iseq->defined_method_id) {
break;
}
iseq = iseq->parent_iseq;
}
if (iseq) {
VALUE klass = vm_search_normal_superclass(iseq->klass, GET_SELF());
if (rb_method_boundp(klass, iseq->defined_method_id, 0)) {
const rb_method_entry_t *me = GET_CFP()->me;
if (me) {
VALUE klass = vm_search_normal_superclass(me->klass, GET_SELF());
ID id = me->def ? me->def->original_id : me->called_id;
if (rb_method_boundp(klass, id, 0)) {
expr_type = "super";
}
}

View file

@ -136,4 +136,20 @@ class TestDefined < Test::Unit::TestCase
bug5786 = '[ruby-dev:45021]'
assert_nil(defined?(raise("[Bug#5786]")::A), bug5786)
end
def test_define_method
bug6644 = '[ruby-core:45831]'
a = Class.new do
def self.def_f!;
singleton_class.send(:define_method, :f) { defined? super }
end
end
aa = Class.new(a)
a.def_f!
assert_nil(a.f)
assert_nil(aa.f)
aa.def_f!
assert_equal("super", aa.f, bug6644)
assert_nil(a.f, bug6644)
end
end