Skip to content
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

Fix UNIXSocket#send_io and recv_io types #2264

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

pocke
Copy link
Member

@pocke pocke commented Jan 31, 2025

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_io actually receives an IO, but the type definition only accepts BasicSocket, which is a subclass of IO. So I fixed it to allow IO.

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.

  • Without argument, it returns an IO.
  • With the Integer class or nil, it returns an Integer.
  • With any object having for_fd method, it calls this method and returns the returned value of for_fd.
    • The first argument of for_fd is the file descripter. The second argument is mode, and the second argument of recv_io.

@@ -3251,6 +3251,10 @@ class IO < Object
# f.close
#
alias to_i fileno

interface _ForFd[RET]
def for_fd: (?) -> RET
Copy link
Member Author

@pocke pocke Jan 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The argument is rough.

Actually, the definition should be the following:

interface _ForFd[MODE, RET]
  def for_fd: (Integer fd, ?MODE) -> RET
end

But the definition is wrong because the following class does not match the interface.

class ForFd
  def self.for_fd: (Integer fd) -> instance
end

I think it's difficult to define strict type, so ? is acceptable for this case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant