diff options
author | Koichi Sasada <[email protected]> | 2024-11-06 03:41:59 +0900 |
---|---|---|
committer | Koichi Sasada <[email protected]> | 2024-11-06 11:06:18 +0900 |
commit | ab7ab9e4508c24b998703824aa9576fb2e092065 (patch) | |
tree | 27baa0a69fbdc59f54bf0526dde4c8c299ccbf82 /include | |
parent | 4203c70dfa96649bae305350817d7cc3c9bc5888 (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 'include')
-rw-r--r-- | include/ruby/internal/error.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/include/ruby/internal/error.h b/include/ruby/internal/error.h index cd37f4461a..3ff885b2b1 100644 --- a/include/ruby/internal/error.h +++ b/include/ruby/internal/error.h @@ -53,6 +53,9 @@ typedef enum { /** Warning is for performance issues (not enabled by -w). */ RB_WARN_CATEGORY_PERFORMANCE, + /** Warning is for checking unused block strictly */ + RB_WARN_CATEGORY_STRICT_UNUSED_BLOCK, + RB_WARN_CATEGORY_DEFAULT_BITS = ( (1U << RB_WARN_CATEGORY_DEPRECATED) | (1U << RB_WARN_CATEGORY_EXPERIMENTAL) | @@ -62,6 +65,7 @@ typedef enum { (1U << RB_WARN_CATEGORY_DEPRECATED) | (1U << RB_WARN_CATEGORY_EXPERIMENTAL) | (1U << RB_WARN_CATEGORY_PERFORMANCE) | + (1U << RB_WARN_CATEGORY_STRICT_UNUSED_BLOCK) | 0) } rb_warning_category_t; |