sorbet-runtime 0.5.10482 → 0.5.10484
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 +30 -0
- data/lib/types/private/methods/signature.rb +7 -5
- 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: 0261ceb29d9d188006f2790e6cf0a498278b8a5ad762b1a7a8cb073d934b1c8d
|
|
4
|
+
data.tar.gz: 449461ef6ec91785cf3dbfd5fdbb13ac1380f28acbb827817d103d022d6d5420
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 89f0ebffb1702107a27381bb89315c1ff88877d6a179ece0165852fda9029ad5b7b6d1554bef45cfd024ad3182479ae4111bd8d998d4a24419903189f5737ab4
|
|
7
|
+
data.tar.gz: a37894b38cb7a26517e253bab1e477925bda7196dc78cdf799d080385f8ce31cdb94e87a14f4f5dbe7e1448e794dac0cd29d263b4070e3c764b618dcbd100186
|
|
@@ -204,6 +204,34 @@ module T::Private::Methods
|
|
|
204
204
|
@modules_with_final[mod.singleton_class.object_id]
|
|
205
205
|
end
|
|
206
206
|
|
|
207
|
+
private_class_method def self.attr_accessor_reader?(method_name)
|
|
208
|
+
# If the method name ends with a "=", it's definitely not an attr_accessor reader
|
|
209
|
+
return false if method_name[-1] == "="
|
|
210
|
+
|
|
211
|
+
# If it was "attr_accessor" that triggered this, we should be 3 frames away from it:
|
|
212
|
+
# 3. `attr_accessor`
|
|
213
|
+
# 2. method_added hook
|
|
214
|
+
# 1. `_on_method_added`
|
|
215
|
+
# 0. `attr_accessor_reader?`
|
|
216
|
+
caller_frame = caller_locations(3, 1).first
|
|
217
|
+
return false unless caller_frame
|
|
218
|
+
|
|
219
|
+
caller_label = caller_frame.label
|
|
220
|
+
return false unless caller_label
|
|
221
|
+
|
|
222
|
+
caller_label.to_s == "attr_accessor"
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
private_class_method def self.declare_writer_sig_from_reader(method_name, current_declaration)
|
|
226
|
+
writer_decl = current_declaration.dup
|
|
227
|
+
# The block for the reader runs the block for the writer,
|
|
228
|
+
# but also adds the writer param with the same type as the return type.
|
|
229
|
+
writer_decl.blk = lambda do
|
|
230
|
+
instance_exec(¤t_declaration.blk).params(**{method_name.to_sym => decl.returns})
|
|
231
|
+
end
|
|
232
|
+
T::Private::DeclState.current.active_declaration = writer_decl
|
|
233
|
+
end
|
|
234
|
+
|
|
207
235
|
# Only public because it needs to get called below inside the replace_method blocks below.
|
|
208
236
|
def self._on_method_added(hook_mod, method_name, is_singleton_method: false)
|
|
209
237
|
if T::Private::DeclState.current.skip_on_method_added
|
|
@@ -229,6 +257,8 @@ module T::Private::Methods
|
|
|
229
257
|
end
|
|
230
258
|
T::Private::DeclState.current.reset!
|
|
231
259
|
|
|
260
|
+
declare_writer_sig_from_reader(method_name, current_declaration) if attr_accessor_reader?(method_name)
|
|
261
|
+
|
|
232
262
|
if method_name == :method_added || method_name == :singleton_method_added
|
|
233
263
|
raise(
|
|
234
264
|
"Putting a `sig` on `#{method_name}` is not supported" \
|
|
@@ -58,12 +58,14 @@ class T::Private::Methods::Signature
|
|
|
58
58
|
@defined_raw = defined_raw
|
|
59
59
|
|
|
60
60
|
declared_param_names = raw_arg_types.keys
|
|
61
|
-
# If sig params are declared
|
|
61
|
+
# If sig params are declared and there is a single parameter with a missing name
|
|
62
62
|
# **and** the method ends with a "=", assume it is a writer method generated
|
|
63
|
-
# by attr_writer or attr_accessor
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
# by attr_writer or attr_accessor.
|
|
64
|
+
# We fix up the parameter name in that case to be the method name without the "=".
|
|
65
|
+
if declared_param_names != [nil] && parameters == [[:req]] && method_name[-1] == "="
|
|
66
|
+
parameters = [[:req, method_name[0...-1].to_sym]]
|
|
67
|
+
end
|
|
68
|
+
|
|
67
69
|
param_names = parameters.map {|_, name| name}
|
|
68
70
|
missing_names = param_names - declared_param_names
|
|
69
71
|
extra_names = declared_param_names - param_names
|
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.10484
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Stripe
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2022-10-
|
|
11
|
+
date: 2022-10-12 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|