mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
class.c: prohibit refinement module
* class.c (ensure_includable): cannot include refinement module, or the type and the class do not match. [ruby-core:79632] [Bug #13236] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58083 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
19a1f70364
commit
217f599a1e
2 changed files with 17 additions and 0 deletions
3
class.c
3
class.c
|
@ -854,6 +854,9 @@ ensure_includable(VALUE klass, VALUE module)
|
|||
{
|
||||
rb_frozen_class_p(klass);
|
||||
Check_Type(module, T_MODULE);
|
||||
if (!NIL_P(rb_refinement_module_get_refined_class(module))) {
|
||||
rb_raise(rb_eArgError, "refinement module is not allowed");
|
||||
}
|
||||
OBJ_INFECT(klass, module);
|
||||
}
|
||||
|
||||
|
|
|
@ -1886,6 +1886,20 @@ class TestRefinement < Test::Unit::TestCase
|
|||
assert_equal("Parent -> Child", SuperToModule::Child.test, bug)
|
||||
end
|
||||
|
||||
def test_include_refinement
|
||||
bug = '[ruby-core:79632] [Bug #13236] cannot include refinement module'
|
||||
r = nil
|
||||
m = Module.new do
|
||||
r = refine(String) {def test;:ok end}
|
||||
end
|
||||
assert_raise_with_message(ArgumentError, /refinement/, bug) do
|
||||
m.module_eval {include r}
|
||||
end
|
||||
assert_raise_with_message(ArgumentError, /refinement/, bug) do
|
||||
m.module_eval {prepend r}
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def eval_using(mod, s)
|
||||
|
|
Loading…
Reference in a new issue