@@ -313,10 +313,12 @@ private void performIncludes(ModuleChain inclusionPoint, Deque<RubyModule> modul
313
313
while (!moduleAncestors .isEmpty ()) {
314
314
RubyModule toInclude = moduleAncestors .pop ();
315
315
inclusionPoint .insertAfter (toInclude );
316
- toInclude .fields .includedBy .add (rubyModule );
317
- // Module#include only adds modules between the current class and the super class,
318
- // so invalidating the current class is enough as all affected lookups would go through the current class.
319
- newMethodsVersion (toInclude .fields .getMethodNames ());
316
+ if (rubyModule instanceof RubyClass ) { // M.include(N) just registers N but does nothing until C.include/prepend(M)
317
+ toInclude .fields .includedBy .add (rubyModule );
318
+ // Module#include only adds modules between the current class and the super class,
319
+ // so invalidating the current class is enough as all affected lookups would go through the current class.
320
+ newMethodsVersion (toInclude .fields .getMethodNames ());
321
+ }
320
322
}
321
323
}
322
324
@@ -346,7 +348,9 @@ public void prepend(RubyContext context, Node currentNode, RubyModule module) {
346
348
347
349
/* We need to invalidate all prepended modules and the class, because call sites which looked up methods before
348
350
* only check the class or one of the prepend module (if the method is defined there). */
349
- final List <RubyModule > prependedModulesAndSelf = getPrependedModulesAndSelf ();
351
+ final List <RubyModule > prependedModulesAndClass = rubyModule instanceof RubyClass
352
+ ? getPrependedModulesAndClass ()
353
+ : null ;
350
354
351
355
ModuleChain mod = module .fields .start ;
352
356
ModuleChain cur = start ;
@@ -356,10 +360,12 @@ public void prepend(RubyContext context, Node currentNode, RubyModule module) {
356
360
final RubyModule toPrepend = mod .getActualModule ();
357
361
if (!ModuleOperations .includesModule (rubyModule , toPrepend )) {
358
362
cur .insertAfter (toPrepend );
359
- final List <String > methodsToInvalidate = toPrepend .fields .getMethodNames ();
360
- for (RubyModule moduleToInvalidate : prependedModulesAndSelf ) {
361
- toPrepend .fields .includedBy .add (moduleToInvalidate );
362
- moduleToInvalidate .fields .newMethodsVersion (methodsToInvalidate );
363
+ if (rubyModule instanceof RubyClass ) { // M.prepend(N) just registers N but does nothing until C.prepend/include(M)
364
+ final List <String > methodsToInvalidate = toPrepend .fields .getMethodNames ();
365
+ for (RubyModule moduleToInvalidate : prependedModulesAndClass ) {
366
+ toPrepend .fields .includedBy .add (moduleToInvalidate );
367
+ moduleToInvalidate .fields .newMethodsVersion (methodsToInvalidate );
368
+ }
363
369
}
364
370
cur = cur .getParentModule ();
365
371
}
@@ -373,7 +379,7 @@ public void prepend(RubyContext context, Node currentNode, RubyModule module) {
373
379
invalidateBuiltinsAssumptions ();
374
380
}
375
381
376
- private List <RubyModule > getPrependedModulesAndSelf () {
382
+ private List <RubyModule > getPrependedModulesAndClass () {
377
383
final List <RubyModule > prependedModulesAndClass = new ArrayList <>();
378
384
ModuleChain chain = getFirstModuleChain ();
379
385
while (chain != this ) {
0 commit comments