sorbet-runtime 0.6.13286 → 0.6.13293

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: e2b15b12f019d99d0883d3987d7bd205a368b8646b8c998328967023be62d8a1
4
- data.tar.gz: dbed6520ccd76a2ac122f63cfee589811b4ea570d72d994b0c6e1e2391640e8e
3
+ metadata.gz: 694b8ac11ca3cce9ba8e377eb454d8dc7f1d25a2260d918bbddf6439df4c9e25
4
+ data.tar.gz: 98d704c9f50db944ae0278296a5652cdf2c708c7719216ecb9107243a74d5d23
5
5
  SHA512:
6
- metadata.gz: a30b5d79bb6b5ae5dd11b6a82bdec010bb00ba90d386db70a9fa8ff191180e2a264f89243f45674a7db2d6f7c17f6856d6b32e0795cacb6717852c1e2a902c1a
7
- data.tar.gz: 69d156afa66059195cbc8cf6d5aad958cfc5132959fc18842716d8df563a4f08788e24fd9a43313ba7e667f4e81c30abed3e1aa03a90ee021d267d9061df9ba3
6
+ metadata.gz: c951c0ea164d0ec2c5a37d8a15e76efc269ae4543a4d421ac9fc81381544fb5bbaef1821bab98f9e79cc6cf5d98269e346847ccf385e8490cdab98ce1243a41e
7
+ data.tar.gz: 78c378b45c098585952a9b4b6048008a259b523ebd989d237e3b683094e9414868a1fe88b0ab75653e31f2ae78fcdf4013891d0c3c2620694144e2291fb55393
@@ -12,9 +12,17 @@ class T::Private::DeclState
12
12
 
13
13
  attr_accessor :active_declaration
14
14
  attr_accessor :skip_on_method_added
15
+ attr_accessor :previous_declaration
15
16
 
16
17
  def reset!
17
18
  self.active_declaration = nil
19
+ @previous_declaration = nil
20
+ end
21
+
22
+ def consume!
23
+ @previous_declaration = self.active_declaration
24
+ self.active_declaration = nil
25
+ @previous_declaration
18
26
  end
19
27
 
20
28
  def without_on_method_added
@@ -105,12 +105,17 @@ module T::Private::Methods
105
105
  #
106
106
  # we assume that source_method_names has already been filtered to only include method
107
107
  # names that were declared final at one point.
108
+ #
109
+ # Returns a boolean indicating whether it's okay to define any of `source_method_names` in `target`
110
+ # (e.g. true if no final method violations)
108
111
  def self._check_final_ancestors(target, source_method_names, source)
109
112
  source_ancestors = nil
110
113
  if T::Private::IS_TYPECHECKING
111
114
  # Need to avoid a pinning error, but don't want to use runtime types in _methods.rb
112
115
  source_ancestors = T.let(nil, T.nilable(T::Array[T::Module[T.anything]]))
116
+ found_error = T.let(false, T::Boolean)
113
117
  end
118
+ found_error = false
114
119
  # use reverse_each to check farther-up ancestors first, for better error messages.
115
120
  target.ancestors.reverse_each do |ancestor|
116
121
  final_methods = @modules_with_final.fetch(ancestor, nil)
@@ -142,6 +147,8 @@ module T::Private::Methods
142
147
  next if defining_ancestor_idx && source_ancestors[defining_ancestor_idx] == ancestor
143
148
  end
144
149
 
150
+ found_error = true
151
+
145
152
  final_sig = T::Private::Methods.signature_for_method(ancestor.instance_method(method_name))
146
153
  definition_file, definition_line = final_sig&.method&.source_location
147
154
  is_redefined = target == ancestor
@@ -158,19 +165,14 @@ module T::Private::Methods
158
165
  "#{extra_info}"
159
166
 
160
167
  begin
168
+ # raise + rescue to populate the backtrace
161
169
  raise pretty_message
162
170
  rescue => e
163
- # sig_validation_error_handler raises by default; on the off chance that
164
- # it doesn't raise, we need to ensure that the rest of signature building
165
- # sees a consistent state. This sig failed to validate, so we should get
166
- # rid of it. If we don't do this, errors of the form "You called sig
167
- # twice without declaring a method in between" will non-deterministically
168
- # crop up in tests.
169
- T::Private::DeclState.current.reset!
170
171
  T::Configuration.sig_validation_error_handler(e, {})
171
172
  end
172
173
  end
173
174
  end
175
+ !found_error
174
176
  end
175
177
 
176
178
  def self.add_module_with_final_method(mod, method_name)
@@ -192,23 +194,22 @@ module T::Private::Methods
192
194
  return
193
195
  end
194
196
 
195
- current_declaration = T::Private::DeclState.current.active_declaration
197
+ current_declaration = T::Private::DeclState.current.consume!
196
198
 
197
199
  if T::Private::Final.final_module?(mod) && (current_declaration.nil? || !current_declaration.final)
198
200
  raise "#{mod} was declared as final but its method `#{method_name}` was not declared as final"
199
201
  end
200
202
  # Don't compute mod.ancestors if we don't need to bother checking final-ness.
201
- if @was_ever_final_names.include?(method_name) && @modules_with_final.include?(mod)
202
- _check_final_ancestors(mod, [method_name], nil)
203
- # We need to fetch the active declaration again, as _check_final_ancestors
204
- # may have reset it (see the comment in that method for details).
205
- current_declaration = T::Private::DeclState.current.active_declaration
203
+ if @was_ever_final_names.include?(method_name) && @modules_with_final.include?(mod) &&
204
+ !_check_final_ancestors(mod, [method_name], nil)
205
+ # We want to pretend like the method did not have a sig, so return.
206
+ # (This code is not dead, because some `sig_validation_error_handler`'s do not raise.)
207
+ return
206
208
  end
207
209
 
208
210
  if current_declaration.nil?
209
211
  return
210
212
  end
211
- T::Private::DeclState.current.reset!
212
213
 
213
214
  if method_name == :method_added || method_name == :singleton_method_added
214
215
  raise(
@@ -471,12 +472,22 @@ module T::Private::Methods
471
472
  end
472
473
 
473
474
  def self.run_all_sig_blocks(force_type_init: true)
475
+ current_declaration = T::Private::DeclState.current.active_declaration
476
+ if !current_declaration.nil?
477
+ T::Private::DeclState.current.reset!
478
+ raise "Cannot call `run_all_sig_blocks` while there is a pending `sig` block in #{current_declaration.mod} at #{current_declaration.loc}"
479
+ end
480
+
474
481
  loop do
475
482
  first_wrapper = @sig_wrappers.first
476
483
  break unless first_wrapper
477
484
  key, = first_wrapper
478
485
  run_sig_block_for_key(key, force_type_init: force_type_init)
479
486
  end
487
+
488
+ # Make sure that there are no lingering declaration blocks being kept alive
489
+ # (so we're not retaining any extra references for a possible GC)
490
+ T::Private::DeclState.current.reset!
480
491
  end
481
492
 
482
493
  def self.all_checked_tests_sigs
@@ -507,6 +518,7 @@ module T::Private::Methods
507
518
  end
508
519
 
509
520
  _check_final_ancestors(target, methods, source)
521
+ nil
510
522
  end
511
523
 
512
524
  def self.set_final_checks_on_hooks(enable)
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.6.13286
4
+ version: 0.6.13293
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-06-06 00:00:00.000000000 Z
11
+ date: 2026-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: benchmark