Skip to content

Commit

Permalink
Add positional hash parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Jan 24, 2025
1 parent fdba897 commit 1ce65bd
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 3 deletions.
4 changes: 2 additions & 2 deletions stdlib/net-http/0/net-http.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -978,8 +978,8 @@ module Net
# Note: If `port` is `nil` and `opts[:use_ssl]` is a truthy value, the value
# passed to `new` is Net::HTTP.https_default_port, not `port`.
#
def self.start: (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, **untyped opt) -> Net::HTTP
| [T] (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, **untyped opt) { (Net::HTTP) -> T } -> T
def self.start: (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, ?Hash[Symbol, untyped]?, **untyped opt) -> Net::HTTP
| [T] (String address, ?Integer? port, ?String | :ENV | nil p_addr, ?Integer? p_port, ?String? p_user, ?String? p_pass, ?Hash[Symbol, untyped]?, **untyped opt) { (Net::HTTP) -> T } -> T

# <!--
# rdoc-file=lib/net/http.rb
Expand Down
7 changes: 6 additions & 1 deletion test/stdlib/Net_HTTP_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,12 @@ def test_start
Net::HTTP, :start, 'www.ruby-lang.org', 80 do |net_http| net_http.class end
assert_send_type "(String, Integer, use_ssl: bool) { (Net::HTTP) -> untyped } -> untyped",
Net::HTTP, :start, 'www.ruby-lang.org', 443, use_ssl: true do |net_http| net_http.class end
end

assert_send_type(
"(String, Integer, nil, nil, nil, nil, Hash[Symbol, untyped]) { (Net::HTTP) -> Class } -> Class",
Net::HTTP, :start, 'www.ruby-lang.org', 443, nil, nil, nil, nil, { use_ssl: true }, &->(net_http) { net_http.class }
)
end
end

class NetInstanceTest < Test::Unit::TestCase
Expand Down
8 changes: 8 additions & 0 deletions test/typecheck/net_http/Steepfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
D = Steep::Diagnostic

target :test do
signature "."
check "."
library "net-http"
configure_code_diagnostics(D::Ruby.all_error)
end
5 changes: 5 additions & 0 deletions test/typecheck/net_http/start.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Passing keyword args is allowed.
Net::HTTP.start('example.com', open_timeout: 10)

# Passing a hash object is also allowed, but it needs the predecessor arguments.
Net::HTTP.start('example.com', 443, nil, nil, nil, nil, { open_timeout: 10, read_timeout: 10 })

0 comments on commit 1ce65bd

Please sign in to comment.