зеркало из https://github.com/github/ruby.git
Prevent warnings "the block passed to ... may be ignored"
This commit is contained in:
Родитель
b6c7226fac
Коммит
0f3dc2f958
|
@ -648,11 +648,11 @@ class Socket < BasicSocket
|
|||
# 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?
|
||||
|
@ -897,7 +897,7 @@ class Socket < BasicSocket
|
|||
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
|
||||
|
||||
|
|
|
@ -3,7 +3,24 @@ require 'test/unit'
|
|||
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
|
||||
|
|
|
@ -175,10 +175,13 @@ class TestIterator < Test::Unit::TestCase
|
|||
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)
|
||||
|
@ -308,7 +311,18 @@ class TestIterator < Test::Unit::TestCase
|
|||
|
||||
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
|
||||
|
|
|
@ -207,10 +207,13 @@ class TestProc < Test::Unit::TestCase
|
|||
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
|
||||
|
|
|
@ -1387,7 +1387,7 @@ eom
|
|||
|
||||
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
|
||||
|
@ -2256,7 +2256,7 @@ eom
|
|||
end
|
||||
end
|
||||
|
||||
def caller_lineno(*)
|
||||
def caller_lineno(*, &)
|
||||
caller_locations(1, 1)[0].lineno
|
||||
end
|
||||
end
|
||||
|
|
Загрузка…
Ссылка в новой задаче