sorbet-runtime 0.5.10511 → 0.5.10514
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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fc2dd38a71b81d23d2610e3f5f9c9cac33625013e352a7daf58ebebd55e78ef0
|
|
4
|
+
data.tar.gz: fd2f55279f00607fcb7fef6495ca82e323870d2664ab921bfe2749ad085082f4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 1647c5d87016036740e44263c29b13aff039451a1dc45f879e8684820c7b833623613dffd4c3f33219f31dc1b156a0c989dd8dc0a13e2681b1a0c4a790aaed13
|
|
7
|
+
data.tar.gz: f6a68b760d3e49c5d65fbad93eb91cde28a891dff35f63002d3c3671126b38b4d4dafcad032d57c87020cd8b0199120ece613d73df2b394e36254a3a46f31f3e
|
|
@@ -204,34 +204,6 @@ 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(¤t_declaration.blk).params(**{method_name.to_sym => decl.returns})
|
|
231
|
-
end
|
|
232
|
-
T::Private::DeclState.current.active_declaration = writer_decl
|
|
233
|
-
end
|
|
234
|
-
|
|
235
207
|
# Only public because it needs to get called below inside the replace_method blocks below.
|
|
236
208
|
def self._on_method_added(hook_mod, method_name, is_singleton_method: false)
|
|
237
209
|
if T::Private::DeclState.current.skip_on_method_added
|
|
@@ -257,8 +229,6 @@ module T::Private::Methods
|
|
|
257
229
|
end
|
|
258
230
|
T::Private::DeclState.current.reset!
|
|
259
231
|
|
|
260
|
-
declare_writer_sig_from_reader(method_name, current_declaration) if attr_accessor_reader?(method_name)
|
|
261
|
-
|
|
262
232
|
if method_name == :method_added || method_name == :singleton_method_added
|
|
263
233
|
raise(
|
|
264
234
|
"Putting a `sig` on `#{method_name}` is not supported" \
|
|
@@ -59,8 +59,9 @@ module T::Private::Methods::CallValidation
|
|
|
59
59
|
|
|
60
60
|
def self.create_validator_method(mod, original_method, method_sig, original_visibility)
|
|
61
61
|
has_fixed_arity = method_sig.kwarg_types.empty? && !method_sig.has_rest && !method_sig.has_keyrest &&
|
|
62
|
-
original_method.parameters.all? {|(kind, _name)| kind == :req}
|
|
63
|
-
|
|
62
|
+
original_method.parameters.all? {|(kind, _name)| kind == :req || kind == :block}
|
|
63
|
+
can_skip_block_type = method_sig.block_type.nil? || method_sig.block_type.valid?(nil)
|
|
64
|
+
ok_for_fast_path = has_fixed_arity && can_skip_block_type && !method_sig.bind && method_sig.arg_types.length < 5 && is_allowed_to_have_fast_path
|
|
64
65
|
|
|
65
66
|
all_args_are_simple = ok_for_fast_path && method_sig.arg_types.all? {|_name, type| type.is_a?(T::Types::Simple)}
|
|
66
67
|
simple_method = all_args_are_simple && method_sig.return_type.is_a?(T::Types::Simple)
|
|
@@ -76,6 +77,11 @@ module T::Private::Methods::CallValidation
|
|
|
76
77
|
create_validator_procedure_medium(mod, original_method, method_sig, original_visibility)
|
|
77
78
|
elsif ok_for_fast_path
|
|
78
79
|
create_validator_method_medium(mod, original_method, method_sig, original_visibility)
|
|
80
|
+
elsif can_skip_block_type
|
|
81
|
+
# The Ruby VM already validates that any block passed to a method
|
|
82
|
+
# must be either `nil` or a `Proc` object, so there's no need to also
|
|
83
|
+
# have sorbet-runtime check that.
|
|
84
|
+
create_validator_slow_skip_block_type(mod, original_method, method_sig, original_visibility)
|
|
79
85
|
else
|
|
80
86
|
create_validator_slow(mod, original_method, method_sig, original_visibility)
|
|
81
87
|
end
|
|
@@ -84,6 +90,88 @@ module T::Private::Methods::CallValidation
|
|
|
84
90
|
end
|
|
85
91
|
end
|
|
86
92
|
|
|
93
|
+
def self.create_validator_slow_skip_block_type(mod, original_method, method_sig, original_visibility)
|
|
94
|
+
T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
|
|
95
|
+
CallValidation.validate_call_skip_block_type(self, original_method, method_sig, args, blk)
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def self.validate_call_skip_block_type(instance, original_method, method_sig, args, blk)
|
|
100
|
+
# This method is called for every `sig`. It's critical to keep it fast and
|
|
101
|
+
# reduce number of allocations that happen here.
|
|
102
|
+
|
|
103
|
+
if method_sig.bind
|
|
104
|
+
message = method_sig.bind.error_message_for_obj(instance)
|
|
105
|
+
if message
|
|
106
|
+
CallValidation.report_error(
|
|
107
|
+
method_sig,
|
|
108
|
+
message,
|
|
109
|
+
'Bind',
|
|
110
|
+
nil,
|
|
111
|
+
method_sig.bind,
|
|
112
|
+
instance
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# NOTE: We don't bother validating for missing or extra kwargs;
|
|
118
|
+
# the method call itself will take care of that.
|
|
119
|
+
method_sig.each_args_value_type(args) do |name, arg, type|
|
|
120
|
+
message = type.error_message_for_obj(arg)
|
|
121
|
+
if message
|
|
122
|
+
CallValidation.report_error(
|
|
123
|
+
method_sig,
|
|
124
|
+
message,
|
|
125
|
+
'Parameter',
|
|
126
|
+
name,
|
|
127
|
+
type,
|
|
128
|
+
arg,
|
|
129
|
+
caller_offset: 2
|
|
130
|
+
)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# The original method definition allows passing `nil` for the `&blk`
|
|
135
|
+
# argument, so we do not have to do any method_sig.block_type type checks
|
|
136
|
+
# of our own.
|
|
137
|
+
|
|
138
|
+
# The following line breaks are intentional to show nice pry message
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
# PRY note:
|
|
150
|
+
# this code is sig validation code.
|
|
151
|
+
# Please issue `finish` to step out of it
|
|
152
|
+
|
|
153
|
+
return_value = T::Configuration::AT_LEAST_RUBY_2_7 ? original_method.bind_call(instance, *args, &blk) : original_method.bind(instance).call(*args, &blk)
|
|
154
|
+
|
|
155
|
+
# The only type that is allowed to change the return value is `.void`.
|
|
156
|
+
# It ignores what you returned and changes it to be a private singleton.
|
|
157
|
+
if method_sig.return_type.is_a?(T::Private::Types::Void)
|
|
158
|
+
T::Private::Types::Void::VOID
|
|
159
|
+
else
|
|
160
|
+
message = method_sig.return_type.error_message_for_obj(return_value)
|
|
161
|
+
if message
|
|
162
|
+
CallValidation.report_error(
|
|
163
|
+
method_sig,
|
|
164
|
+
message,
|
|
165
|
+
'Return value',
|
|
166
|
+
nil,
|
|
167
|
+
method_sig.return_type,
|
|
168
|
+
return_value,
|
|
169
|
+
)
|
|
170
|
+
end
|
|
171
|
+
return_value
|
|
172
|
+
end
|
|
173
|
+
end
|
|
174
|
+
|
|
87
175
|
def self.create_validator_slow(mod, original_method, method_sig, original_visibility)
|
|
88
176
|
T::Private::ClassUtils.def_with_visibility(mod, method_sig.method_name, original_visibility) do |*args, &blk|
|
|
89
177
|
CallValidation.validate_call(self, original_method, method_sig, args, blk)
|
|
@@ -125,8 +213,19 @@ module T::Private::Methods::CallValidation
|
|
|
125
213
|
end
|
|
126
214
|
end
|
|
127
215
|
|
|
128
|
-
|
|
129
|
-
|
|
216
|
+
# The Ruby VM already checks that `&blk` is either a `Proc` type or `nil`:
|
|
217
|
+
# https://github.com/ruby/ruby/blob/v2_7_6/vm_args.c#L1150-L1154
|
|
218
|
+
# And `T.proc` types don't (can't) do any runtime arg checking, so we can
|
|
219
|
+
# save work by simply checking that `blk` is non-nil (if the method allows
|
|
220
|
+
# `nil` for the block, it would not have used this validate_call path).
|
|
221
|
+
unless blk
|
|
222
|
+
# Have to use `&.` here, because it's technically a public API that
|
|
223
|
+
# people can _always_ call `validate_call` to validate any signature
|
|
224
|
+
# (i.e., the faster validators are merely optimizations).
|
|
225
|
+
# In practice, this only affects the first call to the method (before the
|
|
226
|
+
# optimized validators have a chance to replace the initial, slow
|
|
227
|
+
# wrapper).
|
|
228
|
+
message = method_sig.block_type&.error_message_for_obj(blk)
|
|
130
229
|
if message
|
|
131
230
|
CallValidation.report_error(
|
|
132
231
|
method_sig,
|
|
@@ -58,14 +58,12 @@ 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
|
|
61
|
+
# If sig params are declared but 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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
end
|
|
68
|
-
|
|
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
|
|
69
67
|
param_names = parameters.map {|_, name| name}
|
|
70
68
|
missing_names = param_names - declared_param_names
|
|
71
69
|
extra_names = declared_param_names - param_names
|
data/lib/types/types/enum.rb
CHANGED
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.
|
|
4
|
+
version: 0.5.10514
|
|
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-
|
|
11
|
+
date: 2022-10-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: minitest
|