sorbet-runtime 0.5.10482 → 0.5.10486

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: ed07fa0fde981e6d17b09b5eeccb79276a465b0351f33afa561c8850b1730fc0
4
+ data.tar.gz: 8a768cefc0f6d450e70e00f371d080a1ca0779db4cd842075df7bc4441a47956
5
5
  SHA512:
6
- metadata.gz: cc8ed0680a1176c3233b5d822f783d8127c576f1b5d7f873718ecd614268a662c464a5726cdc03175bedd7ad52f1b38adb35055592991754b8a6f111ba1204b7
7
- data.tar.gz: 2f04a8a52da91292768ef76300a9418dcdc07a6f52a65090918c91645aa3ccf5e1b512b3489029d3179b9243d3bf27e97dc87d6225df5a0c9898b568fd9670f8
6
+ metadata.gz: 9be6da68516debd7400d9fac4eecc17127c43cd9c5ab4a840d50a1be605682636de204ec0eb42285810c1e1cf482f384ccb8f3f1a20e90dff4de97c464e3df0e
7
+ data.tar.gz: 8f7be4209671446da710ceb9eb783bb07ff415bcd3a22deafb3ee71f153d9b06ab8683ec0d8df3b01b68da2ce5a730070560071a03b3fc9b042c45bdf49f0087
@@ -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.10486
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-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest