@@ -295,6 +295,8 @@ public void include(RubyContext context, Node currentNode, RubyModule module) {
295
295
private void performIncludes (ModuleChain inclusionPoint , Deque <RubyModule > moduleAncestors ) {
296
296
while (!moduleAncestors .isEmpty ()) {
297
297
RubyModule mod = moduleAncestors .pop ();
298
+ // Module#include only adds modules between the current class and the super class,
299
+ // so invalidating the current class is enough as all affected lookups would go through the current class.
298
300
newMethodsVersion (mod .fields .getMethodNames ());
299
301
inclusionPoint .insertAfter (mod );
300
302
}
@@ -324,16 +326,11 @@ public void prepend(RubyContext context, Node currentNode, RubyModule module) {
324
326
325
327
SharedObjects .propagate (context .getLanguageSlow (), rubyModule , module );
326
328
327
- ModuleChain mod = module .fields .start ;
328
- final ModuleChain topPrependedModule = start .getParentModule ();
329
-
330
- final ModuleFields moduleFieldsToInvalidate ;
331
- if (topPrependedModule != this ) {
332
- moduleFieldsToInvalidate = topPrependedModule .getActualModule ().fields ;
333
- } else {
334
- moduleFieldsToInvalidate = this ;
335
- }
329
+ // Previous calls on instances of the current class must have looked up through the first prepended module,
330
+ // so invalidate that one.
331
+ final ModuleFields moduleFieldsToInvalidate = getFirstModuleChain ().getActualModule ().fields ;
336
332
333
+ ModuleChain mod = module .fields .start ;
337
334
ModuleChain cur = start ;
338
335
while (mod != null &&
339
336
!(mod instanceof ModuleFields && ((ModuleFields ) mod ).rubyModule instanceof RubyClass )) {
0 commit comments