sorbet-runtime 0.4.4472 → 0.4.4475

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
  SHA1:
3
- metadata.gz: f8a8b4923b8931649dd95fa7f039ba848b84990d
4
- data.tar.gz: e2bfc998f4b1312b920cc9232d9d99a3dff221dd
3
+ metadata.gz: a5727cbfa118b02720b1f3da2109beee29cf1b67
4
+ data.tar.gz: 0b623c19e8d55101802f76519b96b1a029f0b377
5
5
  SHA512:
6
- metadata.gz: 717fc4d69f03393e336ccd00d204a750ba99cd2085214d90344b8c453a5686b313cb6ca6db787cd7e1f8faae56d8c3b210b20ec1dde90f8da32f210d1ecac9bf
7
- data.tar.gz: 8208290e9829296a7e3a900991ed1f17f28f94948972668c0ad9e14c7cd000c0cd5edb230f3c2fcff8d63e22089b8f44a8b5d9c6d5803633b17e5e8e31341b6f
6
+ metadata.gz: 49bff1319ddf918e15f48259afd4a411583384810e4f03cad56cc2ac8a70b864f22e318faa124c402792594da7054b8e1eec7854fece8a20ae90775a47e6c9cd
7
+ data.tar.gz: 37a01bdeb5d6792737bf44d54e4a6135a9bd0e4f54f854bda52605e293f5ab6ad6c32d3f27e774739c32eca38e06e15c0fbcab5f4752e46a295bad075c5bb38f
@@ -32,14 +32,14 @@ module T::Configuration
32
32
  # def foo; end
33
33
  # end
34
34
  # ```
35
- def self.enable_final_checks_for_include_extend
36
- T::Private::Methods.set_final_checks_for_include_extend(true)
35
+ def self.enable_final_checks_on_hooks
36
+ T::Private::Methods.set_final_checks_on_hooks(true)
37
37
  end
38
38
 
39
39
  # Undo the effects of a previous call to
40
- # `enable_final_checks_for_include_extend`.
41
- def self.reset_final_checks_for_include_extend
42
- T::Private::Methods.set_final_checks_for_include_extend(false)
40
+ # `enable_final_checks_on_hooks`.
41
+ def self.reset_final_checks_on_hooks
42
+ T::Private::Methods.set_final_checks_on_hooks(false)
43
43
  end
44
44
 
45
45
  # Configure the default checked level for a sig with no explicit `.checked`
@@ -11,13 +11,18 @@ module T::Private::Methods
11
11
  # - they are done possibly before any sig block has run.
12
12
  # - they are done even if the method being defined doesn't have a sig.
13
13
  @final_methods = Set.new
14
- # a module-with-final is a module for which at least one of the following is true:
14
+ # a non-singleton is a module for which at least one of the following is true:
15
15
  # - is declared final
16
16
  # - defines a method that is declared final
17
- # - includes an module-with-final
18
- # - extends an module-with-final
17
+ # - includes an non-singleton
18
+ # - extends an non-singleton
19
+ # a singleton is the singleton_class of a non-singleton.
20
+ # modules_with_final is the set of singletons and non-singletons.
19
21
  @modules_with_final = Set.new
20
- @old_included_extended = nil
22
+ # this stores the old [included, extended] hooks for Module and inherited hook for Class that we override when
23
+ # enabling final checks for when those hooks are called. the 'hooks' here don't have anything to do with the 'hooks'
24
+ # in installed_hooks.
25
+ @old_hooks = nil
21
26
 
22
27
  ARG_NOT_PROVIDED = Object.new
23
28
  PROC_TYPE = Object.new
@@ -126,6 +131,9 @@ module T::Private::Methods
126
131
  # the final instance methods of target and source_method_names. so, for every m in source_method_names, check if there
127
132
  # is already a method defined on one of target_ancestors with the same name that is final.
128
133
  def self._check_final_ancestors(target, target_ancestors, source_method_names)
134
+ if !module_with_final?(target)
135
+ return
136
+ end
129
137
  # use reverse_each to check farther-up ancestors first, for better error messages. we could avoid this if we were on
130
138
  # the version of ruby that adds the optional argument to method_defined? that allows you to exclude ancestors.
131
139
  target_ancestors.reverse_each do |ancestor|
@@ -154,6 +162,7 @@ module T::Private::Methods
154
162
 
155
163
  def self.add_module_with_final(mod)
156
164
  @modules_with_final.add(mod)
165
+ @modules_with_final.add(mod.singleton_class)
157
166
  end
158
167
 
159
168
  private_class_method def self.module_with_final?(mod)
@@ -231,7 +240,9 @@ module T::Private::Methods
231
240
  @sig_wrappers[key] = sig_block
232
241
  if current_declaration.final
233
242
  add_final_method(key)
234
- add_module_with_final(mod)
243
+ # use hook_mod, not mod, because for example, we want class C to be marked as having final if we def C.foo as
244
+ # final. change this to mod to see some final_method tests fail.
245
+ add_module_with_final(hook_mod)
235
246
  end
236
247
  end
237
248
 
@@ -369,7 +380,7 @@ module T::Private::Methods
369
380
 
370
381
  # the module target is adding the methods from the module source to itself. we need to check that for all instance
371
382
  # methods M on source, M is not defined on any of target's ancestors.
372
- def self._included_extended_impl(target, target_ancestors, source)
383
+ def self._hook_impl(target, target_ancestors, source)
373
384
  if !module_with_final?(target) && !module_with_final?(source)
374
385
  return
375
386
  end
@@ -378,24 +389,28 @@ module T::Private::Methods
378
389
  _check_final_ancestors(target, target_ancestors - source.ancestors, source.instance_methods)
379
390
  end
380
391
 
381
- def self.set_final_checks_for_include_extend(enable)
382
- is_enabled = @old_included_extended != nil
392
+ def self.set_final_checks_on_hooks(enable)
393
+ is_enabled = @old_hooks != nil
383
394
  if enable == is_enabled
384
395
  return
385
396
  end
386
397
  if is_enabled
387
- @old_included_extended.each(&:restore)
388
- @old_included_extended = nil
398
+ @old_hooks.each(&:restore)
399
+ @old_hooks = nil
389
400
  else
390
401
  old_included = T::Private::ClassUtils.replace_method(Module, :included) do |arg|
391
402
  old_included.bind(self).call(arg)
392
- ::T::Private::Methods._included_extended_impl(arg, arg.ancestors, self)
403
+ ::T::Private::Methods._hook_impl(arg, arg.ancestors, self)
393
404
  end
394
405
  old_extended = T::Private::ClassUtils.replace_method(Module, :extended) do |arg|
395
406
  old_extended.bind(self).call(arg)
396
- ::T::Private::Methods._included_extended_impl(arg, arg.singleton_class.ancestors, self)
407
+ ::T::Private::Methods._hook_impl(arg, arg.singleton_class.ancestors, self)
408
+ end
409
+ old_inherited = T::Private::ClassUtils.replace_method(Class, :inherited) do |arg|
410
+ old_inherited.bind(self).call(arg)
411
+ ::T::Private::Methods._hook_impl(arg, arg.ancestors, self)
397
412
  end
398
- @old_included_extended = [old_included, old_extended]
413
+ @old_hooks = [old_included, old_extended, old_inherited]
399
414
  end
400
415
  end
401
416
 
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.4.4472
4
+ version: 0.4.4475
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-18 00:00:00.000000000 Z
11
+ date: 2019-07-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest