From 6af36f2a4d7452d485ebe94fd75d30b4eac09926 Mon Sep 17 00:00:00 2001 From: Aotokitsuruya Date: Thu, 22 Aug 2024 20:27:39 +0800 Subject: [PATCH] Define search loop in includeModuleAt --- class.go | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/class.go b/class.go index ffee5a4..bfed761 100644 --- a/class.go +++ b/class.go @@ -175,12 +175,30 @@ func (mrb *State) prepareSingletonClass(obj RObject) error { return nil } -func (mrb *State) includeModuleAt(class, insPos, module RClass, superSearch int) int { +func (mrb *State) includeModuleAt(class, insPos, module RClass, searchSuper bool) int { + for module != nil { + parentClass := class.Super() + + if module.Flags()&FlagClassIsPrepended != 0 { + goto Skip + } + + for parentClass != nil { + if !searchSuper { + break + } + + parentClass = parentClass.Super() + } + Skip: + module = module.Super() + } + return 0 } func (mrb *State) IncludeModule(class, module RClass) error { - mrb.includeModuleAt(class, findOrigin(class), module, 1) + mrb.includeModuleAt(class, findOrigin(class), module, true) return nil }