sorbet-runtime 0.5.12214 → 0.5.12219

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16a0c060e90e301e158fb992f5e30dd165de9d924e09a84afee967472738d2e7
4
- data.tar.gz: b8647ade48a60151f782da8191652b5b091e5a01e9a96fae14986aaa203846e8
3
+ metadata.gz: 1f6086643f7a3f4f05ef2d0dbf300335b0944ffd4c216d7dd2e24c83851887ce
4
+ data.tar.gz: 8f327ece9b13165973052513a3c8c8d9c90e9769f06d2ddc31344d6830bc503d
5
5
  SHA512:
6
- metadata.gz: c88768de97137ffca384ed5d658270c5cc3b502c7b16c5d320479265cf2885d3064852157bdd6589caff1904e1cee20681bf96a64e381fe2bb44aaa438b882b1
7
- data.tar.gz: d5aa9e02d8d2fa3d0948663ef053075a61b237a27ffd82e64f93a08ec6544f4aee1e64040e02f032a33227ec0880037fbbf40a78b390c5e8864e06a9217e8da0
6
+ metadata.gz: 2992e679ddef4c96ad7916e088d76125ce9d50d727ef44c0476f5ddd628110644506c3497b2c16dddc3ff30b73d6344ea41fe02c6617b0ffaf793400de3d2073
7
+ data.tar.gz: '0648ef93b75218013bf5347e5bd2abeaac496f1290803cd97f4e33fd59a67ab76186f359b7842c9387bd84055ee93acba131877d4e291d65147fa042df569ef7'
@@ -589,6 +589,22 @@ module T::Private::Methods
589
589
  mod.extend(SingletonMethodHooks)
590
590
  end
591
591
 
592
+ # `name` must be an instance method (for class methods, pass in mod.singleton_class)
593
+ def self.visibility_method_name(mod, name)
594
+ if mod.public_method_defined?(name)
595
+ :public
596
+ elsif mod.protected_method_defined?(name)
597
+ :protected
598
+ elsif mod.private_method_defined?(name)
599
+ :private
600
+ else
601
+ # Raises a NameError formatted like the Ruby VM would (the exact text formatting
602
+ # of these errors changed across Ruby VM versions, in ways that would sometimes
603
+ # cause tests to fail if they were dependent on hard coding errors).
604
+ mod.method(name)
605
+ end
606
+ end
607
+
592
608
  # use this directly if you don't want/need to box up the method into an object to pass to method_to_key.
593
609
  private_class_method def self.method_owner_and_name_to_key(owner, name)
594
610
  "#{owner.object_id}##{name}"
@@ -12,7 +12,7 @@ module T::Private::Methods::CallValidation
12
12
  # @param method_sig [T::Private::Methods::Signature]
13
13
  # @return [UnboundMethod] the new wrapper method (or the original one if we didn't wrap it)
14
14
  def self.wrap_method_if_needed(mod, method_sig, original_method)
15
- original_visibility = visibility_method_name(mod, method_sig.method_name)
15
+ original_visibility = T::Private::Methods.visibility_method_name(mod, method_sig.method_name)
16
16
  if method_sig.mode == T::Private::Methods::Modes.abstract
17
17
  create_abstract_wrapper(mod, method_sig, original_method, original_visibility)
18
18
  # Do nothing in this case; this method was not wrapped in _on_method_added.
@@ -330,19 +330,6 @@ module T::Private::Methods::CallValidation
330
330
  location: caller_loc
331
331
  )
332
332
  end
333
-
334
- # `name` must be an instance method (for class methods, pass in mod.singleton_class)
335
- private_class_method def self.visibility_method_name(mod, name)
336
- if mod.public_method_defined?(name)
337
- :public
338
- elsif mod.protected_method_defined?(name)
339
- :protected
340
- elsif mod.private_method_defined?(name)
341
- :private
342
- else
343
- mod.method(name) # Raises
344
- end
345
- end
346
333
  end
347
334
 
348
335
  if T::Configuration::AT_LEAST_RUBY_2_7
@@ -89,6 +89,7 @@ module T::Private::Methods::SignatureValidation
89
89
  validate_override_mode(signature, super_signature)
90
90
  validate_override_shape(signature, super_signature)
91
91
  validate_override_types(signature, super_signature)
92
+ validate_override_visibility(signature, super_signature)
92
93
  end
93
94
  else
94
95
  validate_non_override_mode(signature)
@@ -276,6 +277,38 @@ module T::Private::Methods::SignatureValidation
276
277
  end
277
278
  end
278
279
 
280
+ def self.validate_override_visibility(signature, super_signature)
281
+ return if super_signature.mode == Modes.untyped
282
+ # This departs from the behavior of other `validate_override_whatever` functions in that it
283
+ # only comes into effect when the child signature explicitly says the word `override`. This was
284
+ # done because the primary method for silencing these errors (`allow_incompatible: :visibility`)
285
+ # requires an `override` node to attach to. Once we have static override checking for implicitly
286
+ # overridden methods, we can remove this.
287
+ return unless [Modes.override, Modes.overridable_override].include?(signature.mode)
288
+ return if [:visibility, true].include?(signature.override_allow_incompatible)
289
+ method = signature.method
290
+ super_method = super_signature.method
291
+ mode_noun = super_signature.mode == Modes.abstract ? 'implementation' : 'override'
292
+ vis = method_visibility(method)
293
+ super_vis = method_visibility(super_method)
294
+
295
+ if visibility_strength(vis) > visibility_strength(super_vis)
296
+ raise "Incompatible visibility for #{mode_noun} of method #{method.name}\n" \
297
+ "* Base: #{super_vis} (in #{method_loc_str(super_method)})\n" \
298
+ "* #{mode_noun.capitalize}: #{vis} (in #{method_loc_str(method)})\n" \
299
+ "(The override must be at least as permissive as the supermethod)" \
300
+ end
301
+ end
302
+
303
+ private_class_method def self.method_visibility(method)
304
+ T::Private::Methods.visibility_method_name(method.owner, method.name)
305
+ end
306
+
307
+ # Higher = more restrictive.
308
+ private_class_method def self.visibility_strength(vis)
309
+ %i[public protected private].find_index(vis)
310
+ end
311
+
279
312
  private_class_method def self.base_override_loc_str(signature, super_signature)
280
313
  mode_noun = super_signature.mode == Modes.abstract ? 'Implementation' : 'Override'
281
314
  "\n * Base definition: in #{method_loc_str(super_signature.method)}" \
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.12214
4
+ version: 0.5.12219
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-07-01 00:00:00.000000000 Z
11
+ date: 2025-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest