зеркало из https://github.com/github/ruby.git
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38274 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
537030e19b
Коммит
bdb8607cb7
|
@ -1,3 +1,10 @@
|
|||
Sat Dec 8 13:17:55 2012 Shugo Maeda <shugo@ruby-lang.org>
|
||||
|
||||
* 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@segment7.net>
|
||||
|
||||
* lib/rubygems/commands/cleanup_command.rb: Skip default gems when
|
||||
|
|
4
eval.c
4
eval.c
|
@ -1393,7 +1393,11 @@ static VALUE
|
|||
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();
|
||||
|
|
|
@ -624,6 +624,33 @@ class TestRefinement < Test::Unit::TestCase
|
|||
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)
|
||||
|
|
Загрузка…
Ссылка в новой задаче