rbs 0.2.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (81) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +7 -1
  3. data/.gitignore +1 -1
  4. data/CHANGELOG.md +35 -0
  5. data/COPYING +1 -1
  6. data/Gemfile +16 -2
  7. data/README.md +87 -48
  8. data/Rakefile +54 -22
  9. data/bin/rbs-prof +9 -0
  10. data/bin/run_in_md.rb +49 -0
  11. data/bin/test_runner.rb +0 -2
  12. data/docs/sigs.md +6 -6
  13. data/docs/stdlib.md +3 -5
  14. data/docs/syntax.md +6 -3
  15. data/goodcheck.yml +65 -0
  16. data/lib/rbs.rb +3 -0
  17. data/lib/rbs/ast/declarations.rb +115 -14
  18. data/lib/rbs/ast/members.rb +41 -17
  19. data/lib/rbs/cli.rb +301 -123
  20. data/lib/rbs/constant.rb +4 -4
  21. data/lib/rbs/constant_table.rb +64 -53
  22. data/lib/rbs/definition.rb +175 -59
  23. data/lib/rbs/definition_builder.rb +646 -603
  24. data/lib/rbs/environment.rb +352 -210
  25. data/lib/rbs/environment_walker.rb +14 -23
  26. data/lib/rbs/errors.rb +159 -3
  27. data/lib/rbs/factory.rb +14 -0
  28. data/lib/rbs/namespace.rb +18 -0
  29. data/lib/rbs/parser.y +75 -21
  30. data/lib/rbs/prototype/rb.rb +119 -117
  31. data/lib/rbs/prototype/rbi.rb +5 -3
  32. data/lib/rbs/prototype/runtime.rb +34 -7
  33. data/lib/rbs/substitution.rb +8 -1
  34. data/lib/rbs/test.rb +81 -3
  35. data/lib/rbs/test/errors.rb +1 -1
  36. data/lib/rbs/test/hook.rb +133 -259
  37. data/lib/rbs/test/observer.rb +17 -0
  38. data/lib/rbs/test/setup.rb +13 -14
  39. data/lib/rbs/test/spy.rb +0 -321
  40. data/lib/rbs/test/tester.rb +116 -0
  41. data/lib/rbs/test/type_check.rb +44 -7
  42. data/lib/rbs/type_name_resolver.rb +58 -0
  43. data/lib/rbs/types.rb +94 -2
  44. data/lib/rbs/validator.rb +51 -0
  45. data/lib/rbs/variance_calculator.rb +12 -2
  46. data/lib/rbs/version.rb +1 -1
  47. data/lib/rbs/writer.rb +127 -91
  48. data/rbs.gemspec +0 -9
  49. data/schema/annotation.json +14 -0
  50. data/schema/comment.json +26 -0
  51. data/schema/decls.json +353 -0
  52. data/schema/function.json +87 -0
  53. data/schema/location.json +56 -0
  54. data/schema/members.json +248 -0
  55. data/schema/methodType.json +44 -0
  56. data/schema/types.json +299 -0
  57. data/stdlib/benchmark/benchmark.rbs +151 -151
  58. data/stdlib/builtin/encoding.rbs +2 -0
  59. data/stdlib/builtin/enumerable.rbs +2 -2
  60. data/stdlib/builtin/enumerator.rbs +3 -1
  61. data/stdlib/builtin/fiber.rbs +5 -1
  62. data/stdlib/builtin/file.rbs +0 -3
  63. data/stdlib/builtin/io.rbs +4 -4
  64. data/stdlib/builtin/proc.rbs +1 -2
  65. data/stdlib/builtin/symbol.rbs +1 -1
  66. data/stdlib/builtin/thread.rbs +2 -2
  67. data/stdlib/csv/csv.rbs +4 -6
  68. data/stdlib/fiber/fiber.rbs +117 -0
  69. data/stdlib/json/json.rbs +1 -1
  70. data/stdlib/logger/formatter.rbs +23 -0
  71. data/stdlib/logger/log_device.rbs +39 -0
  72. data/stdlib/logger/logger.rbs +507 -0
  73. data/stdlib/logger/period.rbs +7 -0
  74. data/stdlib/logger/severity.rbs +8 -0
  75. data/stdlib/mutex_m/mutex_m.rbs +77 -0
  76. data/stdlib/pathname/pathname.rbs +6 -6
  77. data/stdlib/prime/integer-extension.rbs +1 -1
  78. data/stdlib/prime/prime.rbs +44 -44
  79. data/stdlib/tmpdir/tmpdir.rbs +1 -1
  80. metadata +26 -116
  81. data/lib/rbs/test/test_helper.rb +0 -183
@@ -3,279 +3,421 @@ module RBS
3
3
  attr_reader :buffers
4
4
  attr_reader :declarations
5
5
 
6
- attr_reader :name_to_decl
7
- attr_reader :name_to_extensions
8
- attr_reader :name_to_constant
9
- attr_reader :name_to_global
10
- attr_reader :name_to_alias
11
-
12
- def initialize
13
- @buffers = []
14
- @declarations = []
15
-
16
- @name_to_decl = {}
17
- @name_to_extensions = {}
18
- @name_to_constant = {}
19
- @name_to_global = {}
20
- @name_to_alias = {}
6
+ attr_reader :class_decls
7
+ attr_reader :interface_decls
8
+ attr_reader :alias_decls
9
+ attr_reader :constant_decls
10
+ attr_reader :global_decls
11
+
12
+ module ContextUtil
13
+ def context
14
+ @context ||= begin
15
+ (outer + [decl]).each.with_object([Namespace.root]) do |decl, array|
16
+ array.unshift(array.first + decl.name.to_namespace)
17
+ end
18
+ end
19
+ end
21
20
  end
22
21
 
23
- def initialize_copy(other)
24
- @buffers = other.buffers.dup
25
- @declarations = other.declarations.dup
22
+ class MultiEntry
23
+ D = Struct.new(:decl, :outer, keyword_init: true) do
24
+ include ContextUtil
25
+ end
26
26
 
27
- @name_to_decl = other.name_to_decl.dup
28
- @name_to_extensions = other.name_to_extensions.dup
29
- @name_to_constant = other.name_to_constant.dup
30
- @name_to_global = other.name_to_global.dup
31
- @name_to_alias = other.name_to_alias.dup
32
- end
27
+ attr_reader :name
28
+ attr_reader :decls
33
29
 
34
- def cache_name(cache, name:, decl:)
35
- if cache.key?(name)
36
- raise DuplicatedDeclarationError.new(name, decl, cache[name])
30
+ def initialize(name:)
31
+ @name = name
32
+ @decls = []
37
33
  end
38
- cache[name] = decl
39
- end
40
34
 
41
- def <<(decl)
42
- declarations << decl
43
- case decl
44
- when AST::Declarations::Class, AST::Declarations::Module, AST::Declarations::Interface
45
- cache_name name_to_decl, name: decl.name.absolute!, decl: decl
46
- when AST::Declarations::Extension
47
- yield_self do
48
- name = decl.name.absolute!
49
- exts = name_to_extensions.fetch(name) do
50
- name_to_extensions[name] = []
51
- end
52
- exts << decl
53
- end
54
- when AST::Declarations::Alias
55
- cache_name name_to_alias, name: decl.name.absolute!, decl: decl
56
- when AST::Declarations::Constant
57
- cache_name name_to_constant, name: decl.name.absolute!, decl: decl
58
- when AST::Declarations::Global
59
- cache_name name_to_global, name: decl.name, decl: decl
35
+ def insert(decl:, outer:)
36
+ decls << D.new(decl: decl, outer: outer)
37
+ @primary = nil
60
38
  end
61
- end
62
39
 
63
- def find_class(type_name)
64
- name_to_decl[type_name]
65
- end
40
+ def validate_type_params
41
+ unless decls.empty?
42
+ hd_decl, *tl_decls = decls
43
+ hd_params = hd_decl.decl.type_params
44
+ hd_names = hd_params.params.map(&:name)
45
+
46
+ tl_decls.each do |tl_decl|
47
+ tl_params = tl_decl.decl.type_params
66
48
 
