rbs 1.1.1 → 1.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +5 -1
  3. data/.gitignore +2 -0
  4. data/CHANGELOG.md +81 -0
  5. data/README.md +1 -1
  6. data/Rakefile +11 -0
  7. data/Steepfile +1 -0
  8. data/core/array.rbs +2 -2
  9. data/core/basic_object.rbs +1 -1
  10. data/core/enumerable.rbs +1 -1
  11. data/core/hash.rbs +13 -5
  12. data/core/io.rbs +4 -4
  13. data/core/kernel.rbs +2 -2
  14. data/core/marshal.rbs +4 -3
  15. data/core/module.rbs +1 -1
  16. data/core/numeric.rbs +10 -0
  17. data/core/proc.rbs +1 -1
  18. data/core/random.rbs +4 -2
  19. data/core/range.rbs +2 -2
  20. data/core/struct.rbs +3 -2
  21. data/core/thread.rbs +1 -1
  22. data/docs/CONTRIBUTING.md +5 -3
  23. data/docs/rbs_by_example.md +328 -0
  24. data/docs/sigs.md +21 -2
  25. data/docs/stdlib.md +1 -1
  26. data/docs/syntax.md +11 -14
  27. data/lib/rbs.rb +1 -0
  28. data/lib/rbs/ast/annotation.rb +2 -2
  29. data/lib/rbs/ast/comment.rb +2 -2
  30. data/lib/rbs/ast/declarations.rb +37 -22
  31. data/lib/rbs/ast/members.rb +26 -26
  32. data/lib/rbs/cli.rb +3 -0
  33. data/lib/rbs/constant_table.rb +4 -1
  34. data/lib/rbs/definition.rb +1 -1
  35. data/lib/rbs/definition_builder.rb +16 -18
  36. data/lib/rbs/definition_builder/ancestor_builder.rb +10 -2
  37. data/lib/rbs/definition_builder/method_builder.rb +4 -2
  38. data/lib/rbs/errors.rb +36 -0
  39. data/lib/rbs/location.rb +106 -2
  40. data/lib/rbs/locator.rb +205 -0
  41. data/lib/rbs/method_type.rb +2 -2
  42. data/lib/rbs/parser.rb +1315 -962
  43. data/lib/rbs/parser.y +411 -75
  44. data/lib/rbs/prototype/rb.rb +7 -3
  45. data/lib/rbs/prototype/runtime.rb +118 -42
  46. data/lib/rbs/test/hook.rb +8 -2
  47. data/lib/rbs/type_name.rb +2 -3
  48. data/lib/rbs/type_name_resolver.rb +1 -1
  49. data/lib/rbs/types.rb +36 -34
  50. data/lib/rbs/version.rb +1 -1
  51. data/lib/rbs/writer.rb +4 -2
  52. data/rbs.gemspec +1 -1
  53. data/sig/ancestor_builder.rbs +2 -0
  54. data/sig/annotation.rbs +1 -1
  55. data/sig/cli.rbs +31 -21
  56. data/sig/comment.rbs +1 -1
  57. data/sig/declarations.rbs +106 -21
  58. data/sig/environment.rbs +2 -2
  59. data/sig/errors.rbs +15 -0
  60. data/sig/location.rbs +84 -3
  61. data/sig/locator.rbs +44 -0
  62. data/sig/members.rbs +76 -12
  63. data/sig/method_builder.rbs +1 -1
  64. data/sig/method_types.rbs +1 -1
  65. data/sig/namespace.rbs +1 -1
  66. data/sig/polyfill.rbs +4 -17
  67. data/sig/rbs.rbs +8 -4
  68. data/sig/typename.rbs +1 -1
  69. data/sig/types.rbs +60 -19
  70. data/sig/util.rbs +0 -4
  71. data/sig/writer.rbs +8 -2
  72. data/stdlib/dbm/0/dbm.rbs +43 -30
  73. data/stdlib/mutex_m/0/mutex_m.rbs +1 -1
  74. data/stdlib/net-http/0/net-http.rbs +1846 -0
  75. data/stdlib/optparse/0/optparse.rbs +1214 -0
  76. data/stdlib/resolv/0/resolv.rbs +1504 -0
  77. data/stdlib/rubygems/0/requirement.rbs +84 -2
  78. data/stdlib/rubygems/0/version.rbs +2 -1
  79. data/stdlib/shellwords/0/shellwords.rbs +252 -0
  80. data/stdlib/socket/0/addrinfo.rbs +469 -0
  81. data/stdlib/socket/0/basic_socket.rbs +503 -0
  82. data/stdlib/socket/0/ip_socket.rbs +72 -0
  83. data/stdlib/socket/0/socket.rbs +2687 -0
  84. data/stdlib/socket/0/tcp_server.rbs +177 -0
  85. data/stdlib/socket/0/tcp_socket.rbs +35 -0
  86. data/stdlib/socket/0/udp_socket.rbs +111 -0
  87. data/stdlib/socket/0/unix_server.rbs +154 -0
  88. data/stdlib/socket/0/unix_socket.rbs +132 -0
  89. data/stdlib/timeout/0/timeout.rbs +5 -0
  90. data/steep/Gemfile.lock +19 -16
  91. metadata +18 -11
  92. data/bin/annotate-with-rdoc +0 -153
  93. data/bin/console +0 -14
  94. data/bin/query-rdoc +0 -103
  95. data/bin/rbs-prof +0 -9
  96. data/bin/run_in_md.rb +0 -49
  97. data/bin/setup +0 -8
  98. data/bin/sort +0 -89
  99. data/bin/steep +0 -4
  100. data/bin/test_runner.rb +0 -29
