Skip to content

Commit

Permalink
Merge pull request #8219 from enebo/class_vars_overtaken
Browse files Browse the repository at this point in the history
Class vars overtaken
  • Loading branch information
enebo committed Apr 30, 2024
2 parents 3afe3fd + 4c9bcd9 commit e3e2432
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
14 changes: 14 additions & 0 deletions core/src/main/java/org/jruby/RubyModule.java
Expand Up @@ -4610,13 +4610,27 @@ public IRubyObject getClassVarQuiet(String name) {
assert IdUtil.isClassVariable(name);
RubyModule module = this;
RubyModule highest = null;
RubyModule lowest = null;

do {
if (module.hasClassVariable(name)) {
highest = module;
if (lowest == null) lowest = module;
}
} while ((module = module.getSuperClass()) != null);

if (lowest != highest) {
if (!highest.isPrepended()) {
if (lowest.getOrigin().getRealModule() != highest.getOrigin().getRealModule()) {
throw getRuntime().newRuntimeError(str(getRuntime(), "class variable " + name + " of ",
lowest.getOrigin(), " is overtaken by ", highest.getOrigin()));
}

if (lowest.isClass()) lowest.removeClassVariable(name);
}

}

if (highest != null) return highest.fetchClassVariable(name);

return null;
Expand Down
1 change: 0 additions & 1 deletion spec/tags/ruby/language/class_variable_tags.txt

This file was deleted.

0 comments on commit e3e2432

Please sign in to comment.