Skip to content

Conversation

@ko1
Copy link
Contributor

@ko1 ko1 commented Apr 17, 2024

if a method foo uses a block, other (unrelated) method foo can receives a block. So try to relax the unused block warning condition.

      class C0
        def f = yield
      end

      class C1 < C0
        def f = nil
      end

      [C0, C1].f{ block } # do not warn

if a method `foo` uses a block, other (unrelated) method `foo`
can receives a block. So try to relax the unused block warning
condition.

```ruby
      class C0
        def f = yield
      end

      class C1 < C0
        def f = nil
      end

      [C0, C1].f{ block } # do not warn
```
@ko1 ko1 enabled auto-merge (rebase) April 17, 2024 11:05
@ko1 ko1 merged commit e9d7478 into ruby:master Apr 17, 2024
def f = nil
end
C1.new.f{} # do not warn on duck typing
Copy link
Member

@eregon eregon Apr 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this warn?
Because this call site never uses C0#f, and even more C0#f has never been called.
So I think this is warning too little.

From your example at https://bugs.ruby-lang.org/issues/15554#note-29 I thought the logic is "if at a call site we noticed one of the called methods accepts a block, then we don't warn if later methods don't accept a block". I think that's fair, but it is of course order-dependent and would still warn if the method not accepting a block is called first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An idea to address the order could be to print these warnings only on process exit, then the order wouldn't matter, as long as one call at a given call site would be to a method accepting a block it wouldn't warn, but would warn if none of them used the block, even if there are other methods of the same name defined as accepting a block.

yahonda added a commit to yahonda/rails that referenced this pull request May 17, 2024
ruby/ruby#10403 raised many "the block passed to" warnings.
then idnored these warnings because some of them might have contain false positives.

Now we can restore the warning condition
because these false positives should have been addressed by these changes:

ruby/ruby#10559
rails#51597
rails#51583
yahonda added a commit to yahonda/rails that referenced this pull request May 17, 2024
ruby/ruby#10403 raised many "the block passed to" warnings.
then idnored these warnings because some of them might have contain false positives.

Now we can restore the warning condition
because these false positives should have been addressed by these changes:

ruby/ruby#10559
rails#51597
rails#51583
xjunior pushed a commit to xjunior/rails that referenced this pull request Jun 9, 2024
ruby/ruby#10403 raised many "the block passed to" warnings.
then idnored these warnings because some of them might have contain false positives.

Now we can restore the warning condition
because these false positives should have been addressed by these changes:

ruby/ruby#10559
rails#51597
rails#51583
Set2005 pushed a commit to Set2005/fix-association-initialize-order that referenced this pull request Jul 8, 2024
ruby/ruby#10403 raised many "the block passed to" warnings.
then idnored these warnings because some of them might have contain false positives.

Now we can restore the warning condition
because these false positives should have been addressed by these changes:

ruby/ruby#10559
rails#51597
rails#51583
DanielaVelasquez pushed a commit to DanielaVelasquez/rails that referenced this pull request Oct 3, 2024
ruby/ruby#10403 raised many "the block passed to" warnings.
then idnored these warnings because some of them might have contain false positives.

Now we can restore the warning condition
because these false positives should have been addressed by these changes:

ruby/ruby#10559
rails#51597
rails#51583
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants