Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/org/jruby/RubyModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,7 @@ public synchronized void includeModule(IRubyObject arg) {
doIncludeModule(module);
invalidateCoreClasses();
invalidateCacheDescendants();
invalidateConstantCacheForModuleInclusion(module);
}

public void defineAnnotatedMethod(Class clazz, String name) {
Expand Down Expand Up @@ -974,6 +975,16 @@ private CacheEntry cacheHit(String name) {

return null;
}

private void invalidateConstantCacheForModuleInclusion(RubyModule module)
{
for (RubyModule mod : gatherModules(module)) {
if (!mod.getConstantMap().isEmpty()) {
invalidateConstantCache();
break;
}
}
}

protected static abstract class CacheEntryFactory {
public abstract CacheEntry newCacheEntry(DynamicMethod method, int token);
Expand Down
25 changes: 25 additions & 0 deletions test/test_including_module_busts_constant_caches.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
require "test/unit"

class TestIncludingModuleBustsConstantCaches < Test::Unit::TestCase
module M
A = 123
end

module N
A = 456
end

class Foo
include M

def self.get
A
end
end

def test_including_module_busts_constant_caches
assert_equal 123, Foo.get
Foo.send(:include, N)
assert_equal 456, Foo.get
end
end