Skip to content

Commit

Permalink
do not show unused block on send
Browse files Browse the repository at this point in the history
Some case it is difficult to know the calling method uses a block
or not with `send` on a general framework. So this patch stops
showing unused block warning on `send`.

example with test/unit:

```ruby
require 'test/unit'

class T < Test::Unit::TestCase
  def setup
  end

  def test_foo = nil
end

```

Maybe we can show the warning again when we provide a way to recognize
the calling method uses a block or not.
  • Loading branch information
ko1 committed Aug 9, 2024
1 parent f57167d commit b84fd5e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions test/ruby/test_method.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1645,15 +1645,15 @@ def test_warn_unused_block
assert_in_out_err '-w', <<-'RUBY' do |_out, err, _status|
def foo = nil
foo{} # warn
send(:foo){} # warn
send(:foo){} # don't warn because it uses send
b = Proc.new{}
foo(&b) # warn
RUBY
assert_equal 3, err.size
err = err.join
assert_match(/-:2: warning/, err)
assert_match(/-:3: warning/, err)
assert_match(/-:5: warning/, err)
errstr = err.join("\n")
assert_equal 2, err.size, errstr

assert_match(/-:2: warning/, errstr)
assert_match(/-:5: warning/, errstr)
end

assert_in_out_err '-w', <<-'RUBY' do |_out, err, _status|
Expand Down
2 changes: 1 addition & 1 deletion vm_insnhelper.c
Original file line number Diff line number Diff line change
Expand Up @@ -3090,7 +3090,7 @@ vm_callee_setup_arg(rb_execution_context_t *ec, struct rb_calling_info *calling,

if (UNLIKELY(!ISEQ_BODY(iseq)->param.flags.use_block &&
calling->block_handler != VM_BLOCK_HANDLER_NONE &&
!(vm_ci_flag(calling->cd->ci) & VM_CALL_SUPER))) {
!(vm_ci_flag(calling->cd->ci) & (VM_CALL_OPT_SEND | VM_CALL_SUPER)))) {
warn_unused_block(vm_cc_cme(cc), iseq, (void *)ec->cfp->pc);
}

Expand Down

0 comments on commit b84fd5e

Please sign in to comment.