67
- def each_decl
68
- if block_given?
69
- name_to_decl.each do |name, decl|
70
- yield name, decl
49
+ unless hd_params.size == tl_params.size && hd_params == tl_params.rename_to(hd_names)
50
+ raise GenericParameterMismatchError.new(name: name, decl: tl_decl.decl)
51
+ end
52
+ end
71
53
  end
72
- else
73
- enum_for :each_decl
74
54
  end
75
- end
76
55
 
77
- def each_constant
78
- if block_given?
79
- name_to_constant.each do |name, decl|
80
- yield name, decl
81
- end
82
- else
83
- enum_for :each_constant
56
+ def type_params
57
+ primary.decl.type_params
84
58
  end
85
59
  end
86
60
 
87
- def each_global
88
- if block_given?
89
- name_to_global.each do |name, global|
90
- yield name, global
91
- end
92
- else
93
- enum_for :each_global
61
+ class ModuleEntry < MultiEntry
62
+ def self_types
63
+ decls.flat_map do |d|
64
+ d.decl.self_types
65
+ end.uniq
94
66
  end
95
- end
96
67
 
97
- def each_alias(&block)
98
- if block_given?
99
- name_to_alias.each(&block)
100
- else
101
- enum_for :each_alias
68
+ def primary
69
+ @primary ||= begin
70
+ validate_type_params
71
+ decls.first
72
+ end
102
73
  end
103
74
  end
104
75
 
105
- def each_class_name(&block)
106
- each_decl.select {|name,| class?(name) }.each(&block)
76
+ class ClassEntry < MultiEntry
77
+ def primary
78
+ @primary ||= begin
79
+ validate_type_params
80
+ decls.find {|d| d.decl.super_class } || decls.first
81
+ end
82
+ end
107
83
  end
108
84
 
109
- def class?(type_name)
110
- find_class(type_name)&.yield_self do |decl|
111
- decl.is_a?(AST::Declarations::Class) || decl.is_a?(AST::Declarations::Module)
85
+ class SingleEntry
86
+ include ContextUtil
87
+
88
+ attr_reader :name
89
+ attr_reader :outer
90
+ attr_reader :decl
91
+
92
+ def initialize(name:, decl:, outer:)
93
+ @name = name
94
+ @decl = decl
95
+ @outer = outer
112
96
  end
113
97
  end
114
98
 
115
- def find_type_decl(type_name)
116
- name_to_decl[type_name]
99
+ def initialize
100
+ @buffers = []
101
+ @declarations = []
102
+
103
+ @class_decls = {}
104
+ @interface_decls = {}
105
+ @alias_decls = {}
106
+ @constant_decls = {}
107
+ @global_decls = {}
117
108
  end
118
109
 
119
- def find_extensions(type_name)
120
- name_to_extensions[type_name] || []
110
+ def initialize_copy(other)
111
+ @buffers = other.buffers.dup
112
+ @declarations = other.declarations.dup
113
+
114
+ @class_decls = other.class_decls.dup
115
+ @interface_decls = other.interface_decls.dup
116
+ @alias_decls = other.alias_decls.dup
117
+ @constant_decls = other.constant_decls.dup
118
+ @global_decls = other.global_decls.dup
121
119
  end
122
120
 
123
- def find_alias(type_name)
124
- name_to_alias[type_name]
121
+ def self.from_loader(loader)
122
+ self.new.tap do |env|
123
+ loader.load(env: env)
124
+ end
125
125
  end
126
126
 
127
- def each_extension(type_name, &block)
128
- if block_given?
129
- (name_to_extensions[type_name] || []).each(&block)
130
- else
131
- enum_for :each_extension, type_name
127
+ def cache_name(cache, name:, decl:, outer:)
128
+ if cache.key?(name)
129
+ raise DuplicatedDeclarationError.new(name, decl, cache[name])
132
130
  end
