Fix UNIXSocket#send_io and recv_io types#2264
Merged
pocke merged 3 commits intoruby:masterfrom Feb 20, 2025
Merged
Conversation
pocke
commented
Jan 31, 2025
| alias to_i fileno | ||
|
|
||
| interface _ForFd[RET] | ||
| def for_fd: (?) -> RET |
Member
Author
There was a problem hiding this comment.
The argument is rough.
Actually, the definition should be the following:
interface _ForFd[MODE, RET]
def for_fd: (Integer fd, ?MODE) -> RET
endBut the definition is wrong because the following class does not match the interface.
class ForFd
def self.for_fd: (Integer fd) -> instance
endI think it's difficult to define strict type, so ? is acceptable for this case.
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.
This PR fixes the method type definitions for
UNIXSocket#{send_io,recv_io}.send_io
https://docs.ruby-lang.org/en/3.3/UNIXSocket.html#method-i-send_io
send_ioactually receives an IO, but the type definition only acceptsBasicSocket, which is a subclass ofIO. So I fixed it to allowIO.recv_io
https://docs.ruby-lang.org/en/3.3/UNIXSocket.html#method-i-recv_io
It's a bit complex. It has three patterns.
IO.Integerclass or nil, it returns an Integer.for_fdmethod, it calls this method and returns the returned value offor_fd.for_fdis the file descripter. The second argument ismode, and the second argument ofrecv_io.