diff options
author | Yusuke Endoh <[email protected]> | 2024-09-13 13:48:51 +0900 |
---|---|---|
committer | Yusuke Endoh <[email protected]> | 2024-09-13 16:52:38 +0900 |
commit | 0f3dc2f958bd1447cc459bc4a4f39071a6a07a9c (patch) | |
tree | 18778bfcd6c52ff80ad05d6e2cf5bd7b5bb6ffd9 | |
parent | b6c7226facc140bf8976d48fbd6c06f729534379 (diff) |
Prevent warnings "the block passed to ... may be ignored"
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11611
-rw-r--r-- | ext/socket/lib/socket.rb | 8 | ||||
-rw-r--r-- | test/ruby/test_call.rb | 19 | ||||
-rw-r--r-- | test/ruby/test_iterator.rb | 16 | ||||
-rw-r--r-- | test/ruby/test_proc.rb | 3 | ||||
-rw-r--r-- | test/ruby/test_syntax.rb | 4 |
5 files changed, 42 insertions, 8 deletions
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb index 86f2a523eb..d61de1e8e9 100644 --- a/ext/socket/lib/socket.rb +++ b/ext/socket/lib/socket.rb @@ -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 diff --git a/test/ruby/test_call.rb b/test/ruby/test_call.rb index 14847bf629..b7d62ae111 100644 --- a/test/ruby/test_call.rb +++ b/test/ruby/test_call.rb @@ -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 diff --git a/test/ruby/test_iterator.rb b/test/ruby/test_iterator.rb index 820d5591c1..1bb655d52e 100644 --- a/test/ruby/test_iterator.rb +++ b/test/ruby/test_iterator.rb @@ -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 diff --git a/test/ruby/test_proc.rb b/test/ruby/test_proc.rb index 2f91da8aa8..192955c60a 100644 --- a/test/ruby/test_proc.rb +++ b/test/ruby/test_proc.rb @@ -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 diff --git a/test/ruby/test_syntax.rb b/test/ruby/test_syntax.rb index bd15d7c9f3..fe6fa30e02 100644 --- a/test/ruby/test_syntax.rb +++ b/test/ruby/test_syntax.rb @@ -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 |