131
+
132
+ cache[name] = SingleEntry.new(name: name, decl: decl, outer: outer)
133
133
  end
134
134
 
135
- def absolute_type_name_in(environment, name:, namespace:)
136
- raise "Namespace should be absolute: #{namespace}" unless namespace.absolute?
135
+ def insert_decl(decl, outer:, namespace:)
136
+ case decl
137
+ when AST::Declarations::Class, AST::Declarations::Module
138
+ name = decl.name.with_prefix(namespace)
137
139
 
138
- if name.absolute?
139
- name if environment.key?(name)
140
- else
141
- absolute_name = name.with_prefix(namespace)
140
+ if constant_decls.key?(name)
141
+ raise DuplicatedDeclarationError.new(name, decl, constant_decls[name].decl)
142
+ end
142
143
 
143
- if environment.key?(absolute_name)
144
- absolute_name
145
- else
146
- if namespace.empty?
147
- nil
148
- else
149
- parent = namespace.parent
150
- absolute_type_name_in environment, name: name, namespace: parent
144
+ unless class_decls.key?(name)
145
+ case decl
146
+ when AST::Declarations::Class
147
+ class_decls[name] ||= ClassEntry.new(name: name)
148
+ when AST::Declarations::Module
149
+ class_decls[name] ||= ModuleEntry.new(name: name)
151
150
  end
152
151
  end
152
+
153
+ existing_entry = class_decls[name]
154
+
155
+ case
156
+ when decl.is_a?(AST::Declarations::Module) && existing_entry.is_a?(ModuleEntry)
157
+ # OK
158
+ when decl.is_a?(AST::Declarations::Class) && existing_entry.is_a?(ClassEntry)
159
+ # OK
160
+ else
161
+ raise DuplicatedDeclarationError.new(name, decl, existing_entry.primary.decl)
162
+ end
163
+
164
+ existing_entry.insert(decl: decl, outer: outer)
165
+
166
+ prefix = outer + [decl]
167
+ ns = name.to_namespace
168
+ decl.each_decl do |d|
169
+ insert_decl(d, outer: prefix, namespace: ns)
170
+ end
171
+
172
+ when AST::Declarations::Interface
173
+ cache_name interface_decls, name: decl.name.with_prefix(namespace), decl: decl, outer: outer
174
+
175
+ when AST::Declarations::Alias
176
+ cache_name alias_decls, name: decl.name.with_prefix(namespace), decl: decl, outer: outer
177
+
178
+ when AST::Declarations::Constant
179
+ name = decl.name.with_prefix(namespace)
180
+
181
+ if class_decls.key?(name)
182
+ raise DuplicatedDeclarationError.new(name, decl, class_decls[name].decls[0].decl)
183
+ end
184
+
185
+ cache_name constant_decls, name: name, decl: decl, outer: outer
186
+
187
+ when AST::Declarations::Global
188
+ cache_name global_decls, name: decl.name, decl: decl, outer: outer
189
+
190
+ when AST::Declarations::Extension
191
+ RBS.logger.warn "#{Location.to_string decl.location} Extension construct is deprecated: use class/module syntax instead"
153
192
  end
154
193
  end
155
194
 
156
- def absolute_class_name(name, namespace:)
157
- raise "Class name expected: #{name}" unless name.class?
158
- absolute_type_name_in name_to_decl, name: name, namespace: namespace
195
+ def <<(decl)
196
+ declarations << decl
197
+ insert_decl(decl, outer: [], namespace: Namespace.root)
198
+ self
159
199
  end
160
200
 
161
- def absolute_interface_name(name, namespace:)
162
- raise "Interface name expected: #{name}" unless name.interface?
163
- absolute_type_name_in name_to_decl, name: name, namespace: namespace
164
- end
201
+ def resolve_type_names
202
+ resolver = TypeNameResolver.from_env(self)
203
+ env = Environment.new()
165
204
 
166
- def absolute_alias_name(name, namespace:)
167
- raise "Alias name expected: #{name}" unless name.alias?
168
- absolute_type_name_in name_to_alias, name: name, namespace: namespace
169
- end
205
+ declarations.each do |decl|
206
+ env << resolve_declaration(resolver, decl, outer: [], prefix: Namespace.root)
207
+ end
170
208
 
171
- def absolute_type_name(type_name, namespace:)
172
- absolute_name = case
173
- when type_name.class?
174
- absolute_class_name(type_name, namespace: namespace)
175
- when type_name.alias?
176
- absolute_alias_name(type_name, namespace: namespace)
177
- when type_name.interface?
178
- absolute_interface_name(type_name, namespace: namespace)
179
- end
180
-
181
- absolute_name || yield(type_name)
209
+ env
182
210
  end
183
211
 
184
- def absolute_name_or(name, type)
185
- if name.absolute?
186
- type
187
- else
188
- yield
212
+ def resolve_declaration(resolver, decl, outer:, prefix:)
213
+ if decl.is_a?(AST::Declarations::Global)
214
+ return AST::Declarations::Global.new(
215
+ name: decl.name,
216
+ type: absolute_type(resolver, decl.type, context: [Namespace.root]),
217
+ location: decl.location,
218
+ comment: decl.comment
219
+ )
220
+ end
221
+
222
+ context = (outer + [decl]).each.with_object([Namespace.root]) do |decl, array|
223
+ array.unshift(array.first + decl.name.to_namespace)
224
+ end
225
+
226
+ case decl
227
+ when AST::Declarations::Class
228
+ outer_ = outer + [decl]
229
+ prefix_ = prefix + decl.name.to_namespace
230
+ AST::Declarations::Class.new(
231
+ name: decl.name.with_prefix(prefix),
232
+ type_params: decl.type_params,
233
+ super_class: decl.super_class&.yield_self do |super_class|
234
+ AST::Declarations::Class::Super.new(
235
+ name: absolute_type_name(resolver, super_class.name, context: context),
236
+ args: super_class.args.map {|type| absolute_type(resolver, type, context: context) }
237
+ )
238
+ end,
239
+ members: decl.members.map do |member|
240
+ case member
241
+ when AST::Members::Base
242
+ resolve_member(resolver, member, context: context)
243
+ when AST::Declarations::Base
244
+ resolve_declaration(
245
+ resolver,
246
+ member,
247
+ outer: outer_,
248
+ prefix: prefix_
249
+ )
250
+ end
251
+ end,
252
+ location: decl.location,
253
+ annotations: decl.annotations,
254
+ comment: decl.comment
255
+ )
256
+ when AST::Declarations::Module
257
+ outer_ = outer + [decl]
258
+ prefix_ = prefix + decl.name.to_namespace
259
+ AST::Declarations::Module.new(
260
+ name: decl.name.with_prefix(prefix),
261
+ type_params: decl.type_params,
262
+ self_types: decl.self_types.map do |module_self|
263
+ AST::Declarations::Module::Self.new(
264
+ name: absolute_type_name(resolver, module_self.name, context: context),
265
+ args: module_self.args.map {|type| absolute_type(resolver, type, context: context) },
266
+ location: module_self.location
267
+ )
268
+ end,
269
+ members: decl.members.map do |member|
270
+ case member
271
+ when AST::Members::Base
272
+ resolve_member(resolver, member, context: context)
273
+ when AST::Declarations::Base
274
+ resolve_declaration(
275
+ resolver,
276
+ member,
277
+ outer: outer_,
278
+ prefix: prefix_
279
+ )
280
+ end
281
+ end,
282
+ location: decl.location,
283
+ annotations: decl.annotations,
284
+ comment: decl.comment
285
+ )
286
+ when AST::Declarations::Interface
287
+ AST::Declarations::Interface.new(
288
+ name: decl.name.with_prefix(prefix),
289
+ type_params: decl.type_params,
290
+ members: decl.members.map do |member|
291
+ resolve_member(resolver, member, context: context)
292
+ end,
293
+ comment: decl.comment,
294
+ location: decl.location,
295
+ annotations: decl.annotations
296
+ )
297
+ when AST::Declarations::Alias
298
+ AST::Declarations::Alias.new(
299
+ name: decl.name.with_prefix(prefix),
300
+ type: absolute_type(resolver, decl.type, context: context),
301
+ location: decl.location,
302
+ annotations: decl.annotations,
303
+ comment: decl.comment
304
+ )
305
+
306
+ when AST::Declarations::Constant
307
+ AST::Declarations::Constant.new(
308
+ name: decl.name.with_prefix(prefix),
309
+ type: absolute_type(resolver, decl.type, context: context),
310
+ location: decl.location,
311
+ comment: decl.comment
312
+ )
189
313
  end
