sorbet-runtime 0.5.9426 → 0.5.9431

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69d5b10e37d71fe876975606fde9b51e352fe7f67f480beff7dbed78e81f7b6e
4
- data.tar.gz: 5dc9be32f364e2fc8c05df9e67635c6332cdf205cf347d8d54b1635815d96b74
3
+ metadata.gz: 9208d78f8055eb2c5ebf6d665728d898c5ae7895bb59dce20e57cfbcb7491d08
4
+ data.tar.gz: '0957123248c7d548d8a25c7c5aae395be8506e01c0b1dfb87b307797bc9777c4'
5
5
  SHA512:
6
- metadata.gz: 172f75e575ae989784006e53c9ebe4314907df62740cc7a2929462063ce4354e70d001b22f319d855845c4c0c8c7aca9c8cf5986d0b344ecdfa531d9e0675e25
7
- data.tar.gz: d7c7b4c9faff43db9249bcf09a8d4ac64c3702540d79299323916d12cb470f4d8582dc6b8708a4a52e8088963d54a76ee401d3db45188ce0157930f0a1a3a86b
6
+ metadata.gz: 97dcd774b64c2d9621a1c235c3d53aa286a51fd76af26d6b018ea9e44943d1c3fe771e2fd206153f77e3cc96502f8b7f9bd78d5d06d920a627a506200c17ef9d
7
+ data.tar.gz: 0f5f87a751301cac4bd14984e2e570472a1b94a76c28aac05ad3a3ed16608271c70bcbb0b01b6ccc14eee4013b130ebf1c84393830fa14fa51dffaf567cf52f2
@@ -22,8 +22,6 @@ require_relative 'types/private/decl_state'
22
22
  require_relative 'types/private/class_utils'
23
23
  require_relative 'types/private/runtime_levels'
24
24
  require_relative 'types/private/methods/_methods'
25
- require_relative 'types/private/methods/modes'
26
- require_relative 'types/private/methods/decl_builder'
27
25
  require_relative 'types/sig'
28
26
  require_relative 'types/helpers'
29
27
  require_relative 'types/private/final'
@@ -62,6 +60,7 @@ require_relative 'types/types/type_member'
62
60
  require_relative 'types/types/type_template'
63
61
 
64
62
  # Call validation
63
+ require_relative 'types/private/methods/modes'
65
64
  require_relative 'types/private/methods/call_validation'
66
65
 
67
66
  # Signature validation
@@ -75,6 +74,7 @@ require_relative 'types/interface_wrapper'
75
74
  require_relative 'types/private/abstract/declare'
76
75
  require_relative 'types/private/abstract/hooks'
77
76
  require_relative 'types/private/casts'
77
+ require_relative 'types/private/methods/decl_builder'
78
78
  require_relative 'types/private/methods/signature'
79
79
  require_relative 'types/private/retry'
80
80
  require_relative 'types/utils'
@@ -29,13 +29,12 @@ module T::Private::Methods
29
29
  ARG_NOT_PROVIDED = Object.new
30
30
  PROC_TYPE = Object.new
31
31
 
32
- DeclarationBlock = Struct.new(:mod, :loc, :blk, :raw, :decl_builder)
32
+ DeclarationBlock = Struct.new(:mod, :loc, :blk, :final, :raw)
33
33
 
34
34
  def self.declare_sig(mod, loc, arg, &blk)
35
- declaration = _declare_sig_internal(mod, loc, arg, &blk)
36
- T::Private::DeclState.current.active_declaration = declaration
35
+ T::Private::DeclState.current.active_declaration = _declare_sig_internal(mod, loc, arg, &blk)
37
36
 
38
- declaration.decl_builder
37
+ nil
39
38
  end
40
39
 
41
40
  # See tests for how to use this. But you shouldn't be using this.
@@ -55,10 +54,7 @@ module T::Private::Methods
55
54
  raise "Invalid argument to `sig`: #{arg}"
56
55
  end
57
56
 
58
- decl_builder = DeclBuilder.new(mod, raw)
59
- decl_builder.final if arg == :final # needed for backwards compatibility with sig(:final) {...}
60
-
61
- DeclarationBlock.new(mod, loc, blk, raw, decl_builder)
57
+ DeclarationBlock.new(mod, loc, blk, arg == :final, raw)
62
58
  end
63
59
 
64
60
  def self._with_declared_signature(mod, declblock, &blk)
@@ -217,7 +213,7 @@ module T::Private::Methods
217
213
  current_declaration = T::Private::DeclState.current.active_declaration
218
214
  mod = is_singleton_method ? hook_mod.singleton_class : hook_mod
219
215
 
220
- if T::Private::Final.final_module?(mod) && (current_declaration.nil? || !current_declaration.decl_builder.final?)
216
+ if T::Private::Final.final_module?(mod) && (current_declaration.nil? || !current_declaration.final)
221
217
  raise "#{mod} was declared as final but its method `#{method_name}` was not declared as final"
222
218
  end
223
219
  # Don't compute mod.ancestors if we don't need to bother checking final-ness.
@@ -281,7 +277,7 @@ module T::Private::Methods
281
277
  end
282
278
 
283
279
  @sig_wrappers[key] = sig_block
284
- if current_declaration.decl_builder.final?
280
+ if current_declaration.final
285
281
  @was_ever_final_names[method_name] = true
286
282
  # use hook_mod, not mod, because for example, we want class C to be marked as having final if we def C.foo as
287
283
  # final. change this to mod to see some final_method tests fail.
@@ -350,9 +346,10 @@ module T::Private::Methods
350
346
  end
351
347
 
352
348
  def self.run_builder(declaration_block)
353
- declaration_block
354
- .decl_builder
355
- .run!(&declaration_block.blk)
349
+ builder = DeclBuilder.new(declaration_block.mod, declaration_block.raw)
350
+ builder
351
+ .instance_exec(&declaration_block.blk)
352
+ .finalize!
356
353
  .decl
357
354
  end
358
355
 
@@ -2,23 +2,9 @@
2
2
  # typed: true
3
3
 
4
4
  module T::Private::Methods
5
- Declaration = Struct.new(
6
- :mod,
7
- :params,
8
- :returns,
9
- :bind,
10
- :mode,
11
- :checked,
12
- :finalized,
13
- :on_failure,
14
- :override_allow_incompatible,
15
- :type_parameters,
16
- :raw,
17
- :final
18
- )
5
+ Declaration = Struct.new(:mod, :params, :returns, :bind, :mode, :checked, :finalized, :on_failure, :override_allow_incompatible, :type_parameters, :raw)
19
6
 
20
7
  class DeclBuilder
21
- # The signature declaration the builder is composing (class `Declaration`)
22
8
  attr_reader :decl
23
9
 
24
10
  class BuilderError < StandardError; end
@@ -29,24 +15,6 @@ module T::Private::Methods
29
15
  end
30
16
  end
31
17
 
32
- private def check_sig_block_is_unset!
33
- if T::Private::DeclState.current.active_declaration&.blk
34
- raise BuilderError.new(
35
- "Cannot add more signature statements after the declaration block."
36
- )
37
- end
38
- end
39
-
40
- # Verify if we're trying to invoke the method outside of a signature block. Notice that we need to check if it's a
41
- # proc, because this is valid and would lead to a false positive: `T.type_alias { T.proc.params(a: Integer).void }`
42
- private def check_running_inside_block!(method_name)
43
- unless @inside_sig_block || decl.mod == T::Private::Methods::PROC_TYPE
44
- raise BuilderError.new(
45
- "Can't invoke #{method_name} outside of a signature declaration block"
46
- )
47
- end
48
- end
49
-
50
18
  def initialize(mod, raw)
51
19
  # TODO RUBYPLAT-1278 - with ruby 2.5, use kwargs here
52
20
  @decl = Declaration.new(
@@ -60,23 +28,12 @@ module T::Private::Methods
60
28
  ARG_NOT_PROVIDED, # on_failure
61
29
  nil, # override_allow_incompatible
62
30
  ARG_NOT_PROVIDED, # type_parameters
63
- raw,
64
- ARG_NOT_PROVIDED, # final
31
+ raw
65
32
  )
66
- @inside_sig_block = false
67
- end
68
-
69
- def run!(&block)
70
- @inside_sig_block = true
71
- instance_exec(&block)
72
- finalize!
73
- self
74
33
  end
75
34
 
76
35
  def params(**params)
77
36
  check_live!
78
- check_running_inside_block!(__method__)
79
-
80
37
  if !decl.params.equal?(ARG_NOT_PROVIDED)
81
38
  raise BuilderError.new("You can't call .params twice")
82
39
  end
@@ -91,8 +48,6 @@ module T::Private::Methods
91
48
 
92
49
  def returns(type)
93
50
  check_live!
94
- check_running_inside_block!(__method__)
95
-
96
51
  if decl.returns.is_a?(T::Private::Types::Void)
97
52
  raise BuilderError.new("You can't call .returns after calling .void.")
98
53
  end
@@ -107,8 +62,6 @@ module T::Private::Methods
107
62
 
108
63
  def void
109
64
  check_live!
110
- check_running_inside_block!(__method__)
111
-
112
65
  if !decl.returns.equal?(ARG_NOT_PROVIDED)
113
66
  raise BuilderError.new("You can't call .void after calling .returns.")
114
67
  end
@@ -120,8 +73,6 @@ module T::Private::Methods
120
73
 
121
74
  def bind(type)
122
75
  check_live!
123
- check_running_inside_block!(__method__)
124
-
125
76
  if !decl.bind.equal?(ARG_NOT_PROVIDED)
126
77
  raise BuilderError.new("You can't call .bind multiple times in a signature.")
127
78
  end
@@ -133,7 +84,6 @@ module T::Private::Methods
133
84
 
134
85
  def checked(level)
135
86
  check_live!
136
- check_running_inside_block!(__method__)
137
87
 
138
88
  if !decl.checked.equal?(ARG_NOT_PROVIDED)
139
89
  raise BuilderError.new("You can't call .checked multiple times in a signature.")
@@ -152,7 +102,6 @@ module T::Private::Methods
152
102
 
153
103
  def on_failure(*args)
154
104
  check_live!
155
- check_running_inside_block!(__method__)
156
105
 
157
106
  if !decl.on_failure.equal?(ARG_NOT_PROVIDED)
158
107
  raise BuilderError.new("You can't call .on_failure multiple times in a signature.")
@@ -166,7 +115,7 @@ module T::Private::Methods
166
115
  self
167
116
  end
168
117
 
169
- def abstract(&blk)
118
+ def abstract
170
119
  check_live!
171
120
 
172
121
  case decl.mode
@@ -178,47 +127,15 @@ module T::Private::Methods
178
127
  raise BuilderError.new("`.abstract` cannot be combined with `.override` or `.overridable`.")
179
128
  end
180
129
 
181
- check_sig_block_is_unset!
182
-
183
- if blk
184
- T::Private::DeclState.current.active_declaration.blk = blk
185
- end
186
-
187
130
  self
188
131
  end
189
132
 
190
- def final(&blk)
133
+ def final
191
134
  check_live!
192
-
193
- if !decl.final.equal?(ARG_NOT_PROVIDED)
194
- raise BuilderError.new("You can't call .final multiple times in a signature.")
195
- end
196
-
197
- if @inside_sig_block
198
- raise BuilderError.new(
199
- "Unlike other sig annotations, the `final` annotation must remain outside the sig block, " \
200
- "using either `sig(:final) {...}` or `sig.final {...}`, not `sig {final. ...}"
201
- )
202
- end
203
-
204
- raise BuilderError.new(".final cannot be repeated in a single signature") if final?
205
-
206
- decl.final = true
207
-
208
- check_sig_block_is_unset!
209
-
210
- if blk
211
- T::Private::DeclState.current.active_declaration.blk = blk
212
- end
213
-
214
- self
135
+ raise BuilderError.new("The syntax for declaring a method final is `sig(:final) {...}`, not `sig {final. ...}`")
215
136
  end
216
137
 
217
- def final?
218
- !decl.final.equal?(ARG_NOT_PROVIDED) && decl.final
219
- end
220
-
221
- def override(allow_incompatible: false, &blk)
138
+ def override(allow_incompatible: false)
222
139
  check_live!
223
140
 
224
141
  case decl.mode
@@ -233,16 +150,10 @@ module T::Private::Methods
233
150
  raise BuilderError.new("`.override` cannot be combined with `.abstract`.")
234
151
  end
235
152
 
236
- check_sig_block_is_unset!
237
-
238
- if blk
239
- T::Private::DeclState.current.active_declaration.blk = blk
240
- end
241
-
242
153
  self
243
154
  end
244
155
 
245
- def overridable(&blk)
156
+ def overridable
246
157
  check_live!
247
158
 
248
159
  case decl.mode
@@ -256,12 +167,6 @@ module T::Private::Methods
256
167
  raise BuilderError.new(".overridable cannot be repeated in a single signature")
257
168
  end
258
169
 
259
- check_sig_block_is_unset!
260
-
261
- if blk
262
- T::Private::DeclState.current.active_declaration.blk = blk
263
- end
264
-
265
170
  self
266
171
  end
267
172
 
@@ -278,7 +183,6 @@ module T::Private::Methods
278
183
  # def map(&blk); end
279
184
  def type_parameters(*names)
280
185
  check_live!
281
- check_running_inside_block!(__method__)
282
186
 
283
187
  names.each do |name|
284
188
  raise BuilderError.new("not a symbol: #{name}") unless name.is_a?(Symbol)
data/lib/types/sig.rb CHANGED
@@ -12,53 +12,10 @@ module T::Sig
12
12
  original_verbose = $VERBOSE
13
13
  $VERBOSE = false
14
14
 
15
- # At runtime, only returns a fake declaration builder to allow chaining methods, but statically it is treated
16
- # exactly the same as T::Sig#sig. Only use it in cases where you can't use T::Sig#sig.
15
+ # At runtime, does nothing, but statically it is treated exactly the same
16
+ # as T::Sig#sig. Only use it in cases where you can't use T::Sig#sig.
17
17
  T::Sig::WithoutRuntime.sig {params(arg0: T.nilable(Symbol), blk: T.proc.bind(T::Private::Methods::DeclBuilder).void).void}
18
- def self.sig(arg0=nil, &blk) # rubocop:disable Lint/DuplicateMethods
19
- DeclBuilder.new
20
- end
21
-
22
- # This fake version of DeclBuilder exists so that signatures without runtime don't have to pay the cost associated
23
- # with using the actual DeclBuilder
24
- class DeclBuilder
25
- T::Sig::WithoutRuntime.sig do
26
- params(
27
- _blk: T.nilable(T.proc.bind(T::Private::Methods::DeclBuilder).void)
28
- ).returns(DeclBuilder)
29
- end
30
- def abstract(&_blk)
31
- self
32
- end
33
-
34
- T::Sig::WithoutRuntime.sig do
35
- params(
36
- _blk: T.nilable(T.proc.bind(T::Private::Methods::DeclBuilder).void)
37
- ).returns(DeclBuilder)
38
- end
39
- def final(&_blk)
40
- self
41
- end
42
-
43
- T::Sig::WithoutRuntime.sig do
44
- params(
45
- _allow_incompatible: T::Boolean,
46
- _blk: T.nilable(T.proc.bind(T::Private::Methods::DeclBuilder).void)
47
- ).returns(DeclBuilder)
48
- end
49
- def override(_allow_incompatible: false, &_blk)
50
- self
51
- end
52
-
53
- T::Sig::WithoutRuntime.sig do
54
- params(
55
- _blk: T.nilable(T.proc.bind(T::Private::Methods::DeclBuilder).void)
56
- ).returns(DeclBuilder)
57
- end
58
- def overridable(&_blk)
59
- self
60
- end
61
- end
18
+ def self.sig(arg0=nil, &blk); end # rubocop:disable Lint/DuplicateMethods
62
19
 
63
20
  $VERBOSE = original_verbose
64
21
  end
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.9426
4
+ version: 0.5.9431
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stripe
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-04 00:00:00.000000000 Z
11
+ date: 2021-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest