Skip to content

Commit

Permalink
Merge pull request #659 from kachick/accurate-some-io-attr_setters
Browse files Browse the repository at this point in the history
Correct IO#{close_on_exec=, autoclose=, sync=} signatures
  • Loading branch information
soutaro committed Apr 21, 2021
2 parents f928d0f + 2c20223 commit 66913e9
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
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',
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

0 comments on commit 66913e9

Please sign in to comment.