Skip to content

Fix UNIXSocket#send_io and recv_io types#2264

Merged
pocke merged 3 commits intoruby:masterfrom
pocke:Fix_UNIXSocket_send_io_and_recv_io_types
Feb 20, 2025
Merged

Fix UNIXSocket#send_io and recv_io types#2264
pocke merged 3 commits intoruby:masterfrom
pocke:Fix_UNIXSocket_send_io_and_recv_io_types

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.

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.

@soutaro soutaro added this to the RBS 3.9 milestone Feb 19, 2025
Copy link
Member

@soutaro soutaro left a comment

Choose a reason for hiding this comment

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

👍

@pocke pocke added this pull request to the merge queue Feb 20, 2025
Merged via the queue into ruby:master with commit 0ddf214 Feb 20, 2025
19 checks passed
@pocke pocke deleted the Fix_UNIXSocket_send_io_and_recv_io_types branch February 20, 2025 02:10
@soutaro soutaro added the Released PRs already included in the released version label Mar 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Released PRs already included in the released version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants