sorbet-runtime 0.5.11144 → 0.5.11218
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sorbet-runtime.rb +0 -1
- data/lib/types/private/abstract/declare.rb +4 -5
- data/lib/types/private/methods/_methods.rb +23 -23
- data/lib/types/private/methods/call_validation.rb +16 -2
- data/lib/types/private/methods/call_validation_2_6.rb +518 -0
- data/lib/types/private/methods/call_validation_2_7.rb +518 -0
- data/lib/types/private/methods/decl_builder.rb +1 -1
- data/lib/types/private/methods/signature.rb +9 -0
- data/lib/types/private/methods/signature_validation.rb +9 -2
- data/lib/types/private/types/not_typed.rb +4 -0
- data/lib/types/private/types/string_holder.rb +4 -0
- data/lib/types/private/types/type_alias.rb +4 -0
- data/lib/types/private/types/void.rb +4 -0
- data/lib/types/props/_props.rb +2 -2
- data/lib/types/props/decorator.rb +7 -6
- data/lib/types/props/pretty_printable.rb +1 -1
- data/lib/types/props/private/setter_factory.rb +129 -69
- data/lib/types/types/anything.rb +4 -0
- data/lib/types/types/attached_class.rb +4 -0
- data/lib/types/types/base.rb +6 -0
- data/lib/types/types/class_of.rb +4 -0
- data/lib/types/types/enum.rb +4 -0
- data/lib/types/types/fixed_array.rb +19 -12
- data/lib/types/types/fixed_hash.rb +16 -9
- data/lib/types/types/intersection.rb +13 -6
- data/lib/types/types/noreturn.rb +4 -0
- data/lib/types/types/proc.rb +19 -9
- data/lib/types/types/self_type.rb +4 -0
- data/lib/types/types/simple.rb +4 -0
- data/lib/types/types/t_enum.rb +4 -0
- data/lib/types/types/type_parameter.rb +4 -0
- data/lib/types/types/type_variable.rb +4 -0
- data/lib/types/types/typed_array.rb +6 -1
- data/lib/types/types/typed_class.rb +21 -4
- data/lib/types/types/typed_enumerable.rb +18 -11
- data/lib/types/types/typed_enumerator.rb +1 -3
- data/lib/types/types/typed_enumerator_chain.rb +1 -3
- data/lib/types/types/typed_enumerator_lazy.rb +1 -3
- data/lib/types/types/typed_hash.rb +17 -7
- data/lib/types/types/typed_range.rb +1 -3
- data/lib/types/types/typed_set.rb +1 -3
- data/lib/types/types/union.rb +12 -5
- data/lib/types/types/untyped.rb +4 -0
- data/lib/types/utils.rb +2 -2
- metadata +2 -3
- data/lib/types/interface_wrapper.rb +0 -162
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc3bbd1acf267719f097fe97d978b1896075899607230c1f64d9c9dd3c5b3d33
|
4
|
+
data.tar.gz: fc59cc7e14e1218a2567b20267562e60bf229283ffc3db5c28096bfbf3a7cf64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d5549e16e9f5a96f4fbc692b4fac7a498ce74deb4bff02f92a9c43318418d1d4ccefa594d7884cdd7662b5225e5e3abe41136afe4682c98fe30430099aa93c0
|
7
|
+
data.tar.gz: 20d1ef7401dd881324f02c58f2938bef3f3f304d3bf2c3eefc2b68f7e5fce28e69db27c5ed5bd4c1a4ac3bedd302469f1a45314e8e6858cd898943b788814e17
|
data/lib/sorbet-runtime.rb
CHANGED
@@ -73,7 +73,6 @@ require_relative 'types/private/abstract/validate'
|
|
73
73
|
|
74
74
|
# Catch all. Sort of built by `cd extn; find types -type f | grep -v test | sort`
|
75
75
|
require_relative 'types/generic'
|
76
|
-
require_relative 'types/interface_wrapper'
|
77
76
|
require_relative 'types/private/abstract/declare'
|
78
77
|
require_relative 'types/private/abstract/hooks'
|
79
78
|
require_relative 'types/private/casts'
|
@@ -18,7 +18,6 @@ module T::Private::Abstract::Declare
|
|
18
18
|
Abstract::Data.set(mod, :abstract_type, type)
|
19
19
|
|
20
20
|
mod.extend(Abstract::Hooks)
|
21
|
-
mod.extend(T::InterfaceWrapper::Helpers)
|
22
21
|
|
23
22
|
if mod.is_a?(Class)
|
24
23
|
if type == :interface
|
@@ -35,11 +34,11 @@ module T::Private::Abstract::Declare
|
|
35
34
|
# define_method because of the guard above
|
36
35
|
|
37
36
|
mod.send(:define_singleton_method, :new) do |*args, &blk|
|
38
|
-
super(*args, &blk)
|
39
|
-
|
40
|
-
|
41
|
-
end
|
37
|
+
result = super(*args, &blk)
|
38
|
+
if result.instance_of?(mod)
|
39
|
+
raise "#{mod} is declared as abstract; it cannot be instantiated"
|
42
40
|
end
|
41
|
+
result
|
43
42
|
end
|
44
43
|
|
45
44
|
# Ruby doesn not emit "method redefined" warnings for aliased methods
|
@@ -8,7 +8,7 @@ module T::Private::Methods
|
|
8
8
|
@sigs_that_raised = {}
|
9
9
|
# stores method names that were declared final without regard for where.
|
10
10
|
# enables early rejection of names that we know can't induce final method violations.
|
11
|
-
@was_ever_final_names = {}
|
11
|
+
@was_ever_final_names = {}.compare_by_identity
|
12
12
|
# maps from a module's object_id to the set of final methods declared in that module.
|
13
13
|
# we also overload entries slightly: if the value is nil, that means that the
|
14
14
|
# module has final methods somewhere along its ancestor chain, but does not itself
|
@@ -20,7 +20,7 @@ module T::Private::Methods
|
|
20
20
|
# twice is permitted). we could do this with two tables, but it seems slightly
|
21
21
|
# cleaner with a single table.
|
22
22
|
# Effectively T::Hash[Module, T.nilable(Set))]
|
23
|
-
@modules_with_final = Hash.new {|hash, key| hash[key] = nil}
|
23
|
+
@modules_with_final = Hash.new {|hash, key| hash[key] = nil}.compare_by_identity
|
24
24
|
# this stores the old [included, extended] hooks for Module and inherited hook for Class that we override when
|
25
25
|
# enabling final checks for when those hooks are called. the 'hooks' here don't have anything to do with the 'hooks'
|
26
26
|
# in installed_hooks.
|
@@ -132,7 +132,7 @@ module T::Private::Methods
|
|
132
132
|
source_ancestors = nil
|
133
133
|
# use reverse_each to check farther-up ancestors first, for better error messages.
|
134
134
|
target_ancestors.reverse_each do |ancestor|
|
135
|
-
final_methods = @modules_with_final.fetch(ancestor
|
135
|
+
final_methods = @modules_with_final.fetch(ancestor, nil)
|
136
136
|
# In this case, either ancestor didn't have any final methods anywhere in its
|
137
137
|
# ancestor chain, or ancestor did have final methods somewhere in its ancestor
|
138
138
|
# chain, but no final methods defined in ancestor itself. Either way, there
|
@@ -150,13 +150,13 @@ module T::Private::Methods
|
|
150
150
|
# filter out things without actual final methods just to make sure that
|
151
151
|
# the below checks (which should be uncommon) go as quickly as possible.
|
152
152
|
source_ancestors.select! do |a|
|
153
|
-
@modules_with_final.fetch(a
|
153
|
+
@modules_with_final.fetch(a, nil)
|
154
154
|
end
|
155
155
|
end
|
156
156
|
# final-ness means that there should be no more than one index for which
|
157
157
|
# the below block returns true.
|
158
158
|
defining_ancestor_idx = source_ancestors.index do |a|
|
159
|
-
@modules_with_final.fetch(a
|
159
|
+
@modules_with_final.fetch(a).include?(method_name)
|
160
160
|
end
|
161
161
|
next if defining_ancestor_idx && source_ancestors[defining_ancestor_idx] == ancestor
|
162
162
|
end
|
@@ -191,13 +191,11 @@ module T::Private::Methods
|
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
194
|
-
def self.add_module_with_final_method(mod, method_name
|
195
|
-
|
196
|
-
mid = m.object_id
|
197
|
-
methods = @modules_with_final[mid]
|
194
|
+
def self.add_module_with_final_method(mod, method_name)
|
195
|
+
methods = @modules_with_final[mod]
|
198
196
|
if methods.nil?
|
199
197
|
methods = {}
|
200
|
-
@modules_with_final[
|
198
|
+
@modules_with_final[mod] = methods
|
201
199
|
end
|
202
200
|
methods[method_name] = true
|
203
201
|
nil
|
@@ -205,24 +203,23 @@ module T::Private::Methods
|
|
205
203
|
|
206
204
|
def self.note_module_deals_with_final(mod)
|
207
205
|
# Side-effectfully initialize the value if it's not already there
|
208
|
-
@modules_with_final[mod
|
209
|
-
@modules_with_final[mod.singleton_class
|
206
|
+
@modules_with_final[mod]
|
207
|
+
@modules_with_final[mod.singleton_class]
|
210
208
|
end
|
211
209
|
|
212
210
|
# Only public because it needs to get called below inside the replace_method blocks below.
|
213
|
-
def self._on_method_added(hook_mod,
|
211
|
+
def self._on_method_added(hook_mod, mod, method_name)
|
214
212
|
if T::Private::DeclState.current.skip_on_method_added
|
215
213
|
return
|
216
214
|
end
|
217
215
|
|
218
216
|
current_declaration = T::Private::DeclState.current.active_declaration
|
219
|
-
mod = is_singleton_method ? hook_mod.singleton_class : hook_mod
|
220
217
|
|
221
218
|
if T::Private::Final.final_module?(mod) && (current_declaration.nil? || !current_declaration.final)
|
222
219
|
raise "#{mod} was declared as final but its method `#{method_name}` was not declared as final"
|
223
220
|
end
|
224
221
|
# Don't compute mod.ancestors if we don't need to bother checking final-ness.
|
225
|
-
if @was_ever_final_names.include?(method_name) && @modules_with_final.include?(mod
|
222
|
+
if @was_ever_final_names.include?(method_name) && @modules_with_final.include?(mod)
|
226
223
|
_check_final_ancestors(mod, mod.ancestors, [method_name], nil)
|
227
224
|
# We need to fetch the active declaration again, as _check_final_ancestors
|
228
225
|
# may have reset it (see the comment in that method for details).
|
@@ -287,7 +284,7 @@ module T::Private::Methods
|
|
287
284
|
# use hook_mod, not mod, because for example, we want class C to be marked as having final if we def C.foo as
|
288
285
|
# final. change this to mod to see some final_method tests fail.
|
289
286
|
note_module_deals_with_final(hook_mod)
|
290
|
-
add_module_with_final_method(
|
287
|
+
add_module_with_final_method(mod, method_name)
|
291
288
|
end
|
292
289
|
end
|
293
290
|
|
@@ -431,7 +428,7 @@ module T::Private::Methods
|
|
431
428
|
run_sig_block_for_key(method_to_key(method))
|
432
429
|
end
|
433
430
|
|
434
|
-
private_class_method def self.run_sig_block_for_key(key)
|
431
|
+
private_class_method def self.run_sig_block_for_key(key, force_type_init: false)
|
435
432
|
blk = @sig_wrappers[key]
|
436
433
|
if !blk
|
437
434
|
sig = @signatures_by_method[key]
|
@@ -454,14 +451,17 @@ module T::Private::Methods
|
|
454
451
|
end
|
455
452
|
|
456
453
|
@sig_wrappers.delete(key)
|
454
|
+
|
455
|
+
sig.force_type_init if force_type_init
|
456
|
+
|
457
457
|
sig
|
458
458
|
end
|
459
459
|
|
460
|
-
def self.run_all_sig_blocks
|
460
|
+
def self.run_all_sig_blocks(force_type_init: true)
|
461
461
|
loop do
|
462
462
|
break if @sig_wrappers.empty?
|
463
463
|
key, = @sig_wrappers.first
|
464
|
-
run_sig_block_for_key(key)
|
464
|
+
run_sig_block_for_key(key, force_type_init: force_type_init)
|
465
465
|
end
|
466
466
|
end
|
467
467
|
|
@@ -474,8 +474,8 @@ module T::Private::Methods
|
|
474
474
|
def self._hook_impl(target, singleton_class, source)
|
475
475
|
# we do not need to call add_was_ever_final here, because we have already marked
|
476
476
|
# any such methods when source was originally defined.
|
477
|
-
if !@modules_with_final.include?(target
|
478
|
-
if !@modules_with_final.include?(source
|
477
|
+
if !@modules_with_final.include?(target)
|
478
|
+
if !@modules_with_final.include?(source)
|
479
479
|
return
|
480
480
|
end
|
481
481
|
note_module_deals_with_final(target)
|
@@ -541,14 +541,14 @@ module T::Private::Methods
|
|
541
541
|
module MethodHooks
|
542
542
|
def method_added(name)
|
543
543
|
super(name)
|
544
|
-
::T::Private::Methods._on_method_added(self,
|
544
|
+
::T::Private::Methods._on_method_added(self, self, name)
|
545
545
|
end
|
546
546
|
end
|
547
547
|
|
548
548
|
module SingletonMethodHooks
|
549
549
|
def singleton_method_added(name)
|
550
550
|
super(name)
|
551
|
-
::T::Private::Methods._on_method_added(self,
|
551
|
+
::T::Private::Methods._on_method_added(self, singleton_class, name)
|
552
552
|
end
|
553
553
|
end
|
554
554
|
|
@@ -15,8 +15,6 @@ module T::Private::Methods::CallValidation
|
|
15
15
|
original_visibility = visibility_method_name(mod, method_sig.method_name)
|
16
16
|
if method_sig.mode == T::Private::Methods::Modes.abstract
|
17
17
|
T::Private::ClassUtils.replace_method(mod, method_sig.method_name, true) do |*args, &blk|
|
18
|
-
# TODO: write a cop to ensure that abstract methods have an empty body
|
19
|
-
#
|
20
18
|
# We allow abstract methods to be implemented by things further down the ancestor chain.
|
21
19
|
# So, if a super method exists, call it.
|
22
20
|
if defined?(super)
|
@@ -67,14 +65,30 @@ module T::Private::Methods::CallValidation
|
|
67
65
|
simple_method = all_args_are_simple && method_sig.return_type.is_a?(T::Types::Simple)
|
68
66
|
simple_procedure = all_args_are_simple && method_sig.return_type.is_a?(T::Private::Types::Void)
|
69
67
|
|
68
|
+
# All the types for which valid? unconditionally returns `true`
|
69
|
+
return_is_ignorable =
|
70
|
+
(method_sig.return_type.equal?(T::Types::Untyped::Private::INSTANCE) ||
|
71
|
+
method_sig.return_type.equal?(T::Types::Anything::Private::INSTANCE) ||
|
72
|
+
method_sig.return_type.equal?(T::Types::AttachedClassType::Private::INSTANCE) ||
|
73
|
+
method_sig.return_type.equal?(T::Types::SelfType::Private::INSTANCE) ||
|
74
|
+
method_sig.return_type.is_a?(T::Types::TypeParameter) ||
|
75
|
+
method_sig.return_type.is_a?(T::Types::TypeVariable) ||
|
76
|
+
(method_sig.return_type.is_a?(T::Types::Simple) && method_sig.return_type.raw_type.equal?(BasicObject)))
|
77
|
+
|
78
|
+
returns_anything_method = all_args_are_simple && return_is_ignorable
|
79
|
+
|
70
80
|
T::Configuration.without_ruby_warnings do
|
71
81
|
T::Private::DeclState.current.without_on_method_added do
|
72
82
|
if simple_method
|
73
83
|
create_validator_method_fast(mod, original_method, method_sig, original_visibility)
|
84
|
+
elsif returns_anything_method
|
85
|
+
create_validator_method_skip_return_fast(mod, original_method, method_sig, original_visibility)
|
74
86
|
elsif simple_procedure
|
75
87
|
create_validator_procedure_fast(mod, original_method, method_sig, original_visibility)
|
76
88
|
elsif ok_for_fast_path && method_sig.return_type.is_a?(T::Private::Types::Void)
|
77
89
|
create_validator_procedure_medium(mod, original_method, method_sig, original_visibility)
|
90
|
+
elsif ok_for_fast_path && return_is_ignorable
|
91
|
+
create_validator_method_skip_return_medium(mod, original_method, method_sig, original_visibility)
|
78
92
|
elsif ok_for_fast_path
|
79
93
|
create_validator_method_medium(mod, original_method, method_sig, original_visibility)
|
80
94
|
elsif can_skip_block_type
|