190
314
  end
191
315
 
192
- def absolute_type(type, namespace:, &block)
193
- case type
194
- when Types::ClassSingleton
195
- absolute_name_or(type.name, type) do
196
- absolute_name = absolute_type_name(type.name, namespace: namespace) { yield(type) }
197
- Types::ClassSingleton.new(name: absolute_name, location: type.location)
198
- end
199
- when Types::ClassInstance
200
- absolute_name = absolute_type_name(type.name, namespace: namespace) { yield(type) }
201
- Types::ClassInstance.new(name: absolute_name,
202
- args: type.args.map {|ty|
203
- absolute_type(ty, namespace: namespace, &block)
204
- },
205
- location: type.location)
206
- when Types::Interface
207
- absolute_name = absolute_type_name(type.name, namespace: namespace) { yield(type) }
208
- Types::Interface.new(name: absolute_name,
209
- args: type.args.map {|ty|
210
- absolute_type(ty, namespace: namespace, &block)
211
- },
212
- location: type.location)
213
- when Types::Alias
214
- absolute_name_or(type.name, type) do
215
- absolute_name = absolute_type_name(type.name, namespace: namespace) { yield(type) }
216
- Types::Alias.new(name: absolute_name, location: type.location)
217
- end
218
- when Types::Tuple
219
- Types::Tuple.new(
220
- types: type.types.map {|ty| absolute_type(ty, namespace: namespace, &block) },
221
- location: type.location
316
+ def resolve_member(resolver, member, context:)
317
+ case member
318
+ when AST::Members::MethodDefinition
319
+ AST::Members::MethodDefinition.new(
320
+ name: member.name,
321
+ kind: member.kind,
322
+ types: member.types.map do |type|
323
+ type.map_type {|ty| absolute_type(resolver, ty, context: context) }
324
+ end,
325
+ comment: member.comment,
326
+ overload: member.overload?,
327
+ annotations: member.annotations,
328
+ attributes: member.attributes,
329
+ location: member.location
330
+ )
331
+ when AST::Members::AttrAccessor
332
+ AST::Members::AttrAccessor.new(
333
+ name: member.name,
334
+ type: absolute_type(resolver, member.type, context: context),
335
+ annotations: member.annotations,
336
+ comment: member.comment,
337
+ location: member.location,
338
+ ivar_name: member.ivar_name
339
+ )
340
+ when AST::Members::AttrReader
341
+ AST::Members::AttrReader.new(
342
+ name: member.name,
343
+ type: absolute_type(resolver, member.type, context: context),
344
+ annotations: member.annotations,
345
+ comment: member.comment,
346
+ location: member.location,
347
+ ivar_name: member.ivar_name
348
+ )
349
+ when AST::Members::AttrWriter
350
+ AST::Members::AttrWriter.new(
351
+ name: member.name,
352
+ type: absolute_type(resolver, member.type, context: context),
353
+ annotations: member.annotations,
354
+ comment: member.comment,
355
+ location: member.location,
356
+ ivar_name: member.ivar_name
222
357
  )
223
- when Types::Record
224
- Types::Record.new(
225
- fields: type.fields.transform_values {|ty| absolute_type(ty, namespace: namespace, &block) },
226
- location: type.location
358
+ when AST::Members::InstanceVariable
359
+ AST::Members::InstanceVariable.new(
360
+ name: member.name,
361
+ type: absolute_type(resolver, member.type, context: context),
362
+ comment: member.comment,
363
+ location: member.location
227
364
  )
228
- when Types::Union
229
- Types::Union.new(
230
- types: type.types.map {|ty| absolute_type(ty, namespace: namespace, &block) },
231
- location: type.location
365
+ when AST::Members::ClassInstanceVariable
366
+ AST::Members::ClassInstanceVariable.new(
367
+ name: member.name,
368
+ type: absolute_type(resolver, member.type, context: context),
369
+ comment: member.comment,
370
+ location: member.location
232
371
  )
233
- when Types::Intersection
234
- Types::Intersection.new(
235
- types: type.types.map {|ty| absolute_type(ty, namespace: namespace, &block) },
236
- location: type.location
372
+ when AST::Members::ClassVariable
373
+ AST::Members::ClassVariable.new(
374
+ name: member.name,
375
+ type: absolute_type(resolver, member.type, context: context),
376
+ comment: member.comment,
377
+ location: member.location
237
378
  )
238
- when Types::Optional
239
- Types::Optional.new(
240
- type: absolute_type(type.type, namespace: namespace, &block),
241
- location: type.location
379
+ when AST::Members::Include
380
+ AST::Members::Include.new(
381
+ name: absolute_type_name(resolver, member.name, context: context),
382
+ args: member.args.map {|type| absolute_type(resolver, type, context: context) },
383
+ comment: member.comment,
384
+ location: member.location,
385
+ annotations: member.annotations
242
386
  )
243
- when Types::Proc
244
- Types::Proc.new(
245
- type: type.type.map_type {|ty| absolute_type(ty, namespace: namespace, &block) },
246
- location: type.location
387
+ when AST::Members::Extend
388
+ AST::Members::Extend.new(
389
+ name: absolute_type_name(resolver, member.name, context: context),
390
+ args: member.args.map {|type| absolute_type(resolver, type, context: context) },
391
+ comment: member.comment,
392
+ location: member.location,
393
+ annotations: member.annotations
394
+ )
395
+ when AST::Members::Prepend
396
+ AST::Members::Prepend.new(
397
+ name: absolute_type_name(resolver, member.name, context: context),
398
+ args: member.args.map {|type| absolute_type(resolver, type, context: context) },
399
+ comment: member.comment,
400
+ location: member.location,
401
+ annotations: member.annotations
247
402
  )
248
403
  else
249
- type
404
+ member
250
405
  end
251
406
  end
252
407
 
253
- # Validates presence of the relative type, and application arity match.
254
- def validate(type, namespace:)
255
- case type
256
- when Types::ClassInstance, Types::Interface
257
- if type.name.namespace.relative?
258
- type = absolute_type(type, namespace: namespace) do |type|
259
- NoTypeFoundError.check!(type.name.absolute!, env: self, location: type.location)
260
- end
261
- end
262
-
263
- decl = find_class(type.name)
264
- unless decl
265
- raise NoTypeFoundError.new(type_name: type.name, location: type.location)
266
- end
408
+ def absolute_type_name(resolver, type_name, context:)
409
+ resolver.resolve(type_name, context: context) || type_name
410
+ end
267
411
 
268
- InvalidTypeApplicationError.check!(
269
- type_name: type.name,
270
- args: type.args,
271
- params: decl.type_params,
272
- location: type.location
273
- )
412
+ def absolute_type(resolver, type, context:)
413
+ type.map_type_name do |name|
414
+ absolute_type_name(resolver, name, context: context)
274
415
  end
416
+ end
275
417
 
276
- type.each_type do |type_|
277
- validate(type_, namespace: namespace)
278
- end
418
+ def inspect
419
+ ivars = %i[@buffers @declarations @class_decls @interface_decls @alias_decls @constant_decls @global_decls]
420
+ "\#<RBS::Environment #{ivars.map { |iv| "#{iv}=(#{instance_variable_get(iv).size} items)"}.join(' ')}>"
279
421
  end
280
422
  end
281
423
  end