sorbet-runtime 0.5.5855 → 0.5.5865
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 +33 -23
- data/lib/types/private/methods/signature.rb +9 -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: 356642261e3c9f5451beb62ee6fd4cd4e4a346b2686954ce87fe60df0796013a
|
4
|
+
data.tar.gz: f9884e720101c6ec2f90601ea470ae36dc4afc4728ff5015a088bb6cc063782a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98a17fa21e3662b1b1c7c0626faa39a3dcb4f5b45059cc3f891ecfecb51a5556279e21e70f1f8aadb394786ed874f74ef577bc145fe8e0d4450efc4c6a4b3cfc
|
7
|
+
data.tar.gz: 50ebe42e01b78d7d390c55dbb50f439818470b022bdf8293a0dc903584456becee442654c052f65096e7247e5881b777efd37a91ab64138af7de08160b40cc98
|
@@ -208,7 +208,7 @@ module T::Private::Methods
|
|
208
208
|
T::Private::ClassUtils.replace_method(mod, method_name) do |*args, &blk|
|
209
209
|
method_sig = T::Private::Methods.maybe_run_sig_block_for_method(new_method)
|
210
210
|
method_sig ||= T::Private::Methods._handle_missing_method_signature(
|
211
|
-
|
211
|
+
self,
|
212
212
|
original_method,
|
213
213
|
__callee__,
|
214
214
|
)
|
@@ -242,30 +242,40 @@ module T::Private::Methods
|
|
242
242
|
end
|
243
243
|
end
|
244
244
|
|
245
|
-
def self._handle_missing_method_signature(
|
245
|
+
def self._handle_missing_method_signature(receiver, original_method, callee)
|
246
246
|
method_sig = T::Private::Methods.signature_for_method(original_method)
|
247
|
-
|
248
|
-
|
249
|
-
aliasing_mod = aliasing_method.owner
|
250
|
-
|
251
|
-
if method_sig && aliasing_method != original_method && aliasing_method.original_name == original_method.name
|
252
|
-
# We're handling a case where `alias` or `alias_method` was called for a
|
253
|
-
# method which had already had a `sig` applied.
|
254
|
-
#
|
255
|
-
# Note, this logic is duplicated above, make sure to keep changes in sync.
|
256
|
-
if method_sig.check_level == :always || (method_sig.check_level == :tests && T::Private::RuntimeLevels.check_tests?)
|
257
|
-
# Checked, so copy the original signature to the aliased copy.
|
258
|
-
T::Private::Methods.unwrap_method(aliasing_mod, method_sig, aliasing_method)
|
259
|
-
else
|
260
|
-
# Unchecked, so just make `alias_method` behave as if it had been called pre-sig.
|
261
|
-
aliasing_mod.send(:alias_method, callee, original_method.name)
|
262
|
-
end
|
263
|
-
else
|
264
|
-
raise "`sig` not present for method `#{aliasing_method.name}` but you're trying to run it anyways. " \
|
247
|
+
if !method_sig
|
248
|
+
raise "`sig` not present for method `#{callee}` on #{receiver.inspect} but you're trying to run it anyways. " \
|
265
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. " \
|
266
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."
|
267
251
|
end
|
268
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
|
+
method_sig = method_sig.as_alias(callee)
|
276
|
+
unwrap_method(aliasing_mod, method_sig, original_method)
|
277
|
+
end
|
278
|
+
|
269
279
|
method_sig
|
270
280
|
end
|
271
281
|
|
@@ -287,7 +297,7 @@ module T::Private::Methods
|
|
287
297
|
Signature.new_untyped(method: original_method)
|
288
298
|
end
|
289
299
|
|
290
|
-
unwrap_method(
|
300
|
+
unwrap_method(signature.method.owner, signature, original_method)
|
291
301
|
signature
|
292
302
|
end
|
293
303
|
|
@@ -339,8 +349,8 @@ module T::Private::Methods
|
|
339
349
|
end
|
340
350
|
end
|
341
351
|
|
342
|
-
def self.unwrap_method(
|
343
|
-
maybe_wrapped_method = CallValidation.wrap_method_if_needed(
|
352
|
+
def self.unwrap_method(mod, signature, original_method)
|
353
|
+
maybe_wrapped_method = CallValidation.wrap_method_if_needed(mod, signature, original_method)
|
344
354
|
@signatures_by_method[method_to_key(maybe_wrapped_method)] = signature
|
345
355
|
end
|
346
356
|
|
@@ -121,6 +121,15 @@ class T::Private::Methods::Signature
|
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
|
+
attr_writer :method_name
|
125
|
+
protected :method_name=
|
126
|
+
|
127
|
+
def as_alias(alias_name)
|
128
|
+
new_sig = clone
|
129
|
+
new_sig.method_name = alias_name
|
130
|
+
new_sig
|
131
|
+
end
|
132
|
+
|
124
133
|
def arg_count
|
125
134
|
@arg_types.length
|
126
135
|
end
|
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.5865
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stripe
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07
|
11
|
+
date: 2020-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|