Skip to content

Commit

Permalink
[Truffle] Class vars: do the lookup on the given module in all cases.
Browse files Browse the repository at this point in the history
* Also add an instanceof check in case the type of attached evolves.
  • Loading branch information
eregon committed Mar 9, 2015
1 parent 8c3f7f3 commit 0f7a77d
Showing 1 changed file with 12 additions and 13 deletions.
Expand Up @@ -225,35 +225,34 @@ public static Map<String, Object> getAllClassVariables(RubyModule module) {
public static Object lookupClassVariable(RubyModule module, String name) {
CompilerAsserts.neverPartOfCompilation();

// Look in the current module
Object value = module.getClassVariables().get(name);
if (value != null) {
return value;
}

// If singleton class, check attached module.
if (module instanceof RubyClass) {
RubyClass klass = (RubyClass) module;

if (klass.isSingleton() && klass.getAttached() != null) {
if (klass.isSingleton() && klass.getAttached() instanceof RubyModule) {
module = klass.getAttached();
}
}

Object value;

// Look in the current module
value = module.getClassVariables().get(name);

if (value != null) {
return value;
value = module.getClassVariables().get(name);
if (value != null) {
return value;
}
}
}

// Look in ancestors
for (RubyModule ancestor : module.parentAncestors()) {
value = ancestor.getClassVariables().get(name);

if (value != null) {
return value;
}
}

// Nothing found

return null;
}

Expand Down

0 comments on commit 0f7a77d

Please sign in to comment.