summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorKoichi Sasada <[email protected]>2024-11-06 03:41:59 +0900
committerKoichi Sasada <[email protected]>2024-11-06 11:06:18 +0900
commitab7ab9e4508c24b998703824aa9576fb2e092065 (patch)
tree27baa0a69fbdc59f54bf0526dde4c8c299ccbf82 /compile.c
parent4203c70dfa96649bae305350817d7cc3c9bc5888 (diff)
`Warning[:strict_unused_block]`
to show unused block warning strictly. ```ruby class C def f = nil end class D def f = yield end [C.new, D.new].each{|obj| obj.f{}} ``` In this case, `D#f` accepts a block. However `C#f` doesn't accept a block. There are some cases passing a block with `obj.f{}` where `obj` is `C` or `D`. To avoid warnings on such cases, "unused block warning" will be warned only if there is not same name which accepts a block. On the above example, `C.new.f{}` doesn't show any warnings because there is a same name `D#f` which accepts a block. We call this default behavior as "relax mode". `strict_unused_block` new warning category changes from "relax mode" to "strict mode", we don't check same name methods and `C.new.f{}` will be warned. [Feature #15554]
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/12005
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/compile.c b/compile.c
index d1c86b3427..e777fba89a 100644
--- a/compile.c
+++ b/compile.c
@@ -2007,7 +2007,7 @@ iseq_set_use_block(rb_iseq_t *iseq)
rb_vm_t *vm = GET_VM();
- if (!vm->unused_block_warning_strict) {
+ if (!rb_warning_category_enabled_p(RB_WARN_CATEGORY_STRICT_UNUSED_BLOCK)) {
st_data_t key = (st_data_t)rb_intern_str(body->location.label); // String -> ID
st_insert(vm->unused_block_warning_table, key, 1);
}