зеркало из https://github.com/github/ruby.git
fix refinements/prepend bug
replaced method entry should be invalidated. [Bug #17386]
This commit is contained in:
Родитель
04d62e6f62
Коммит
cee02d754d
4
class.c
4
class.c
|
@ -1110,7 +1110,9 @@ move_refined_method(ID key, VALUE value, void *data)
|
|||
struct rb_id_table *tbl = RCLASS_M_TBL(klass);
|
||||
|
||||
if (me->def->type == VM_METHOD_TYPE_REFINED) {
|
||||
if (me->def->body.refined.orig_me) {
|
||||
rb_clear_method_cache(klass, me->called_id);
|
||||
|
||||
if (me->def->body.refined.orig_me) {
|
||||
const rb_method_entry_t *orig_me = me->def->body.refined.orig_me, *new_me;
|
||||
RB_OBJ_WRITE(me, &me->def->body.refined.orig_me, NULL);
|
||||
new_me = rb_method_entry_clone(me);
|
||||
|
|
|
@ -2446,4 +2446,31 @@ class TestRefinement < Test::Unit::TestCase
|
|||
def eval_using(mod, s)
|
||||
eval("using #{mod}; #{s}", Sandbox::BINDING)
|
||||
end
|
||||
|
||||
# [Bug #17386]
|
||||
def test_prepended_with_method_cache
|
||||
foo = Class.new do
|
||||
def foo
|
||||
:Foo
|
||||
end
|
||||
end
|
||||
|
||||
code = Module.new do
|
||||
def foo
|
||||
:Code
|
||||
end
|
||||
end
|
||||
|
||||
_ext = Module.new do
|
||||
refine foo do
|
||||
def foo; end
|
||||
end
|
||||
end
|
||||
|
||||
obj = foo.new
|
||||
|
||||
assert_equal :Foo, obj.foo
|
||||
foo.prepend code
|
||||
assert_equal :Code, obj.foo
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче