sorbet-runtime 0.5.10813 → 0.5.10818
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/types/private/methods/signature.rb +22 -16
- data/lib/types/private/types/not_typed.rb +2 -0
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ddfd9761a4a88233877d8cbfe25d3e5bd257c1e4ea7497c255bec6c7d5897e3a
|
|
4
|
+
data.tar.gz: 38ed467519b492e37c20b4c8a8c051731deec8b2fc561508fbe1506a8c4aae15
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9eeaf99c28f740abab40b839a0c70185891e2c0565d095b762664000ad0ed34effab6ce909c5b7e9c87ac37e7b8f7acb72c3ec62f4e79ef619981b0cfd581cfd
|
|
7
|
+
data.tar.gz: f2f55b4b4c85c23e31914c5b73692adebf64330ae8c0ca4ce3cab2190cea328f0cece749884e2a5a6aba8d7dd92636a8bf2e9fec6f7ab8cd7005330cd8ab7839
|
|
@@ -8,19 +8,19 @@ class T::Private::Methods::Signature
|
|
|
8
8
|
:check_level, :parameters, :on_failure, :override_allow_incompatible,
|
|
9
9
|
:defined_raw
|
|
10
10
|
|
|
11
|
-
SIG_EMPTY_DECLARED_PARAMETERS = [nil].freeze
|
|
12
11
|
UNNAMED_REQUIRED_PARAMETERS = [[:req]].freeze
|
|
13
12
|
|
|
14
13
|
def self.new_untyped(method:, mode: T::Private::Methods::Modes.untyped, parameters: method.parameters)
|
|
15
|
-
# Using `
|
|
16
|
-
not_typed = T::Private::Types::NotTyped
|
|
14
|
+
# Using `NotTyped` ensures we'll get an error if we ever try validation on these.
|
|
15
|
+
not_typed = T::Private::Types::NotTyped::INSTANCE
|
|
17
16
|
raw_return_type = not_typed
|
|
18
17
|
# Map missing parameter names to "argN" positionally
|
|
19
18
|
parameters = parameters.each_with_index.map do |(param_kind, param_name), index|
|
|
20
19
|
[param_kind, param_name || "arg#{index}"]
|
|
21
20
|
end
|
|
22
|
-
raw_arg_types =
|
|
23
|
-
|
|
21
|
+
raw_arg_types = {}
|
|
22
|
+
parameters.each do |_, param_name|
|
|
23
|
+
raw_arg_types[param_name] = not_typed
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
self.new(
|
|
@@ -60,21 +60,23 @@ class T::Private::Methods::Signature
|
|
|
60
60
|
@override_allow_incompatible = override_allow_incompatible
|
|
61
61
|
@defined_raw = defined_raw
|
|
62
62
|
|
|
63
|
-
declared_param_names = raw_arg_types.keys
|
|
64
63
|
# If sig params are declared but there is a single parameter with a missing name
|
|
65
64
|
# **and** the method ends with a "=", assume it is a writer method generated
|
|
66
65
|
# by attr_writer or attr_accessor
|
|
67
|
-
writer_method =
|
|
66
|
+
writer_method = !(raw_arg_types.size == 1 && raw_arg_types.key?(nil)) && parameters == UNNAMED_REQUIRED_PARAMETERS && method_name[-1] == "="
|
|
68
67
|
# For writer methods, map the single parameter to the method name without the "=" at the end
|
|
69
68
|
parameters = [[:req, method_name[0...-1].to_sym]] if writer_method
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
is_name_missing = parameters.any? {|_, name| !raw_arg_types.key?(name)}
|
|
70
|
+
if is_name_missing
|
|
71
|
+
param_names = parameters.map {|_, name| name}
|
|
72
|
+
missing_names = param_names - raw_arg_types.keys
|
|
73
73
|
raise "The declaration for `#{method.name}` is missing parameter(s): #{missing_names.join(', ')}"
|
|
74
|
-
elsif
|
|
74
|
+
elsif parameters.length == raw_arg_types.size
|
|
75
75
|
else
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
param_names = parameters.map {|_, name| name}
|
|
77
|
+
has_extra_names = parameters.count {|_, name| raw_arg_types.key?(name)} < raw_arg_types.size
|
|
78
|
+
if has_extra_names
|
|
79
|
+
extra_names = raw_arg_types.keys - param_names
|
|
78
80
|
raise "The declaration for `#{method.name}` has extra parameter(s): #{extra_names.join(', ')}"
|
|
79
81
|
end
|
|
80
82
|
end
|
|
@@ -82,8 +84,10 @@ class T::Private::Methods::Signature
|
|
|
82
84
|
if parameters.size != raw_arg_types.size
|
|
83
85
|
raise "The declaration for `#{method.name}` has arguments with duplicate names"
|
|
84
86
|
end
|
|
87
|
+
i = 0
|
|
88
|
+
raw_arg_types.each do |type_name, raw_type|
|
|
89
|
+
param_kind, param_name = parameters[i]
|
|
85
90
|
|
|
86
|
-
parameters.zip(raw_arg_types) do |(param_kind, param_name), (type_name, raw_type)|
|
|
87
91
|
if type_name != param_name
|
|
88
92
|
hint = ""
|
|
89
93
|
# Ruby reorders params so that required keyword arguments
|
|
@@ -97,8 +101,8 @@ class T::Private::Methods::Signature
|
|
|
97
101
|
end
|
|
98
102
|
|
|
99
103
|
raise "Parameter `#{type_name}` is declared out of order (declared as arg number " \
|
|
100
|
-
"#{
|
|
101
|
-
"#{
|
|
104
|
+
"#{i + 1}, defined in the method as arg number " \
|
|
105
|
+
"#{parameters.index {|_, name| name == type_name} + 1}).#{hint}\nMethod: #{method_desc}"
|
|
102
106
|
end
|
|
103
107
|
|
|
104
108
|
type = T::Utils.coerce(raw_type)
|
|
@@ -139,6 +143,8 @@ class T::Private::Methods::Signature
|
|
|
139
143
|
else
|
|
140
144
|
raise "Unexpected param_kind: `#{param_kind}`. Method: #{method_desc}"
|
|
141
145
|
end
|
|
146
|
+
|
|
147
|
+
i += 1
|
|
142
148
|
end
|
|
143
149
|
end
|
|
144
150
|
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sorbet-runtime
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.5.
|
|
4
|
+
version: 0.5.10818
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stripe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2023-05-
|
|
11
|
+
date: 2023-05-11 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|