From d99bcbe583eb9f95022f8bcc51674cbdecf40d3b Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 2 Feb 2007 09:47:55 +0000 Subject: * vm.c (eval_get_cvar_base): destination for class variable access is now strictly innermost surrounding class or module. warned if accessed from toplevel. * variable.c (rb_cvar_get): new class variable look-up scheme: 1) look up in the class. 2) if the class is singleton attached to a class (i.e. metaclass) then start look up in the attached class and its ancestors. 3) otherwise, look-up in ancestors of the class. * eval.c (cvar_cbase): destination for class variable access is the class/module that holds the method, or cbase outside of methods. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@11613 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- vm.c | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'vm.c') diff --git a/vm.c b/vm.c index 8898cfb516..cdf61509e6 100644 --- a/vm.c +++ b/vm.c @@ -1141,22 +1141,11 @@ eval_get_cvar_base(yarv_thread_t *th, yarv_iseq_t *iseq) NODE *cref = get_cref(iseq, th->cfp->lfp); VALUE klass = Qnil; - while (cref) { + if (cref) { klass = cref->nd_clss; - cref = cref->nd_next; - - if (cref == 0) { - continue; + if (!cref->nd_next) { + rb_warn("class variable access from toplevel"); } - - if (NIL_P(klass) || FL_TEST(klass, FL_SINGLETON)) { - if (cref->nd_next == 0) { - rb_warn - ("class variable access from toplevel singleton method"); - } - continue; - } - break; } if (NIL_P(klass)) { rb_raise(rb_eTypeError, "no class variables available"); -- cgit v1.2.3