rbs 1.1.1 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +5 -1
- data/.gitignore +2 -0
- data/CHANGELOG.md +81 -0
- data/README.md +1 -1
- data/Rakefile +11 -0
- data/Steepfile +1 -0
- data/core/array.rbs +2 -2
- data/core/basic_object.rbs +1 -1
- data/core/enumerable.rbs +1 -1
- data/core/hash.rbs +13 -5
- data/core/io.rbs +4 -4
- data/core/kernel.rbs +2 -2
- data/core/marshal.rbs +4 -3
- data/core/module.rbs +1 -1
- data/core/numeric.rbs +10 -0
- data/core/proc.rbs +1 -1
- data/core/random.rbs +4 -2
- data/core/range.rbs +2 -2
- data/core/struct.rbs +3 -2
- data/core/thread.rbs +1 -1
- data/docs/CONTRIBUTING.md +5 -3
- data/docs/rbs_by_example.md +328 -0
- data/docs/sigs.md +21 -2
- data/docs/stdlib.md +1 -1
- data/docs/syntax.md +11 -14
- data/lib/rbs.rb +1 -0
- data/lib/rbs/ast/annotation.rb +2 -2
- data/lib/rbs/ast/comment.rb +2 -2
- data/lib/rbs/ast/declarations.rb +37 -22
- data/lib/rbs/ast/members.rb +26 -26
- data/lib/rbs/cli.rb +3 -0
- data/lib/rbs/constant_table.rb +4 -1
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder.rb +16 -18
- data/lib/rbs/definition_builder/ancestor_builder.rb +10 -2
- data/lib/rbs/definition_builder/method_builder.rb +4 -2
- data/lib/rbs/errors.rb +36 -0
- data/lib/rbs/location.rb +106 -2
- data/lib/rbs/locator.rb +205 -0
- data/lib/rbs/method_type.rb +2 -2
- data/lib/rbs/parser.rb +1315 -962
- data/lib/rbs/parser.y +411 -75
- data/lib/rbs/prototype/rb.rb +7 -3
- data/lib/rbs/prototype/runtime.rb +118 -42
- data/lib/rbs/test/hook.rb +8 -2
- data/lib/rbs/type_name.rb +2 -3
- data/lib/rbs/type_name_resolver.rb +1 -1
- data/lib/rbs/types.rb +36 -34
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +4 -2
- data/rbs.gemspec +1 -1
- data/sig/ancestor_builder.rbs +2 -0
- data/sig/annotation.rbs +1 -1
- data/sig/cli.rbs +31 -21
- data/sig/comment.rbs +1 -1
- data/sig/declarations.rbs +106 -21
- data/sig/environment.rbs +2 -2
- data/sig/errors.rbs +15 -0
- data/sig/location.rbs +84 -3
- data/sig/locator.rbs +44 -0
- data/sig/members.rbs +76 -12
- data/sig/method_builder.rbs +1 -1
- data/sig/method_types.rbs +1 -1
- data/sig/namespace.rbs +1 -1
- data/sig/polyfill.rbs +4 -17
- data/sig/rbs.rbs +8 -4
- data/sig/typename.rbs +1 -1
- data/sig/types.rbs +60 -19
- data/sig/util.rbs +0 -4
- data/sig/writer.rbs +8 -2
- data/stdlib/dbm/0/dbm.rbs +43 -30
- data/stdlib/mutex_m/0/mutex_m.rbs +1 -1
- data/stdlib/net-http/0/net-http.rbs +1846 -0
- data/stdlib/optparse/0/optparse.rbs +1214 -0
- data/stdlib/resolv/0/resolv.rbs +1504 -0
- data/stdlib/rubygems/0/requirement.rbs +84 -2
- data/stdlib/rubygems/0/version.rbs +2 -1
- data/stdlib/shellwords/0/shellwords.rbs +252 -0
- data/stdlib/socket/0/addrinfo.rbs +469 -0
- data/stdlib/socket/0/basic_socket.rbs +503 -0
- data/stdlib/socket/0/ip_socket.rbs +72 -0
- data/stdlib/socket/0/socket.rbs +2687 -0
- data/stdlib/socket/0/tcp_server.rbs +177 -0
- data/stdlib/socket/0/tcp_socket.rbs +35 -0
- data/stdlib/socket/0/udp_socket.rbs +111 -0
- data/stdlib/socket/0/unix_server.rbs +154 -0
- data/stdlib/socket/0/unix_socket.rbs +132 -0
- data/stdlib/timeout/0/timeout.rbs +5 -0
- data/steep/Gemfile.lock +19 -16
- metadata +18 -11
- data/bin/annotate-with-rdoc +0 -153
- data/bin/console +0 -14
- data/bin/query-rdoc +0 -103
- data/bin/rbs-prof +0 -9
- data/bin/run_in_md.rb +0 -49
- data/bin/setup +0 -8
- data/bin/sort +0 -89
- data/bin/steep +0 -4
- data/bin/test_runner.rb +0 -29
data/lib/rbs.rb
CHANGED
data/lib/rbs/ast/annotation.rb
CHANGED
data/lib/rbs/ast/comment.rb
CHANGED
@@ -19,8 +19,8 @@ module RBS
|
|
19
19
|
self.class.hash ^ string.hash
|
20
20
|
end
|
21
21
|
|
22
|
-
def to_json(
|
23
|
-
{ string: string, location: location }.to_json(
|
22
|
+
def to_json(state = _ = nil)
|
23
|
+
{ string: string, location: location }.to_json(state)
|
24
24
|
end
|
25
25
|
|
26
26
|
def concat(string:, location:)
|
data/lib/rbs/ast/declarations.rb
CHANGED
@@ -7,13 +7,28 @@ module RBS
|
|
7
7
|
class ModuleTypeParams
|
8
8
|
attr_reader :params
|
9
9
|
|
10
|
-
TypeParam = _ = Struct.new(:name, :variance, :skip_validation, keyword_init: true) do
|
11
|
-
|
10
|
+
TypeParam = _ = Struct.new(:name, :variance, :skip_validation, :location, keyword_init: true) do
|
11
|
+
# @implements TypeParam
|
12
|
+
|
13
|
+
def to_json(state = _ = nil)
|
12
14
|
{
|
13
15
|
name: name,
|
14
16
|
variance: variance,
|
15
17
|
skip_validation: skip_validation,
|
16
|
-
}.to_json(
|
18
|
+
}.to_json(state)
|
19
|
+
end
|
20
|
+
|
21
|
+
def ==(other)
|
22
|
+
other.is_a?(TypeParam) &&
|
23
|
+
other.name == name &&
|
24
|
+
other.variance == variance &&
|
25
|
+
other.skip_validation == skip_validation
|
26
|
+
end
|
27
|
+
|
28
|
+
alias eql? ==
|
29
|
+
|
30
|
+
def hash
|
31
|
+
self.class.hash ^ name.hash ^ variance.hash ^ skip_validation.hash
|
17
32
|
end
|
18
33
|
end
|
19
34
|
|
@@ -40,10 +55,10 @@ module RBS
|
|
40
55
|
params.find {|p| p.name == name }
|
41
56
|
end
|
42
57
|
|
43
|
-
def to_json(
|
58
|
+
def to_json(state = _ = nil)
|
44
59
|
{
|
45
60
|
params: params
|
46
|
-
}.to_json(
|
61
|
+
}.to_json(state)
|
47
62
|
end
|
48
63
|
|
49
64
|
def each(&block)
|
@@ -80,7 +95,7 @@ module RBS
|
|
80
95
|
ModuleTypeParams.new().tap do |params|
|
81
96
|
names.each.with_index do |new_name, index|
|
82
97
|
param = self.params[index]
|
83
|
-
params.add(TypeParam.new(name: new_name, variance: param.variance, skip_validation: param.skip_validation))
|
98
|
+
params.add(TypeParam.new(name: new_name, variance: param.variance, skip_validation: param.skip_validation, location: param.location))
|
84
99
|
end
|
85
100
|
end
|
86
101
|
end
|
@@ -154,12 +169,12 @@ module RBS
|
|
154
169
|
self.class.hash ^ name.hash ^ args.hash
|
155
170
|
end
|
156
171
|
|
157
|
-
def to_json(
|
172
|
+
def to_json(state = _ = nil)
|
158
173
|
{
|
159
174
|
name: name,
|
160
175
|
args: args,
|
161
176
|
location: location
|
162
|
-
}.to_json(
|
177
|
+
}.to_json(state)
|
163
178
|
end
|
164
179
|
end
|
165
180
|
|
@@ -198,7 +213,7 @@ module RBS
|
|
198
213
|
self.class.hash ^ name.hash ^ type_params.hash ^ super_class.hash ^ members.hash
|
199
214
|
end
|
200
215
|
|
201
|
-
def to_json(
|
216
|
+
def to_json(state = _ = nil)
|
202
217
|
{
|
203
218
|
declaration: :class,
|
204
219
|
name: name,
|
@@ -208,7 +223,7 @@ module RBS
|
|
208
223
|
annotations: annotations,
|
209
224
|
location: location,
|
210
225
|
comment: comment
|
211
|
-
}.to_json(
|
226
|
+
}.to_json(state)
|
212
227
|
end
|
213
228
|
end
|
214
229
|
|
@@ -234,12 +249,12 @@ module RBS
|
|
234
249
|
self.class.hash ^ name.hash ^ args.hash ^ location.hash
|
235
250
|
end
|
236
251
|
|
237
|
-
def to_json(
|
252
|
+
def to_json(state = _ = nil)
|
238
253
|
{
|
239
254
|
name: name,
|
240
255
|
args: args,
|
241
256
|
location: location
|
242
|
-
}.to_json(
|
257
|
+
}.to_json(state)
|
243
258
|
end
|
244
259
|
|
245
260
|
def to_s
|
@@ -286,7 +301,7 @@ module RBS
|
|
286
301
|
self.class.hash ^ name.hash ^ type_params.hash ^ self_types.hash ^ members.hash
|
287
302
|
end
|
288
303
|
|
289
|
-
def to_json(
|
304
|
+
def to_json(state = _ = nil)
|
290
305
|
{
|
291
306
|
declaration: :module,
|
292
307
|
name: name,
|
@@ -296,7 +311,7 @@ module RBS
|
|
296
311
|
annotations: annotations,
|
297
312
|
location: location,
|
298
313
|
comment: comment
|
299
|
-
}.to_json(
|
314
|
+
}.to_json(state)
|
300
315
|
end
|
301
316
|
end
|
302
317
|
|
@@ -332,7 +347,7 @@ module RBS
|
|
332
347
|
self.class.hash ^ type_params.hash ^ members.hash
|
333
348
|
end
|
334
349
|
|
335
|
-
def to_json(
|
350
|
+
def to_json(state = _ = nil)
|
336
351
|
{
|
337
352
|
declaration: :interface,
|
338
353
|
name: name,
|
@@ -341,7 +356,7 @@ module RBS
|
|
341
356
|
annotations: annotations,
|
342
357
|
location: location,
|
343
358
|
comment: comment
|
344
|
-
}.to_json(
|
359
|
+
}.to_json(state)
|
345
360
|
end
|
346
361
|
end
|
347
362
|
|
@@ -372,7 +387,7 @@ module RBS
|
|
372
387
|
self.class.hash ^ name.hash ^ type.hash
|
373
388
|
end
|
374
389
|
|
375
|
-
def to_json(
|
390
|
+
def to_json(state = _ = nil)
|
376
391
|
{
|
377
392
|
declaration: :alias,
|
378
393
|
name: name,
|
@@ -380,7 +395,7 @@ module RBS
|
|
380
395
|
annotations: annotations,
|
381
396
|
location: location,
|
382
397
|
comment: comment
|
383
|
-
}.to_json(
|
398
|
+
}.to_json(state)
|
384
399
|
end
|
385
400
|
end
|
386
401
|
|
@@ -409,14 +424,14 @@ module RBS
|
|
409
424
|
self.class.hash ^ name.hash ^ type.hash
|
410
425
|
end
|
411
426
|
|
412
|
-
def to_json(
|
427
|
+
def to_json(state = _ = nil)
|
413
428
|
{
|
414
429
|
declaration: :constant,
|
415
430
|
name: name,
|
416
431
|
type: type,
|
417
432
|
location: location,
|
418
433
|
comment: comment
|
419
|
-
}.to_json(
|
434
|
+
}.to_json(state)
|
420
435
|
end
|
421
436
|
end
|
422
437
|
|
@@ -445,14 +460,14 @@ module RBS
|
|
445
460
|
self.class.hash ^ name.hash ^ type.hash
|
446
461
|
end
|
447
462
|
|
448
|
-
def to_json(
|
463
|
+
def to_json(state = _ = nil)
|
449
464
|
{
|
450
465
|
declaration: :global,
|
451
466
|
name: name,
|
452
467
|
type: type,
|
453
468
|
location: location,
|
454
469
|
comment: comment
|
455
|
-
}.to_json(
|
470
|
+
}.to_json(state)
|
456
471
|
end
|
457
472
|
end
|
458
473
|
end
|
data/lib/rbs/ast/members.rb
CHANGED
@@ -61,7 +61,7 @@ module RBS
|
|
61
61
|
)
|
62
62
|
end
|
63
63
|
|
64
|
-
def to_json(
|
64
|
+
def to_json(state = _ = nil)
|
65
65
|
{
|
66
66
|
member: :method_definition,
|
67
67
|
kind: kind,
|
@@ -70,7 +70,7 @@ module RBS
|
|
70
70
|
location: location,
|
71
71
|
comment: comment,
|
72
72
|
overload: overload
|
73
|
-
}.to_json(
|
73
|
+
}.to_json(state)
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -101,42 +101,42 @@ module RBS
|
|
101
101
|
class InstanceVariable < Base
|
102
102
|
include Var
|
103
103
|
|
104
|
-
def to_json(
|
104
|
+
def to_json(state = _ = nil)
|
105
105
|
{
|
106
106
|
member: :instance_variable,
|
107
107
|
name: name,
|
108
108
|
type: type,
|
109
109
|
location: location,
|
110
110
|
comment: comment
|
111
|
-
}.to_json(
|
111
|
+
}.to_json(state)
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
115
|
class ClassInstanceVariable < Base
|
116
116
|
include Var
|
117
117
|
|
118
|
-
def to_json(
|
118
|
+
def to_json(state = _ = nil)
|
119
119
|
{
|
120
120
|
member: :class_instance_variable,
|
121
121
|
name: name,
|
122
122
|
type: type,
|
123
123
|
location: location,
|
124
124
|
comment: comment
|
125
|
-
}.to_json(
|
125
|
+
}.to_json(state)
|
126
126
|
end
|
127
127
|
end
|
128
128
|
|
129
129
|
class ClassVariable < Base
|
130
130
|
include Var
|
131
131
|
|
132
|
-
def to_json(
|
132
|
+
def to_json(state = _ = nil)
|
133
133
|
{
|
134
134
|
member: :class_variable,
|
135
135
|
name: name,
|
136
136
|
type: type,
|
137
137
|
location: location,
|
138
138
|
comment: comment
|
139
|
-
}.to_json(
|
139
|
+
}.to_json(state)
|
140
140
|
end
|
141
141
|
end
|
142
142
|
|
@@ -171,7 +171,7 @@ module RBS
|
|
171
171
|
class Include < Base
|
172
172
|
include Mixin
|
173
173
|
|
174
|
-
def to_json(
|
174
|
+
def to_json(state = _ = nil)
|
175
175
|
{
|
176
176
|
member: :include,
|
177
177
|
name: name,
|
@@ -179,14 +179,14 @@ module RBS
|
|
179
179
|
annotations: annotations,
|
180
180
|
location: location,
|
181
181
|
comment: comment
|
182
|
-
}.to_json(
|
182
|
+
}.to_json(state)
|
183
183
|
end
|
184
184
|
end
|
185
185
|
|
186
186
|
class Extend < Base
|
187
187
|
include Mixin
|
188
188
|
|
189
|
-
def to_json(
|
189
|
+
def to_json(state = _ = nil)
|
190
190
|
{
|
191
191
|
member: :extend,
|
192
192
|
name: name,
|
@@ -194,14 +194,14 @@ module RBS
|
|
194
194
|
annotations: annotations,
|
195
195
|
location: location,
|
196
196
|
comment: comment
|
197
|
-
}.to_json(
|
197
|
+
}.to_json(state)
|
198
198
|
end
|
199
199
|
end
|
200
200
|
|
201
201
|
class Prepend < Base
|
202
202
|
include Mixin
|
203
203
|
|
204
|
-
def to_json(
|
204
|
+
def to_json(state = _ = nil)
|
205
205
|
{
|
206
206
|
member: :prepend,
|
207
207
|
name: name,
|
@@ -209,7 +209,7 @@ module RBS
|
|
209
209
|
annotations: annotations,
|
210
210
|
location: location,
|
211
211
|
comment: comment
|
212
|
-
}.to_json(
|
212
|
+
}.to_json(state)
|
213
213
|
end
|
214
214
|
end
|
215
215
|
|
@@ -263,7 +263,7 @@ module RBS
|
|
263
263
|
class AttrReader < Base
|
264
264
|
include Attribute
|
265
265
|
|
266
|
-
def to_json(
|
266
|
+
def to_json(state = _ = nil)
|
267
267
|
{
|
268
268
|
member: :attr_reader,
|
269
269
|
name: name,
|
@@ -273,14 +273,14 @@ module RBS
|
|
273
273
|
annotations: annotations,
|
274
274
|
location: location,
|
275
275
|
comment: comment
|
276
|
-
}.to_json(
|
276
|
+
}.to_json(state)
|
277
277
|
end
|
278
278
|
end
|
279
279
|
|
280
280
|
class AttrAccessor < Base
|
281
281
|
include Attribute
|
282
282
|
|
283
|
-
def to_json(
|
283
|
+
def to_json(state = _ = nil)
|
284
284
|
{
|
285
285
|
member: :attr_accessor,
|
286
286
|
name: name,
|
@@ -290,14 +290,14 @@ module RBS
|
|
290
290
|
annotations: annotations,
|
291
291
|
location: location,
|
292
292
|
comment: comment
|
293
|
-
}.to_json(
|
293
|
+
}.to_json(state)
|
294
294
|
end
|
295
295
|
end
|
296
296
|
|
297
297
|
class AttrWriter < Base
|
298
298
|
include Attribute
|
299
299
|
|
300
|
-
def to_json(
|
300
|
+
def to_json(state = _ = nil)
|
301
301
|
{
|
302
302
|
member: :attr_writer,
|
303
303
|
name: name,
|
@@ -307,7 +307,7 @@ module RBS
|
|
307
307
|
annotations: annotations,
|
308
308
|
location: location,
|
309
309
|
comment: comment
|
310
|
-
}.to_json(
|
310
|
+
}.to_json(state)
|
311
311
|
end
|
312
312
|
end
|
313
313
|
|
@@ -332,16 +332,16 @@ module RBS
|
|
332
332
|
class Public < Base
|
333
333
|
include LocationOnly
|
334
334
|
|
335
|
-
def to_json(
|
336
|
-
{ member: :public, location: location }.to_json(
|
335
|
+
def to_json(state = _ = nil)
|
336
|
+
{ member: :public, location: location }.to_json(state)
|
337
337
|
end
|
338
338
|
end
|
339
339
|
|
340
340
|
class Private < Base
|
341
341
|
include LocationOnly
|
342
342
|
|
343
|
-
def to_json(
|
344
|
-
{ member: :private, location: location }.to_json(
|
343
|
+
def to_json(state = _ = nil)
|
344
|
+
{ member: :private, location: location }.to_json(state)
|
345
345
|
end
|
346
346
|
end
|
347
347
|
|
@@ -375,7 +375,7 @@ module RBS
|
|
375
375
|
self.class.hash ^ new_name.hash ^ old_name.hash ^ kind.hash
|
376
376
|
end
|
377
377
|
|
378
|
-
def to_json(
|
378
|
+
def to_json(state = _ = nil)
|
379
379
|
{
|
380
380
|
member: :alias,
|
381
381
|
new_name: new_name,
|
@@ -384,7 +384,7 @@ module RBS
|
|
384
384
|
annotations: annotations,
|
385
385
|
location: location,
|
386
386
|
comment: comment
|
387
|
-
}.to_json(
|
387
|
+
}.to_json(state)
|
388
388
|
end
|
389
389
|
|
390
390
|
def instance?
|
data/lib/rbs/cli.rb
CHANGED
@@ -816,9 +816,12 @@ EOB
|
|
816
816
|
'RBS_TEST_TARGET' => (targets.join(',') unless targets.empty?)
|
817
817
|
}
|
818
818
|
|
819
|
+
# @type var out: String
|
820
|
+
# @type var err: String
|
819
821
|
out, err, status = Open3.capture3(env_hash, *args)
|
820
822
|
stdout.print(out)
|
821
823
|
stderr.print(err)
|
824
|
+
|
822
825
|
status
|
823
826
|
end
|
824
827
|
end
|
data/lib/rbs/constant_table.rb
CHANGED
@@ -56,7 +56,10 @@ module RBS
|
|
56
56
|
name_to_constant(TypeName.new(name: head, namespace: Namespace.root))
|
57
57
|
else
|
58
58
|
resolve_constant_reference_context(head, context: context) ||
|
59
|
-
|
59
|
+
context.first.yield_self do |first_contet|
|
60
|
+
raise unless first_contet
|
61
|
+
resolve_constant_reference_inherit(head, scopes: constant_scopes(first_contet.to_type_name))
|
62
|
+
end
|
60
63
|
end
|
61
64
|
|
62
65
|
tail.inject(head_constant) do |constant, name|
|
data/lib/rbs/definition.rb
CHANGED