diff options
| author | Takashi Kokubun <takashikkbn@gmail.com> | 2024-11-04 14:42:47 -0800 |
|---|---|---|
| committer | Takashi Kokubun <takashikkbn@gmail.com> | 2024-11-04 14:42:47 -0800 |
| commit | edeb0319f7a95dfe3f9b895bcf32371dd8514726 (patch) | |
| tree | 62047e61307d9930c2c96ece1eb98de41a6b42aa | |
| parent | 5ce0ba0d415deb99527c409cc5f1df16ce02ef3e (diff) | |
merge revision(s) 6118e8a47394409b53164b60e79fadf348b97db3: [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]
| -rw-r--r-- | class.c | 10 | ||||
| -rw-r--r-- | test/ruby/test_super.rb | 29 | ||||
| -rw-r--r-- | version.h | 2 |
3 files changed, 33 insertions, 8 deletions
@@ -1326,7 +1326,6 @@ do_include_modules_at(const VALUE klass, VALUE c, VALUE module, int search_super iclass = rb_include_class_new(module, super_class); c = RCLASS_SET_SUPER(c, iclass); RCLASS_SET_INCLUDER(iclass, klass); - add_subclass = TRUE; if (module != RCLASS_ORIGIN(module)) { if (!origin_stack) origin_stack = rb_ary_hidden_new(2); 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 RCLASS_SET_ORIGIN(RARRAY_AREF(origin_stack, (origin_len -= 2)), iclass); RICLASS_SET_ORIGIN_SHARED_MTBL(iclass); rb_ary_resize(origin_stack, origin_len); - add_subclass = FALSE; } - if (add_subclass) { - VALUE m = module; - if (BUILTIN_TYPE(m) == T_ICLASS) m = METACLASS_OF(m); - rb_module_add_to_subclasses_list(m, iclass); - } + VALUE m = module; + if (BUILTIN_TYPE(m) == T_ICLASS) m = METACLASS_OF(m); + rb_module_add_to_subclasses_list(m, iclass); if (BUILTIN_TYPE(klass) == T_MODULE && FL_TEST(klass, RMODULE_IS_REFINEMENT)) { VALUE refined_class = diff --git a/test/ruby/test_super.rb b/test/ruby/test_super.rb index ce78e66c52..acc59c1520 100644 --- a/test/ruby/test_super.rb +++ b/test/ruby/test_super.rb @@ -617,6 +617,35 @@ class TestSuper < Test::Unit::TestCase } end + def test_super_with_included_prepended_module_method_caching_bug_20716 + a = Module.new do + def test(*args) + super + end + end + + b = Module.new do + def test(a) + a + end + end + + c = Class.new + + b.prepend(a) + c.include(b) + + assert_equal(1, c.new.test(1)) + + b.class_eval do + def test + :test + end + end + + assert_equal(:test, c.new.test) + end + class TestFor_super_with_modified_rest_parameter_base def foo *args args @@ -11,7 +11,7 @@ # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 5 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 106 +#define RUBY_PATCHLEVEL 107 #include "ruby/version.h" #include "ruby/internal/abi.h" |
