[前][次][番号順一覧][スレッド一覧]

ruby-changes:41296

From: nobu <ko1@a...>
Date: Tue, 29 Dec 2015 17:54:27 +0900 (JST)
Subject: [ruby-changes:41296] nobu:r53368 (trunk): eval.c: warn block for using

nobu	2015-12-29 17:54:18 +0900 (Tue, 29 Dec 2015)

  New Revision: 53368

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53368

  Log:
    eval.c: warn block for using
    
    * eval.c (ignored_block): warn if a block is given to `using`,
      which is probably for `Module.new`.

  Modified files:
    trunk/ChangeLog
    trunk/eval.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 53367)
+++ ChangeLog	(revision 53368)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Dec 29 17:54:16 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* eval.c (ignored_block): warn if a block is given to `using`,
+	  which is probably for `Module.new`.
+
 Tue Dec 29 12:48:34 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* lib/ostruct.rb (OpenStruct): make respond_to? working on
Index: eval.c
===================================================================
--- eval.c	(revision 53367)
+++ eval.c	(revision 53368)
@@ -1273,6 +1273,16 @@ rb_mod_refine(VALUE module, VALUE klass) https://github.com/ruby/ruby/blob/trunk/eval.c#L1273
     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) https://github.com/ruby/ruby/blob/trunk/eval.c#L1303
     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) https://github.com/ruby/ruby/blob/trunk/eval.c#L1439
     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;
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]