ruby-changes:46012
From: nobu <ko1@a...>
Date: Sat, 25 Mar 2017 12:23:48 +0900 (JST)
Subject: [ruby-changes:46012] nobu:r58083 (trunk): class.c: prohibit refinement module
nobu 2017-03-25 12:23:43 +0900 (Sat, 25 Mar 2017) New Revision: 58083 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58083 Log: 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] Modified files: trunk/class.c trunk/test/ruby/test_refinement.rb Index: class.c =================================================================== --- class.c (revision 58082) +++ class.c (revision 58083) @@ -854,6 +854,9 @@ ensure_includable(VALUE klass, VALUE mod https://github.com/ruby/ruby/blob/trunk/class.c#L854 { 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); } Index: test/ruby/test_refinement.rb =================================================================== --- test/ruby/test_refinement.rb (revision 58082) +++ test/ruby/test_refinement.rb (revision 58083) @@ -1886,6 +1886,20 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L1886 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/