aboutsummaryrefslogtreecommitdiffstats
path: root/eval.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-29 08:54:18 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-29 08:54:18 +0000
commitc367128d2749e502ea903381c9322b3c227a04f6 (patch)
tree0bab9154493d606984eed3b553367a68cd641ce0 /eval.c
parent05f83d927ffc7432b75cedf1003196e67ff391d8 (diff)
downloadruby-c367128d2749e502ea903381c9322b3c227a04f6.tar.gz
eval.c: warn block for using
* eval.c (ignored_block): warn if a block is given to `using`, which is probably for `Module.new`. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53368 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'eval.c')
-rw-r--r--eval.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index f87be390f6..b9fcd86f5c 100644
--- a/eval.c
+++ b/eval.c
@@ -1273,6 +1273,16 @@ rb_mod_refine(VALUE module, VALUE klass)
return refinement;
}
+static void
+ignored_block(VALUE module, const char *klass)
+{
+ const char *anon = "";
+ if (!RTEST(rb_search_class_path(module))) {
+ anon = ", maybe for Module.new";
+ }
+ rb_warn("%s""using doesn't call the given block""%s.", klass, anon);
+}
+
/*
* call-seq:
* using(module) -> self
@@ -1293,6 +1303,9 @@ mod_using(VALUE self, VALUE module)
if (prev_cfp && prev_cfp->self != self) {
rb_raise(rb_eRuntimeError, "Module#using is not called on self");
}
+ if (rb_block_given_p()) {
+ ignored_block(module, "Module#");
+ }
rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
return self;
}
@@ -1426,6 +1439,9 @@ top_using(VALUE self, VALUE module)
if (CREF_NEXT(cref) || (prev_cfp && rb_vm_frame_method_entry(prev_cfp))) {
rb_raise(rb_eRuntimeError, "main.using is permitted only at toplevel");
}
+ if (rb_block_given_p()) {
+ ignored_block(module, "main.");
+ }
rb_using_module(rb_vm_cref_replace_with_duplicated_cref(), module);
return self;
}