mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* vm_insnhelper.c (vm_search_const_defined_class): search
ancestors only when global scope. [ruby-core:39227] [Bug #5264] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33163 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
5e14b97947
commit
7dddaf6807
4 changed files with 38 additions and 22 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Fri Sep 2 14:36:47 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* vm_insnhelper.c (vm_search_const_defined_class): search
|
||||||
|
ancestors only when global scope. [ruby-core:39227] [Bug #5264]
|
||||||
|
|
||||||
Fri Sep 2 09:58:08 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Fri Sep 2 09:58:08 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* parse.y (parser_tokadd_string, parser_yylex): ignore a backslash
|
* parse.y (parser_tokadd_string, parser_yylex): ignore a backslash
|
||||||
|
|
10
insns.def
10
insns.def
|
@ -895,7 +895,6 @@ defineclass
|
||||||
(VALUE val)
|
(VALUE val)
|
||||||
{
|
{
|
||||||
VALUE klass;
|
VALUE klass;
|
||||||
int newclass = 1;
|
|
||||||
|
|
||||||
switch ((int)define_type) {
|
switch ((int)define_type) {
|
||||||
case 0: /* scoped: class Foo::Bar */
|
case 0: /* scoped: class Foo::Bar */
|
||||||
|
@ -904,16 +903,15 @@ defineclass
|
||||||
|
|
||||||
if (super == Qnil) {
|
if (super == Qnil) {
|
||||||
super = rb_cObject;
|
super = rb_cObject;
|
||||||
newclass = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vm_check_if_namespace(cbase);
|
vm_check_if_namespace(cbase);
|
||||||
|
|
||||||
/* find klass */
|
/* find klass */
|
||||||
rb_autoload_load(cbase, id);
|
rb_autoload_load(cbase, id);
|
||||||
if (vm_const_defined_at(cbase, id, newclass)) {
|
if ((klass = vm_search_const_defined_class(cbase, id)) != 0) {
|
||||||
/* already exist */
|
/* already exist */
|
||||||
klass = define_type == 0 ? rb_public_const_get(cbase, id) : rb_const_get_from(cbase, id);
|
klass = define_type == 0 ? rb_public_const_get_at(klass, id) : rb_const_get_at(klass, id);
|
||||||
if (TYPE(klass) != T_CLASS) {
|
if (TYPE(klass) != T_CLASS) {
|
||||||
rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
|
rb_raise(rb_eTypeError, "%s is not a class", rb_id2name(id));
|
||||||
}
|
}
|
||||||
|
@ -949,8 +947,8 @@ defineclass
|
||||||
vm_check_if_namespace(cbase);
|
vm_check_if_namespace(cbase);
|
||||||
|
|
||||||
/* find klass */
|
/* find klass */
|
||||||
if (vm_const_defined_at(cbase, id, 0)) {
|
if ((klass = vm_search_const_defined_class(cbase, id)) != 0) {
|
||||||
klass = define_type == 2 ? rb_public_const_get(cbase, id) : rb_const_get_from(cbase, id);
|
klass = define_type == 2 ? rb_public_const_get_at(klass, id) : rb_const_get_at(klass, id);
|
||||||
/* already exist */
|
/* already exist */
|
||||||
if (TYPE(klass) != T_MODULE) {
|
if (TYPE(klass) != T_MODULE) {
|
||||||
rb_raise(rb_eTypeError, "%s is not a module", rb_id2name(id));
|
rb_raise(rb_eTypeError, "%s is not a module", rb_id2name(id));
|
||||||
|
|
|
@ -557,6 +557,16 @@ module LangModuleTop
|
||||||
end
|
end
|
||||||
puts "ok" if LangModuleSpecInObject::LangModuleTop == LangModuleTop
|
puts "ok" if LangModuleSpecInObject::LangModuleTop == LangModuleTop
|
||||||
INPUT
|
INPUT
|
||||||
|
|
||||||
|
bug5264 = '[ruby-core:39227]'
|
||||||
|
assert_in_out_err([], <<-'INPUT', [], [], bug5264)
|
||||||
|
class A
|
||||||
|
class X; end
|
||||||
|
end
|
||||||
|
class B < A
|
||||||
|
module X; end
|
||||||
|
end
|
||||||
|
INPUT
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_variable_get
|
def test_class_variable_get
|
||||||
|
|
|
@ -1253,15 +1253,18 @@ vm_get_cvar_base(NODE *cref)
|
||||||
return klass;
|
return klass;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static VALUE
|
||||||
vm_const_defined_at(VALUE cbase, ID id, int newclass)
|
vm_search_const_defined_class(const VALUE cbase, ID id)
|
||||||
{
|
{
|
||||||
int ret = rb_const_defined_at(cbase, id);
|
if (rb_const_defined_at(cbase, id)) return cbase;
|
||||||
if (!ret && !newclass) {
|
if (cbase == rb_cObject) {
|
||||||
while ((cbase = RCLASS_SUPER(cbase)) != 0 && cbase != rb_cObject &&
|
VALUE tmp = RCLASS_SUPER(cbase);
|
||||||
!(ret = rb_const_defined_at(cbase, id)));
|
while (tmp) {
|
||||||
|
if (rb_const_defined_at(tmp, id)) return tmp;
|
||||||
|
tmp = RCLASS_SUPER(tmp);
|
||||||
}
|
}
|
||||||
return ret;
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef USE_IC_FOR_IVAR
|
#ifndef USE_IC_FOR_IVAR
|
||||||
|
|
Loading…
Reference in a new issue