summaryrefslogtreecommitdiff
path: root/class.c
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2019-08-08 09:55:33 -0700
committerJeremy Evans <code@jeremyevans.net>2020-11-20 15:26:43 -0800
commit08686e71d5c48325ee1bd41c8d7ebcd6c37fa496 (patch)
treeff711636c0746b3dcce4b543699a4aa1e1773cda /class.c
parent1f7b557890c41e59b461d42a5fb9e1f25da9b33d (diff)
Do not allow Module#include to insert modules before the origin in the lookup chain
Module#include should only be able to insert modules after the origin, otherwise it ends up working like Module#prepend. This fixes the case where one of the modules in the included module chain is included in a module that is already prepended to the receiver. Fixes [Bug #7844]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3796
Diffstat (limited to 'class.c')
-rw-r--r--class.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/class.c b/class.c
index 709d49c..1f56385 100644
--- a/class.c
+++ b/class.c
@@ -1013,17 +1013,22 @@ include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super)
VALUE original_klass = klass;
while (module) {
+ int origin_seen = FALSE;
int superclass_seen = FALSE;
struct rb_id_table *tbl;
+ if (klass == c)
+ origin_seen = TRUE;
if (klass_m_tbl && klass_m_tbl == RCLASS_M_TBL(module))
return -1;
/* ignore if the module included already in superclasses */
for (p = RCLASS_SUPER(klass); p; p = RCLASS_SUPER(p)) {
int type = BUILTIN_TYPE(p);
+ if (c == p)
+ origin_seen = TRUE;
if (type == T_ICLASS) {
if (RCLASS_M_TBL(p) == RCLASS_M_TBL(module)) {
- if (!superclass_seen) {
+ if (!superclass_seen && origin_seen) {
c = p; /* move insertion point */
}
goto skip;