summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-13 11:10:24 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-09-13 11:10:24 (GMT)
commit384fda18b885872aacf225ac6ad7805fb101e497 (patch)
tree4ce162ac23bd0b9a6e78a1f3c82fa57ea97480bf /enum.c
parentcff6bdfcba57995e1879c7a2003f9949aec29632 (diff)
warn unused blocks with Enumerable#all? any? one? none?
[Fix GH-1953] From: Koji Onishi <fursich0@gmail.com> git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64733 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/enum.c b/enum.c
index 293ddd4..127b839 100644
--- a/enum.c
+++ b/enum.c
@@ -1212,6 +1212,12 @@ name##_eqq(RB_BLOCK_CALL_FUNC_ARGLIST(i, memo)) \
static VALUE \
enum_##name##_func(VALUE result, struct MEMO *memo)
+#define WARN_UNUSED_BLOCK(argc) do { \
+ if ((argc) > 0 && rb_block_given_p()) { \
+ rb_warn("given block not used"); \
+ } \
+} while (0)
+
DEFINE_ENUMFUNCS(all)
{
if (!RTEST(result)) {
@@ -1249,6 +1255,7 @@ static VALUE
enum_all(int argc, VALUE *argv, VALUE obj)
{
struct MEMO *memo = MEMO_ENUM_NEW(Qtrue);
+ WARN_UNUSED_BLOCK(argc);
rb_block_call(obj, id_each, 0, 0, ENUMFUNC(all), (VALUE)memo);
return memo->v1;
}
@@ -1290,6 +1297,7 @@ static VALUE
enum_any(int argc, VALUE *argv, VALUE obj)
{
struct MEMO *memo = MEMO_ENUM_NEW(Qfalse);
+ WARN_UNUSED_BLOCK(argc);
rb_block_call(obj, id_each, 0, 0, ENUMFUNC(any), (VALUE)memo);
return memo->v1;
}
@@ -1557,6 +1565,7 @@ enum_one(int argc, VALUE *argv, VALUE obj)
struct MEMO *memo = MEMO_ENUM_NEW(Qundef);
VALUE result;
+ WARN_UNUSED_BLOCK(argc);
rb_block_call(obj, id_each, 0, 0, ENUMFUNC(one), (VALUE)memo);
result = memo->v1;
if (result == Qundef) return Qfalse;
@@ -1598,6 +1607,8 @@ static VALUE
enum_none(int argc, VALUE *argv, VALUE obj)
{
struct MEMO *memo = MEMO_ENUM_NEW(Qtrue);
+
+ WARN_UNUSED_BLOCK(argc);
rb_block_call(obj, id_each, 0, 0, ENUMFUNC(none), (VALUE)memo);
return memo->v1;
}