Repository navigation
TCPServer.new takes a nil host and a String port - #3274
Open
hasannadeem wants to merge 1 commit into
Open
hasannadeem wants to merge 1 commit into
hasannadeem wants to merge 1 commit into
Conversation
TCPServer.new([hostname,] port) passes both arguments to getaddrinfo,
so the host can be nil and the port can be a String, either a number
or a service name. The signature only allowed a String host and an
Integer port, so calls such as TCPServer.new(nil, 0) and
TCPServer.new("127.0.0.1", "8080") didn't type-check.
Allow String? for the host and Integer | String for the port, return
void from initialize, and add TCPServerSingletonTest#test_new.
Fixes ruby#1671
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1671.
TCPServer.new([hostname,] port)passes both arguments to getaddrinfo, so the host can beniland the port can be a String, either a number or a service name:All four work in Ruby, but the signature was
(?String host, Integer port) -> untyped. This changes it to(?String? host, Integer | String port) -> void, and addsTCPServerSingletonTest#test_newfor each of these calls. With the old signature the test fails at the first String port ("Call trace does not match one of method definitions"). With the new one it passes, and so do the other socket tests andNet_HTTP_test.rb.rbs validateand rubocop pass too (Ruby 3.4.4).I kept to the common types and left out some rarer ones Ruby also accepts: an Integer IPv4 address as the host,
to_strobjects, and anilport. Ato_intport is rejected by Ruby (no implicit conversion of Object into String), so::intwould be wrong for the port.The rest of the socket signatures, such as
TCPSocket#initializeandSocket.tcp_server_loop, also type ports asIntegeronly. I haven't changed those here, to keep this to the method in the issue.