sorbet-runtime 0.5.5846 → 0.5.5859
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/_methods.rb +50 -16
- data/lib/types/private/methods/signature.rb +7 -6
- data/lib/types/types/simple.rb +5 -1
- 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: b26613ee717e93406be9863f6de88ba9ed7d56be71c14e5b9a0f6dea865f6bbd
|
4
|
+
data.tar.gz: 7c52bb7c5ea5624c002a69e6f38c02f64cdf4f1f1b7b0b03a90093511cac169c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce4dcea125090bb935cfe36e7d2c4c6421a4011b135a4c6f2eed4526c814b385d491f2e846629335181af9ec6f39fe7a2046d8333b971698e4a83f14397a3340
|
7
|
+
data.tar.gz: 3b3d85510672d63af66e8603e848e98e4d8c1305e8946acc4a58b21079cbab63a510884e521cc744ba72d1136e7de10bb6d685eaade360af9f03e8fb50579a77
|
@@ -206,22 +206,12 @@ module T::Private::Methods
|
|
206
206
|
# (or unwrap back to the original method).
|
207
207
|
new_method = nil
|
208
208
|
T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
if new_method == new_new_method
|
216
|
-
raise "`sig` not present for method `#{method_name}` but you're trying to run it anyways. " \
|
217
|
-
"This should only be executed if you used `alias_method` to grab a handle to a method after `sig`ing it, but that clearly isn't what you are doing. " \
|
218
|
-
"Maybe look to see if an exception was thrown in your `sig` lambda or somehow else your `sig` wasn't actually applied to the method. " \
|
219
|
-
"Contact #dev-productivity if you're really stuck."
|
220
|
-
end
|
221
|
-
return new_new_method.bind(self).call(*args, &blk)
|
222
|
-
end
|
223
|
-
|
224
|
-
method_sig = T::Private::Methods.run_sig_block_for_method(new_method)
|
209
|
+
method_sig = T::Private::Methods.maybe_run_sig_block_for_method(new_method)
|
210
|
+
method_sig ||= T::Private::Methods._handle_missing_method_signature(
|
211
|
+
self,
|
212
|
+
original_method,
|
213
|
+
__callee__,
|
214
|
+
)
|
225
215
|
|
226
216
|
# Should be the same logic as CallValidation.wrap_method_if_needed but we
|
227
217
|
# don't want that extra layer of indirection in the callstack
|
@@ -252,6 +242,50 @@ module T::Private::Methods
|
|
252
242
|
end
|
253
243
|
end
|
254
244
|
|
245
|
+
def self._handle_missing_method_signature(receiver, original_method, callee)
|
246
|
+
method_sig = T::Private::Methods.signature_for_method(original_method)
|
247
|
+
if !method_sig
|
248
|
+
raise "`sig` not present for method `#{callee}` on #{receiver.inspect} but you're trying to run it anyways. " \
|
249
|
+
"This should only be executed if you used `alias_method` to grab a handle to a method after `sig`ing it, but that clearly isn't what you are doing. " \
|
250
|
+
"Maybe look to see if an exception was thrown in your `sig` lambda or somehow else your `sig` wasn't actually applied to the method."
|
251
|
+
end
|
252
|
+
|
253
|
+
if receiver.class <= original_method.owner
|
254
|
+
receiving_class = receiver.class
|
255
|
+
elsif receiver.singleton_class <= original_method.owner
|
256
|
+
receiving_class = receiver.singleton_class
|
257
|
+
elsif receiver.is_a?(Module) && receiver <= original_method.owner
|
258
|
+
receiving_class = receiver
|
259
|
+
else
|
260
|
+
raise "#{receiver} is not related to #{original_method} - how did we get here?"
|
261
|
+
end
|
262
|
+
|
263
|
+
# Check for a case where `alias` or `alias_method` was called for a
|
264
|
+
# method which had already had a `sig` applied. In that case, we want
|
265
|
+
# to avoid hitting this slow path again, by moving to a faster validator
|
266
|
+
# just like we did or will for the original method.
|
267
|
+
#
|
268
|
+
# If this isn't an `alias` or `alias_method` case, we're probably in the
|
269
|
+
# middle of some metaprogramming using a Method object, e.g. a pattern like
|
270
|
+
# `arr.map(&method(:foo))`. There's nothing really we can do to optimize
|
271
|
+
# that here.
|
272
|
+
receiving_method = receiving_class.instance_method(callee)
|
273
|
+
if receiving_method != original_method && receiving_method.original_name == original_method.name
|
274
|
+
aliasing_mod = receiving_method.owner
|
275
|
+
|
276
|
+
# Note, this logic is duplicated above, make sure to keep changes in sync.
|
277
|
+
if method_sig.check_level == :always || (method_sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
|
278
|
+
# Checked, so copy the original signature to the aliased copy.
|
279
|
+
T::Private::Methods.unwrap_method(aliasing_mod, method_sig, original_method)
|
280
|
+
else
|
281
|
+
# Unchecked, so just make `alias_method` behave as if it had been called pre-sig.
|
282
|
+
aliasing_mod.send(:alias_method, callee, original_method.name)
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
method_sig
|
287
|
+
end
|
288
|
+
|
255
289
|
# Executes the `sig` block, and converts the resulting Declaration
|
256
290
|
# to a Signature.
|
257
291
|
def self.run_sig(hook_mod, method_name, original_method, declaration_block)
|
@@ -146,9 +146,10 @@ class T::Private::Methods::Signature
|
|
146
146
|
# can't) match the definition of the method we're validating. In addition, Ruby has a bug that
|
147
147
|
# causes forwarding **kwargs to do the wrong thing: see https://bugs.ruby-lang.org/issues/10708
|
148
148
|
# and https://bugs.ruby-lang.org/issues/11860.
|
149
|
-
|
149
|
+
args_length = args.length
|
150
|
+
if (args_length > @req_arg_count) && (!@kwarg_types.empty? || @has_keyrest) && args[-1].is_a?(Hash)
|
150
151
|
kwargs = args[-1]
|
151
|
-
|
152
|
+
args_length -= 1
|
152
153
|
else
|
153
154
|
kwargs = EMPTY_HASH
|
154
155
|
end
|
@@ -156,19 +157,19 @@ class T::Private::Methods::Signature
|
|
156
157
|
arg_types = @arg_types
|
157
158
|
|
158
159
|
if @has_rest
|
159
|
-
arg_types += [[@rest_name, @rest_type]] * (
|
160
|
+
arg_types += [[@rest_name, @rest_type]] * (args_length - @arg_types.length)
|
160
161
|
|
161
|
-
elsif (
|
162
|
+
elsif (args_length < @req_arg_count) || (args_length > @arg_types.length)
|
162
163
|
expected_str = @req_arg_count.to_s
|
163
164
|
if @arg_types.length != @req_arg_count
|
164
165
|
expected_str += "..#{@arg_types.length}"
|
165
166
|
end
|
166
|
-
raise ArgumentError.new("wrong number of arguments (given #{
|
167
|
+
raise ArgumentError.new("wrong number of arguments (given #{args_length}, expected #{expected_str})")
|
167
168
|
end
|
168
169
|
|
169
170
|
begin
|
170
171
|
it = 0
|
171
|
-
while it <
|
172
|
+
while it < args_length
|
172
173
|
yield arg_types[it][0], args[it], arg_types[it][1]
|
173
174
|
it += 1
|
174
175
|
end
|
data/lib/types/types/simple.rb
CHANGED
@@ -12,7 +12,11 @@ module T::Types
|
|
12
12
|
|
13
13
|
# @override Base
|
14
14
|
def name
|
15
|
-
|
15
|
+
# Memoize to mitigate pathological performance with anonymous modules (https://bugs.ruby-lang.org/issues/11119)
|
16
|
+
#
|
17
|
+
# `name` isn't normally a hot path for types, but it is used in initializing a T::Types::Union,
|
18
|
+
# and so in `T.nilable`, and so in runtime constructions like `x = T.let(nil, T.nilable(Integer))`.
|
19
|
+
@name ||= @raw_type.name.freeze
|
16
20
|
end
|
17
21
|
|
18
22
|
# @override Base
|
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.5859
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|