diff options
author | Jeremy Evans <[email protected]> | 2019-06-10 15:47:56 -0700 |
---|---|---|
committer | Jeremy Evans <[email protected]> | 2019-06-11 09:43:38 -0700 |
commit | 5e018214e7435030727a97ac49db038d96438e74 (patch) | |
tree | 34be111eb4b7c27c61049ed392f6c7f1302145ed | |
parent | 4f9e7c95e4c8216c17f46747092f28df9c54fab7 (diff) |
Fix SystemStackError when calling a method in an unused refinement
Fixes [Bug #15720]
-rw-r--r-- | test/ruby/test_refinement.rb | 32 | ||||
-rw-r--r-- | vm_insnhelper.c | 5 |
2 files changed, 36 insertions, 1 deletions
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 7d47a52982..59029de890 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -2242,6 +2242,38 @@ class TestRefinement < Test::Unit::TestCase INPUT end + def test_call_method_in_unused_refinement + bug15720 = '[ruby-core:91916] [Bug #15720]' + assert_in_out_err([], <<-INPUT, ["ok"], [], bug15720) + module M1 + refine Kernel do + def foo + 'foo called!' + end + end + end + + module M2 + refine Kernel do + def bar + 'bar called!' + end + end + end + + using M1 + + foo + + begin + bar + rescue NameError + end + + puts "ok" + INPUT + end + def test_super_from_refined_module a = EnvUtil.labeled_module("A") do def foo;"[A#{super}]";end diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 523ac71f42..93b1ebfe7a 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -2635,7 +2635,10 @@ vm_call_method_each_type(rb_execution_context_t *ec, rb_control_frame_t *cfp, st goto no_refinement_dispatch; } } - cc->me = ref_me; + if (cc->me->def->type != VM_METHOD_TYPE_REFINED || + cc->me->def != ref_me->def) { + cc->me = ref_me; + } if (ref_me->def->type != VM_METHOD_TYPE_REFINED) { return vm_call_method(ec, cfp, calling, ci, cc); } |