Skip to content

Prevent warnings "the block passed to ... may be ignored" #11611

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ext/socket/lib/socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -648,11 +648,11 @@ class << self
# sock.close_write
# puts sock.read
# }
def self.tcp(host, port, local_host = nil, local_port = nil, connect_timeout: nil, resolv_timeout: nil, fast_fallback: tcp_fast_fallback, &block) # :yield: socket
def self.tcp(host, port, local_host = nil, local_port = nil, connect_timeout: nil, resolv_timeout: nil, fast_fallback: tcp_fast_fallback, &) # :yield: socket
sock = if fast_fallback && !(host && ip_address?(host))
tcp_with_fast_fallback(host, port, local_host, local_port, connect_timeout:, resolv_timeout:, &block)
tcp_with_fast_fallback(host, port, local_host, local_port, connect_timeout:, resolv_timeout:)
else
tcp_without_fast_fallback(host, port, local_host, local_port, connect_timeout:, resolv_timeout:, &block)
tcp_without_fast_fallback(host, port, local_host, local_port, connect_timeout:, resolv_timeout:)
end

if block_given?
Expand Down Expand Up @@ -897,7 +897,7 @@ def self.tcp_with_fast_fallback(host, port, local_host = nil, local_port = nil,
end
end

def self.tcp_without_fast_fallback(host, port, local_host, local_port, connect_timeout:, resolv_timeout:, &block)
def self.tcp_without_fast_fallback(host, port, local_host, local_port, connect_timeout:, resolv_timeout:)
last_error = nil
ret = nil

Expand Down
19 changes: 18 additions & 1 deletion test/ruby/test_call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,24 @@
require '-test-/iter'

class TestCall < Test::Unit::TestCase
def aaa(a, b=100, *rest)
# These dummy method definitions prevent warnings "the block passed to 'a'..."
def a(&) = nil
def b(&) = nil
def c(&) = nil
def d(&) = nil
def e(&) = nil
def f(&) = nil
def g(&) = nil
def h(&) = nil
def i(&) = nil
def j(&) = nil
def k(&) = nil
def l(&) = nil
def m(&) = nil
def n(&) = nil
def o(&) = nil

def aaa(a, b=100, *rest, &)
res = [a, b]
res += rest if rest
return res
Expand Down
16 changes: 15 additions & 1 deletion test/ruby/test_iterator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,13 @@ def m2
end

def test_block_given
verbose_bak, $VERBOSE = $VERBOSE, nil
assert(m1{p 'test'})
assert(m2{p 'test'})
assert(!m1())
assert(!m2())
ensure
$VERBOSE = verbose_bak
end

def m3(var, &block)
Expand Down Expand Up @@ -308,7 +311,18 @@ def test_proc_return2

def test_ljump
assert_raise(LocalJumpError) {get_block{break}.call}
assert_raise(LocalJumpError) {proc_call2(get_block{break}){}}
begin
verbose_bak, $VERBOSE = $VERBOSE, nil
# See the commit https://github.com/ruby/ruby/commit/7d8a415bc2d08a1b5e9d1ea802493b6eeb99c219
# This block is not used but this is intentional.
# |
# +-----------------------------------------------------+
# |
# vv
assert_raise(LocalJumpError) {proc_call2(get_block{break}){}}
ensure
$VERBOSE = verbose_bak
end

# cannot use assert_nothing_raised due to passing block.
begin
Expand Down
3 changes: 3 additions & 0 deletions test/ruby/test_proc.rb
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,13 @@ def test_method_to_proc
end

def test_block_given_method
verbose_bak, $VERBOSE = $VERBOSE, nil
m = method(:m_block_given?)
assert(!m.call, "without block")
assert(m.call {}, "with block")
assert(!m.call, "without block second")
ensure
$VERBOSE = verbose_bak
end

def test_block_given_method_to_proc
Expand Down
4 changes: 2 additions & 2 deletions test/ruby/test_syntax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1387,7 +1387,7 @@ def test_cmdarg_in_paren

def test_block_after_cmdarg_in_paren
bug11873 = '[ruby-core:72482] [Bug #11873]'
def bug11873.p(*);end;
def bug11873.p(*, &);end;

assert_raise(LocalJumpError, bug11873) do
bug11873.instance_eval do
Expand Down Expand Up @@ -2256,7 +2256,7 @@ def with_script_lines
end
end

def caller_lineno(*)
def caller_lineno(*, &)
caller_locations(1, 1)[0].lineno
end
end