aboutsummaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-08 13:35:12 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-12-08 13:35:12 +0000
commitbdb8607cb7549f8555fed781392231ead86d984b (patch)
treedc4892223043d006fff5b6bf53d9a426d4fa3f60 /eval.c
parent537030e19b98cb99d161eff292a33fbdeea19a93 (diff)
downloadruby-bdb8607cb7549f8555fed781392231ead86d984b.tar.gz
* 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
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index 934037da91..d0dcdddc6b 100644
--- a/eval.c
+++ b/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();