sorbet-runtime 0.5.10482 → 0.5.10484

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11da160a81fa962524ac56b89430caafbd63dce3004e6be72f969e68d4ed325f
4
- data.tar.gz: d7756592877242c01a10bd6196cd51fbffa4137bc953187e8e75743c4b5793f6
3
+ metadata.gz: 0261ceb29d9d188006f2790e6cf0a498278b8a5ad762b1a7a8cb073d934b1c8d
4
+ data.tar.gz: 449461ef6ec91785cf3dbfd5fdbb13ac1380f28acbb827817d103d022d6d5420
5
5
  SHA512:
6
- metadata.gz: cc8ed0680a1176c3233b5d822f783d8127c576f1b5d7f873718ecd614268a662c464a5726cdc03175bedd7ad52f1b38adb35055592991754b8a6f111ba1204b7
7
- data.tar.gz: 2f04a8a52da91292768ef76300a9418dcdc07a6f52a65090918c91645aa3ccf5e1b512b3489029d3179b9243d3bf27e97dc87d6225df5a0c9898b568fd9670f8
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(&current_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 but there is a single parameter with a missing name
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
- writer_method = declared_param_names != [nil] && parameters == [[:req]] && method_name[-1] == "="
65
- # For writer methods, map the single parameter to the method name without the "=" at the end
66
- parameters = [[:req, method_name[0...-1].to_sym]] if writer_method
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.10482
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-08 00:00:00.000000000 Z
11
+ date: 2022-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest