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

Correct IO#{close_on_exec=, autoclose=, sync=} signatures #659

Merged
merged 3 commits into from
Apr 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/io.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class IO < Object
# # ...
# f.gets # won't cause Errno::EBADF
#
def autoclose=: (bool) -> bool
def autoclose=: (boolish) -> untyped

# Returns `true` if the underlying file descriptor of *ios* will be closed
# automatically at its finalization, otherwise `false`.
Expand Down Expand Up @@ -212,7 +212,7 @@ class IO < Object
# just ignored since Ruby 2.3.
def close: () -> NilClass

def close_on_exec=: (boolish) -> bool
def close_on_exec=: (boolish) -> untyped

# Returns `true` if *ios* will be closed on exec.
#
Expand Down Expand Up @@ -656,7 +656,7 @@ class IO < Object
# ```
def sync: () -> bool

def sync=: (boolish) -> bool
def sync=: (boolish) -> untyped

def sysread: (Integer maxlen, String outbuf) -> String

Expand Down
34 changes: 34 additions & 0 deletions test/stdlib/IO_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ def test_autoclose=
io, :autoclose=, true
assert_send_type "(bool) -> bool",
io, :autoclose=, false
assert_send_type "(::Integer) -> ::Integer",
io, :autoclose=, 42
assert_send_type "(nil) -> nil",
io, :autoclose=, nil
end
end

Expand Down Expand Up @@ -180,4 +184,34 @@ def test_write
end
end
end

def test_close_on_exec
IO.open(IO.sysopen(__FILE__)) do |io|
assert_send_type '() -> bool',
io, :close_on_exec?
assert_send_type '(::Integer) -> untyped',
Copy link
Member Author

Choose a reason for hiding this comment

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

Suggested change
assert_send_type '(::Integer) -> untyped',
assert_send_type '(::Integer) -> ::Integer',

When I write above, it fails.
I have issued it in https://bugs.ruby-lang.org/issues/17745 and ruby/ruby#4321.

io, :close_on_exec=, 42
assert_send_type '() -> bool',
io, :close_on_exec?
assert_send_type '(nil) -> nil',
io, :close_on_exec=, nil
assert_send_type '() -> bool',
io, :close_on_exec?
end
end

def test_sync
IO.open(IO.sysopen(__FILE__)) do |io|
assert_send_type '() -> bool',
io, :sync
assert_send_type '(::Integer) -> ::Integer',
io, :sync=, 42
assert_send_type '() -> bool',
io, :sync
assert_send_type '(nil) -> nil',
io, :sync=, nil
assert_send_type '() -> bool',
io, :sync
end
end
end