show warning for unused block

With verbopse mode (-w), the interpreter shows a warning if
a block is passed to a method which does not use the given block.

Warning on:

* the invoked method is written in C
* the invoked method is not `initialize`
* not invoked with `super`
* the first time on the call-site with the invoked method
  (`obj.foo{}` will be warned once if `foo` is same method)

[Feature #15554]

`Primitive.attr! :use_block` is introduced to declare that primitive
functions (written in C) will use passed block.

For minitest, test needs some tweak, so use
ea9caafc07
for `test-bundled-gems`.
This commit is contained in:
Koichi Sasada 2024-03-27 07:29:38 +09:00
parent 515e52a0b1
commit 9180e33ca3
18 changed files with 165 additions and 13 deletions

View file

@ -461,7 +461,7 @@ class OptionParser
candidates
end
def candidate(key, icase = false, pat = nil)
def candidate(key, icase = false, pat = nil, &_)
Completion.candidate(key, icase, pat, &method(:each))
end
@ -739,7 +739,7 @@ class OptionParser
#
# Raises an exception if argument is not present.
#
def parse(arg, argv)
def parse(arg, argv, &_)
unless arg
raise MissingArgument if argv.empty?
arg = argv.shift