Skip to content

Commit edeb031

Browse files
committed
merge revision(s) 6118e8a: [Backport #20716]
Fix method caching bug when including/prepend module A that prepends module B Fix by always adding the generated iclass to the subclasses list, otherwise the method cache for the iclass is not cleared when the method in the module is overwritten. Fixes [Bug #20716]
1 parent 5ce0ba0 commit edeb031

File tree

3 files changed

+33
-8
lines changed

3 files changed

+33
-8
lines changed

class.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,6 @@ do_include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super
13261326
iclass = rb_include_class_new(module, super_class);
13271327
c = RCLASS_SET_SUPER(c, iclass);
13281328
RCLASS_SET_INCLUDER(iclass, klass);
1329-
add_subclass = TRUE;
13301329
if (module != RCLASS_ORIGIN(module)) {
13311330
if (!origin_stack) origin_stack = rb_ary_hidden_new(2);
13321331
VALUE origin[2] = {iclass, RCLASS_ORIGIN(module)};
@@ -1337,14 +1336,11 @@ do_include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super
13371336
RCLASS_SET_ORIGIN(RARRAY_AREF(origin_stack, (origin_len -= 2)), iclass);
13381337
RICLASS_SET_ORIGIN_SHARED_MTBL(iclass);
13391338
rb_ary_resize(origin_stack, origin_len);
1340-
add_subclass = FALSE;
13411339
}
13421340

1343-
if (add_subclass) {
1344-
VALUE m = module;
1345-
if (BUILTIN_TYPE(m) == T_ICLASS) m = METACLASS_OF(m);
1346-
rb_module_add_to_subclasses_list(m, iclass);
1347-
}
1341+
VALUE m = module;
1342+
if (BUILTIN_TYPE(m) == T_ICLASS) m = METACLASS_OF(m);
1343+
rb_module_add_to_subclasses_list(m, iclass);
13481344

13491345
if (BUILTIN_TYPE(klass) == T_MODULE && FL_TEST(klass, RMODULE_IS_REFINEMENT)) {
13501346
VALUE refined_class =

test/ruby/test_super.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,35 @@ def test_public_zsuper_with_prepend
617617
}
618618
end
619619

620+
def test_super_with_included_prepended_module_method_caching_bug_20716
621+
a = Module.new do
622+
def test(*args)
623+
super
624+
end
625+
end
626+
627+
b = Module.new do
628+
def test(a)
629+
a
630+
end
631+
end
632+
633+
c = Class.new
634+
635+
b.prepend(a)
636+
c.include(b)
637+
638+
assert_equal(1, c.new.test(1))
639+
640+
b.class_eval do
641+
def test
642+
:test
643+
end
644+
end
645+
646+
assert_equal(:test, c.new.test)
647+
end
648+
620649
class TestFor_super_with_modified_rest_parameter_base
621650
def foo *args
622651
args

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 5
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 106
14+
#define RUBY_PATCHLEVEL 107
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)