data/lib/rbs.rb CHANGED
@@ -43,6 +43,7 @@ require "rbs/validator"
43
43
  require "rbs/factory"
44
44
  require "rbs/repository"
45
45
  require "rbs/ancestor_graph"
46
+ require "rbs/locator"
46
47
 
47
48
  begin
48
49
  require "rbs/parser"
@@ -19,8 +19,8 @@ module RBS
19
19
  self.class.hash ^ string.hash
20
20
  end
21
21
 
22
- def to_json(*a)
23
- { string: string, location: location }.to_json(*a)
22
+ def to_json(state = _ = nil)
23
+ { string: string, location: location }.to_json(state)
24
24
  end
25
25
  end
26
26
  end
@@ -19,8 +19,8 @@ module RBS
19
19
  self.class.hash ^ string.hash
20
20
  end
21
21
 
22
- def to_json(*a)
23
- { string: string, location: location }.to_json(*a)
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:)
@@ -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
- def to_json(*a)
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(*a)
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(*a)
58
+ def to_json(state = _ = nil)
44
59
  {
45
60
  params: params
46
- }.to_json(*a)
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(*a)
172
+ def to_json(state = _ = nil)
158
173
  {
159
174
  name: name,
160
175
  args: args,
161
176
  location: location
162
- }.to_json(*a)
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(*a)
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(*a)
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(*a)
252
+ def to_json(state = _ = nil)
238
253
  {
239
254
  name: name,
240
255
  args: args,
241
256
  location: location
242
- }.to_json(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
470
+ }.to_json(state)
456
471
  end
457
472
  end
458
473
  end
@@ -61,7 +61,7 @@ module RBS
61
61
  )
62
62
  end
63
63
 
64
- def to_json(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
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(*a)
336
- { member: :public, location: location }.to_json(*a)
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(*a)
344
- { member: :private, location: location }.to_json(*a)
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(*a)
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(*a)
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
@@ -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
- resolve_constant_reference_inherit(head, scopes: constant_scopes(context.first.to_type_name))
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|
@@ -122,7 +122,7 @@ module RBS
122
122
  end
123
123
 
124
124
  def annotations
125
- @annotations ||= @extra_annotations + defs.flat_map(&:annotations)
125
+ @annotations ||= @extra_annotations + defs.flat_map {|d| d.annotations }
126
126
  end
127
127
 
128
128
  def members