ruby-changes:26217
From: shugo <ko1@a...>
Date: Sat, 8 Dec 2012 22:36:54 +0900 (JST)
Subject: [ruby-changes:26217] shugo:r38274 (trunk): * eval.c (top_using): raise a RuntimeError if using is called in a
shugo 2012-12-08 22:35:12 +0900 (Sat, 08 Dec 2012) New Revision: 38274 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38274 Log: * eval.c (top_using): raise a RuntimeError if using is called in a module definition or a method definition. * test/ruby/test_refinement.rb: related test. Modified files: trunk/ChangeLog trunk/eval.c trunk/test/ruby/test_refinement.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 38273) +++ ChangeLog (revision 38274) @@ -1,3 +1,10 @@ +Sat Dec 8 13:17:55 2012 Shugo Maeda <shugo@r...> + + * eval.c (top_using): raise a RuntimeError if using is called in a + module definition or a method definition. + + * test/ruby/test_refinement.rb: related test. + Sat Dec 8 15:01:35 2012 Eric Hodel <drbrain@s...> * lib/rubygems/commands/cleanup_command.rb: Skip default gems when Index: eval.c =================================================================== --- eval.c (revision 38273) +++ eval.c (revision 38274) @@ -1393,7 +1393,11 @@ top_using(VALUE self, VALUE module) { NODE *cref = rb_vm_cref(); + rb_control_frame_t *prev_cfp = previous_frame(GET_THREAD()); + if (cref->nd_next || (prev_cfp && prev_cfp->me)) { + rb_raise(rb_eRuntimeError, "using is permitted only at toplevel"); + } Check_Type(module, T_MODULE); rb_using_module(cref, module); rb_clear_cache(); Index: test/ruby/test_refinement.rb =================================================================== --- test/ruby/test_refinement.rb (revision 38273) +++ test/ruby/test_refinement.rb (revision 38274) @@ -624,6 +624,33 @@ end end + def test_using_in_module + assert_raise(RuntimeError) do + eval(<<-EOF, TOPLEVEL_BINDING) + $main = self + module M + end + module M2 + $main.send(:using, M) + end + EOF + end + end + + def test_using_in_method + assert_raise(RuntimeError) do + eval(<<-EOF, TOPLEVEL_BINDING) + $main = self + module M + end + def call_using_in_method + $main.send(:using, M) + end + call_using_in_method + EOF + end + end + private def eval_using(mod, s) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/