rbs 1.1.1 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +34 -0
  3. data/Rakefile +2 -0
  4. data/core/array.rbs +1 -1
  5. data/core/enumerable.rbs +1 -1
  6. data/core/hash.rbs +13 -5
  7. data/core/io.rbs +3 -3
  8. data/core/module.rbs +1 -1
  9. data/core/numeric.rbs +10 -0
  10. data/core/proc.rbs +1 -1
  11. data/core/random.rbs +4 -2
  12. data/core/range.rbs +2 -2
  13. data/core/struct.rbs +3 -2
  14. data/core/thread.rbs +1 -1
  15. data/docs/CONTRIBUTING.md +5 -3
  16. data/docs/sigs.md +18 -1
  17. data/docs/syntax.md +11 -11
  18. data/lib/rbs.rb +1 -0
  19. data/lib/rbs/ast/annotation.rb +2 -2
  20. data/lib/rbs/ast/comment.rb +2 -2
  21. data/lib/rbs/ast/declarations.rb +37 -22
  22. data/lib/rbs/ast/members.rb +26 -26
  23. data/lib/rbs/cli.rb +3 -0
  24. data/lib/rbs/constant_table.rb +4 -1
  25. data/lib/rbs/definition.rb +1 -1
  26. data/lib/rbs/definition_builder.rb +14 -0
  27. data/lib/rbs/definition_builder/ancestor_builder.rb +1 -0
  28. data/lib/rbs/definition_builder/method_builder.rb +4 -2
  29. data/lib/rbs/location.rb +106 -2
  30. data/lib/rbs/locator.rb +205 -0
  31. data/lib/rbs/method_type.rb +2 -2
  32. data/lib/rbs/parser.rb +1050 -713
  33. data/lib/rbs/parser.y +403 -71
  34. data/lib/rbs/test/hook.rb +8 -2
  35. data/lib/rbs/type_name.rb +2 -3
  36. data/lib/rbs/type_name_resolver.rb +1 -1
  37. data/lib/rbs/types.rb +36 -34
  38. data/lib/rbs/version.rb +1 -1
  39. data/lib/rbs/writer.rb +4 -2
  40. data/sig/annotation.rbs +1 -1
  41. data/sig/cli.rbs +31 -21
  42. data/sig/comment.rbs +1 -1
  43. data/sig/declarations.rbs +106 -21
  44. data/sig/environment.rbs +2 -2
  45. data/sig/location.rbs +84 -3
  46. data/sig/locator.rbs +44 -0
  47. data/sig/members.rbs +76 -12
  48. data/sig/method_builder.rbs +1 -1
  49. data/sig/method_types.rbs +1 -1
  50. data/sig/polyfill.rbs +13 -8
  51. data/sig/rbs.rbs +8 -4
  52. data/sig/typename.rbs +1 -1
  53. data/sig/types.rbs +60 -19
  54. data/sig/util.rbs +0 -4
  55. data/sig/writer.rbs +8 -2
  56. data/stdlib/rubygems/0/requirement.rbs +84 -2
  57. data/stdlib/rubygems/0/version.rbs +2 -1
  58. data/stdlib/shellwords/0/shellwords.rbs +252 -0
  59. data/steep/Gemfile.lock +16 -13
  60. metadata +5 -2
@@ -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
@@ -746,6 +746,20 @@ module RBS
746
746
  end
747
747
  )
748
748
  end
749
+
750
+ defs = method.defs.map do |defn|
751
+ defn.update(
752
+ type: sub.empty? ? defn.type : defn.type.sub(sub),
753
+ implemented_in: case implemented_in
754
+ when :keep
755
+ defn.implemented_in
756
+ when nil
757
+ nil
758
+ else
759
+ implemented_in
760
+ end
761
+ )
762
+ end
749
763
  end
750
764
 
751
765
  super_method = methods[name]
@@ -508,6 +508,7 @@ module RBS
508
508
  included_interfaces = one_ancestors.included_interfaces or raise
509
509
  included_interfaces.each do |a|
510
510
  included_ancestors = interface_ancestors(a.name, building_ancestors: building_ancestors)
511
+
511
512
  ancestors.unshift(*included_ancestors.apply(a.args, location: entry.decl.location))
512
513
  end
513
514