rbs 3.0.0.dev.1 → 3.0.0.dev.2
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 +0 -3
- data/CHANGELOG.md +28 -0
- data/Gemfile.lock +2 -2
- data/README.md +1 -0
- data/Rakefile +75 -1
- data/core/array.rbs +1 -1
- data/core/builtin.rbs +1 -1
- data/core/hash.rbs +1 -1
- data/core/module.rbs +1 -1
- data/ext/rbs_extension/constants.c +16 -2
- data/ext/rbs_extension/constants.h +8 -1
- data/ext/rbs_extension/extconf.rb +1 -1
- data/ext/rbs_extension/lexer.c +834 -777
- data/ext/rbs_extension/lexer.h +3 -1
- data/ext/rbs_extension/lexer.re +3 -1
- data/ext/rbs_extension/lexstate.c +4 -2
- data/ext/rbs_extension/parser.c +264 -44
- data/ext/rbs_extension/ruby_objs.c +56 -2
- data/ext/rbs_extension/ruby_objs.h +7 -1
- data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
- data/lib/rbs/ast/declarations.rb +49 -2
- data/lib/rbs/ast/directives.rb +39 -0
- data/lib/rbs/cli.rb +32 -18
- data/lib/rbs/collection/config/lockfile_generator.rb +25 -20
- data/lib/rbs/collection/config.rb +2 -2
- data/lib/rbs/collection/sources/git.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
- data/lib/rbs/definition_builder.rb +8 -8
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +352 -83
- data/lib/rbs/environment_loader.rb +9 -7
- data/lib/rbs/environment_walker.rb +1 -1
- data/lib/rbs/errors.rb +34 -37
- data/lib/rbs/locator.rb +1 -1
- data/lib/rbs/parser_aux.rb +8 -6
- data/lib/rbs/resolver/constant_resolver.rb +23 -7
- data/lib/rbs/resolver/type_name_resolver.rb +2 -1
- data/lib/rbs/sorter.rb +3 -3
- data/lib/rbs/test/setup.rb +1 -1
- data/lib/rbs/type_alias_dependency.rb +1 -1
- data/lib/rbs/type_alias_regularity.rb +3 -3
- data/lib/rbs/validator.rb +23 -2
- data/lib/rbs/variance_calculator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +28 -2
- data/lib/rbs.rb +2 -2
- data/lib/rdoc_plugin/parser.rb +2 -2
- data/rbs.gemspec +1 -1
- data/sig/ancestor_graph.rbs +22 -2
- data/sig/collection/config/lockfile_generator.rbs +8 -10
- data/sig/collection/config.rbs +1 -1
- data/sig/collection/sources.rbs +12 -6
- data/sig/constant.rbs +1 -1
- data/sig/declarations.rbs +36 -3
- data/sig/definition.rbs +1 -1
- data/sig/definition_builder.rbs +0 -1
- data/sig/directives.rbs +61 -0
- data/sig/environment.rbs +150 -28
- data/sig/environment_loader.rbs +1 -1
- data/sig/errors.rbs +22 -1
- data/sig/parser.rbs +8 -15
- data/sig/resolver/constant_resolver.rbs +1 -2
- data/sig/shims/bundler.rbs +18 -0
- data/sig/shims/rubygems.rbs +6 -0
- data/sig/use_map.rbs +35 -0
- data/sig/validator.rbs +12 -5
- data/sig/writer.rbs +4 -2
- metadata +7 -9
- data/lib/rbs/constant_table.rb +0 -167
- data/lib/rbs/type_name_resolver.rb +0 -67
- data/sig/constant_table.rbs +0 -30
- data/sig/type_name_resolver.rbs +0 -26
- data/steep/Gemfile +0 -3
- data/steep/Gemfile.lock +0 -61
data/lib/rbs/environment.rb
CHANGED
@@ -6,15 +6,21 @@ module RBS
|
|
6
6
|
|
7
7
|
attr_reader :class_decls
|
8
8
|
attr_reader :interface_decls
|
9
|
-
attr_reader :
|
9
|
+
attr_reader :type_alias_decls
|
10
10
|
attr_reader :constant_decls
|
11
11
|
attr_reader :global_decls
|
12
|
+
attr_reader :class_alias_decls
|
13
|
+
attr_reader :buffer_directives
|
12
14
|
|
13
15
|
module ContextUtil
|
14
16
|
def calculate_context(decls)
|
15
|
-
decls.
|
16
|
-
|
17
|
-
|
17
|
+
decls.inject(nil) do |context, decl| #$ Resolver::context
|
18
|
+
if (_, last = context)
|
19
|
+
last or raise
|
20
|
+
[context, last + decl.name]
|
21
|
+
else
|
22
|
+
[nil, decl.name.absolute!]
|
23
|
+
end
|
18
24
|
end
|
19
25
|
end
|
20
26
|
end
|
@@ -90,12 +96,6 @@ module RBS
|
|
90
96
|
end
|
91
97
|
end
|
92
98
|
|
93
|
-
def foo
|
94
|
-
a = [1].sample()
|
95
|
-
return unless a
|
96
|
-
a + 1
|
97
|
-
end
|
98
|
-
|
99
99
|
class ClassEntry < MultiEntry
|
100
100
|
def primary
|
101
101
|
@primary ||= begin
|
@@ -119,19 +119,40 @@ module RBS
|
|
119
119
|
include ContextUtil
|
120
120
|
|
121
121
|
def context
|
122
|
-
@context
|
122
|
+
@context ||= calculate_context(outer)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
126
|
+
class ModuleAliasEntry < SingleEntry
|
127
|
+
end
|
128
|
+
|
129
|
+
class ClassAliasEntry < SingleEntry
|
130
|
+
end
|
131
|
+
|
132
|
+
class InterfaceEntry < SingleEntry
|
133
|
+
end
|
134
|
+
|
135
|
+
class TypeAliasEntry < SingleEntry
|
136
|
+
end
|
137
|
+
|
138
|
+
class ConstantEntry < SingleEntry
|
139
|
+
end
|
140
|
+
|
141
|
+
class GlobalEntry < SingleEntry
|
142
|
+
end
|
143
|
+
|
126
144
|
def initialize
|
127
145
|
@buffers = []
|
128
146
|
@declarations = []
|
129
147
|
|
130
148
|
@class_decls = {}
|
131
149
|
@interface_decls = {}
|
132
|
-
@
|
150
|
+
@type_alias_decls = {}
|
133
151
|
@constant_decls = {}
|
134
152
|
@global_decls = {}
|
153
|
+
@class_alias_decls = {}
|
154
|
+
@normalize_module_name_cache = {}
|
155
|
+
@buffer_directives = {}
|
135
156
|
end
|
136
157
|
|
137
158
|
def initialize_copy(other)
|
@@ -140,9 +161,11 @@ module RBS
|
|
140
161
|
|
141
162
|
@class_decls = other.class_decls.dup
|
142
163
|
@interface_decls = other.interface_decls.dup
|
143
|
-
@
|
164
|
+
@type_alias_decls = other.type_alias_decls.dup
|
144
165
|
@constant_decls = other.constant_decls.dup
|
145
166
|
@global_decls = other.global_decls.dup
|
167
|
+
@class_alias_decls = other.class_alias_decls.dup
|
168
|
+
@buffer_directives = other.buffer_directives.dup
|
146
169
|
end
|
147
170
|
|
148
171
|
def self.from_loader(loader)
|
@@ -151,12 +174,155 @@ module RBS
|
|
151
174
|
end
|
152
175
|
end
|
153
176
|
|
154
|
-
def
|
155
|
-
|
156
|
-
|
177
|
+
def interface_name?(name)
|
178
|
+
interface_decls.key?(name)
|
179
|
+
end
|
180
|
+
|
181
|
+
def type_alias_name?(name)
|
182
|
+
type_alias_decls.key?(name)
|
183
|
+
end
|
184
|
+
|
185
|
+
def module_name?(name)
|
186
|
+
class_decls.key?(name) || class_alias_decls.key?(name)
|
187
|
+
end
|
188
|
+
|
189
|
+
def type_name?(name)
|
190
|
+
interface_name?(name) ||
|
191
|
+
type_alias_name?(name) ||
|
192
|
+
module_name?(name)
|
193
|
+
end
|
194
|
+
|
195
|
+
def constant_name?(name)
|
196
|
+
constant_decl?(name) || module_name?(name)
|
197
|
+
end
|
198
|
+
|
199
|
+
def constant_decl?(name)
|
200
|
+
constant_decls.key?(name)
|
201
|
+
end
|
202
|
+
|
203
|
+
def class_decl?(name)
|
204
|
+
class_decls[name].is_a?(ClassEntry)
|
205
|
+
end
|
206
|
+
|
207
|
+
def module_decl?(name)
|
208
|
+
class_decls[name].is_a?(ModuleEntry)
|
209
|
+
end
|
210
|
+
|
211
|
+
def module_alias?(name)
|
212
|
+
if decl = class_alias_decls[name]
|
213
|
+
decl.decl.is_a?(AST::Declarations::ModuleAlias)
|
214
|
+
else
|
215
|
+
false
|
216
|
+
end
|
217
|
+
end
|
218
|
+
|
219
|
+
def class_alias?(name)
|
220
|
+
if decl = class_alias_decls[name]
|
221
|
+
decl.decl.is_a?(AST::Declarations::ClassAlias)
|
222
|
+
else
|
223
|
+
false
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
def class_entry(type_name)
|
228
|
+
case
|
229
|
+
when (class_entry = class_decls[type_name]).is_a?(ClassEntry)
|
230
|
+
class_entry
|
231
|
+
when (class_alias = class_alias_decls[type_name]).is_a?(ClassAliasEntry)
|
232
|
+
class_alias
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
def module_entry(type_name)
|
237
|
+
case
|
238
|
+
when (module_entry = class_decls[type_name]).is_a?(ModuleEntry)
|
239
|
+
module_entry
|
240
|
+
when (module_alias = class_alias_decls[type_name]).is_a?(ModuleAliasEntry)
|
241
|
+
module_alias
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def normalized_class_entry(type_name)
|
246
|
+
if name = normalize_module_name?(type_name)
|
247
|
+
case entry = class_entry(name)
|
248
|
+
when ClassEntry, nil
|
249
|
+
entry
|
250
|
+
when ClassAliasEntry
|
251
|
+
raise
|
252
|
+
end
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
256
|
+
def normalized_module_entry(type_name)
|
257
|
+
if name = normalize_module_name?(type_name)
|
258
|
+
case entry = module_entry(name)
|
259
|
+
when ModuleEntry, nil
|
260
|
+
entry
|
261
|
+
when ModuleAliasEntry
|
262
|
+
raise
|
263
|
+
end
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
def module_class_entry(type_name)
|
268
|
+
class_entry(type_name) || module_entry(type_name)
|
269
|
+
end
|
270
|
+
|
271
|
+
def normalized_module_class_entry(type_name)
|
272
|
+
normalized_class_entry(type_name) || normalized_module_entry(type_name)
|
273
|
+
end
|
274
|
+
|
275
|
+
def constant_entry(type_name)
|
276
|
+
class_entry(type_name) || module_entry(type_name) || constant_decls[type_name]
|
277
|
+
end
|
278
|
+
|
279
|
+
def normalize_module_name(name)
|
280
|
+
normalize_module_name?(name) or name
|
281
|
+
end
|
282
|
+
|
283
|
+
def normalize_module_name?(name)
|
284
|
+
raise "Class/module name is expected: #{name}" unless name.class?
|
285
|
+
name = name.absolute! if name.relative!
|
286
|
+
|
287
|
+
if @normalize_module_name_cache.key?(name)
|
288
|
+
return @normalize_module_name_cache[name]
|
157
289
|
end
|
158
290
|
|
159
|
-
|
291
|
+
@normalize_module_name_cache[name] = false
|
292
|
+
|
293
|
+
entry = constant_entry(name)
|
294
|
+
case entry
|
295
|
+
when ClassEntry, ModuleEntry
|
296
|
+
@normalize_module_name_cache[name] = entry.name
|
297
|
+
entry.name
|
298
|
+
|
299
|
+
when ClassAliasEntry, ModuleAliasEntry
|
300
|
+
old_name = entry.decl.old_name
|
301
|
+
if old_name.namespace.empty?
|
302
|
+
@normalize_module_name_cache[name] = normalize_module_name?(old_name)
|
303
|
+
else
|
304
|
+
parent = old_name.namespace.to_type_name
|
305
|
+
|
306
|
+
if normalized_parent = normalize_module_name?(parent)
|
307
|
+
@normalize_module_name_cache[name] =
|
308
|
+
if normalized_parent == parent
|
309
|
+
normalize_module_name?(old_name)
|
310
|
+
else
|
311
|
+
normalize_module_name?(
|
312
|
+
TypeName.new(name: old_name.name, namespace: normalized_parent.to_namespace)
|
313
|
+
)
|
314
|
+
end
|
315
|
+
else
|
316
|
+
@normalize_module_name_cache[name] = nil
|
317
|
+
end
|
318
|
+
end
|
319
|
+
|
320
|
+
when ConstantEntry
|
321
|
+
raise "#{name} is a constant name"
|
322
|
+
|
323
|
+
else
|
324
|
+
@normalize_module_name_cache[name] = nil
|
325
|
+
end
|
160
326
|
end
|
161
327
|
|
162
328
|
def insert_decl(decl, outer:, namespace:)
|
@@ -164,8 +330,10 @@ module RBS
|
|
164
330
|
when AST::Declarations::Class, AST::Declarations::Module
|
165
331
|
name = decl.name.with_prefix(namespace)
|
166
332
|
|
167
|
-
if
|
168
|
-
|
333
|
+
if cdecl = constant_entry(name)
|
334
|
+
if cdecl.is_a?(ConstantEntry) || cdecl.is_a?(ModuleAliasEntry) || cdecl.is_a?(ClassAliasEntry)
|
335
|
+
raise DuplicatedDeclarationError.new(name, decl, cdecl.decl)
|
336
|
+
end
|
169
337
|
end
|
170
338
|
|
171
339
|
unless class_decls.key?(name)
|
@@ -181,12 +349,8 @@ module RBS
|
|
181
349
|
|
182
350
|
case
|
183
351
|
when decl.is_a?(AST::Declarations::Module) && existing_entry.is_a?(ModuleEntry)
|
184
|
-
# @type var existing_entry: ModuleEntry
|
185
|
-
# @type var decl: AST::Declarations::Module
|
186
352
|
existing_entry.insert(decl: decl, outer: outer)
|
187
353
|
when decl.is_a?(AST::Declarations::Class) && existing_entry.is_a?(ClassEntry)
|
188
|
-
# @type var existing_entry: ClassEntry
|
189
|
-
# @type var decl: AST::Declarations::Class
|
190
354
|
existing_entry.insert(decl: decl, outer: outer)
|
191
355
|
else
|
192
356
|
raise DuplicatedDeclarationError.new(name, decl, existing_entry.decls[0].decl)
|
@@ -199,22 +363,62 @@ module RBS
|
|
199
363
|
end
|
200
364
|
|
201
365
|
when AST::Declarations::Interface
|
202
|
-
|
366
|
+
name = decl.name.with_prefix(namespace)
|
367
|
+
|
368
|
+
if interface_entry = interface_decls[name]
|
369
|
+
DuplicatedDeclarationError.new(name, decl, interface_entry.decl)
|
370
|
+
end
|
371
|
+
|
372
|
+
interface_decls[name] = InterfaceEntry.new(name: name, decl: decl, outer: outer)
|
203
373
|
|
204
|
-
when AST::Declarations::
|
205
|
-
|
374
|
+
when AST::Declarations::TypeAlias
|
375
|
+
name = decl.name.with_prefix(namespace)
|
376
|
+
|
377
|
+
if entry = type_alias_decls[name]
|
378
|
+
DuplicatedDeclarationError.new(name, decl, entry.decl)
|
379
|
+
end
|
380
|
+
|
381
|
+
type_alias_decls[name] = TypeAliasEntry.new(name: name, decl: decl, outer: outer)
|
206
382
|
|
207
383
|
when AST::Declarations::Constant
|
208
384
|
name = decl.name.with_prefix(namespace)
|
209
385
|
|
210
|
-
if
|
211
|
-
|
386
|
+
if entry = constant_entry(name)
|
387
|
+
case entry
|
388
|
+
when ClassAliasEntry, ModuleAliasEntry, ConstantEntry
|
389
|
+
raise DuplicatedDeclarationError.new(name, decl, entry.decl)
|
390
|
+
when ClassEntry, ModuleEntry
|
391
|
+
raise DuplicatedDeclarationError.new(name, decl, *entry.decls.map(&:decl))
|
392
|
+
end
|
212
393
|
end
|
213
394
|
|
214
|
-
|
395
|
+
constant_decls[name] = ConstantEntry.new(name: name, decl: decl, outer: outer)
|
215
396
|
|
216
397
|
when AST::Declarations::Global
|
217
|
-
|
398
|
+
if entry = global_decls[decl.name]
|
399
|
+
raise DuplicatedDeclarationError.new(name, decl, entry.decl)
|
400
|
+
end
|
401
|
+
|
402
|
+
global_decls[decl.name] = GlobalEntry.new(name: decl.name, decl: decl, outer: outer)
|
403
|
+
|
404
|
+
when AST::Declarations::ClassAlias, AST::Declarations::ModuleAlias
|
405
|
+
name = decl.new_name.with_prefix(namespace)
|
406
|
+
|
407
|
+
if entry = constant_entry(name)
|
408
|
+
case entry
|
409
|
+
when ClassAliasEntry, ModuleAliasEntry, ConstantEntry
|
410
|
+
raise DuplicatedDeclarationError.new(name, decl, entry.decl)
|
411
|
+
when ClassEntry, ModuleEntry
|
412
|
+
raise DuplicatedDeclarationError.new(name, decl, *entry.decls.map(&:decl))
|
413
|
+
end
|
414
|
+
end
|
415
|
+
|
416
|
+
case decl
|
417
|
+
when AST::Declarations::ClassAlias
|
418
|
+
class_alias_decls[name] = ClassAliasEntry.new(name: name, decl: decl, outer: outer)
|
419
|
+
when AST::Declarations::ModuleAlias
|
420
|
+
class_alias_decls[name] = ModuleAliasEntry.new(name: name, decl: decl, outer: outer)
|
421
|
+
end
|
218
422
|
end
|
219
423
|
end
|
220
424
|
|
@@ -224,6 +428,13 @@ module RBS
|
|
224
428
|
self
|
225
429
|
end
|
226
430
|
|
431
|
+
def add_signature(buffer:, directives:, decls:)
|
432
|
+
buffer_directives[buffer] = directives
|
433
|
+
decls.each do |decl|
|
434
|
+
self << decl
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
227
438
|
def validate_type_params
|
228
439
|
class_decls.each_value do |decl|
|
229
440
|
decl.primary
|
@@ -231,59 +442,93 @@ module RBS
|
|
231
442
|
end
|
232
443
|
|
233
444
|
def resolve_type_names(only: nil)
|
234
|
-
resolver = TypeNameResolver.
|
235
|
-
env = Environment.new
|
445
|
+
resolver = Resolver::TypeNameResolver.new(self)
|
446
|
+
env = Environment.new
|
236
447
|
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
448
|
+
table = UseMap::Table.new()
|
449
|
+
table.known_types.merge(class_decls.keys)
|
450
|
+
table.known_types.merge(class_alias_decls.keys)
|
451
|
+
table.known_types.merge(type_alias_decls.keys)
|
452
|
+
table.known_types.merge(interface_decls.keys)
|
453
|
+
table.compute_children
|
454
|
+
|
455
|
+
buffers_decls.each do |buffer, decls|
|
456
|
+
dirs = buffer_directives.fetch(buffer)
|
457
|
+
|
458
|
+
map = UseMap.new(table: table)
|
459
|
+
dirs.each do |dir|
|
460
|
+
dir.clauses.each do |clause|
|
461
|
+
map.build_map(clause)
|
462
|
+
end
|
463
|
+
end
|
464
|
+
|
465
|
+
decls = decls.map do |decl|
|
466
|
+
if only && !only.member?(decl)
|
467
|
+
decl
|
468
|
+
else
|
469
|
+
resolve_declaration(resolver, map, decl, outer: [], prefix: Namespace.root)
|
470
|
+
end
|
242
471
|
end
|
472
|
+
|
473
|
+
env.add_signature(buffer: buffer, directives: dirs, decls: decls)
|
243
474
|
end
|
244
475
|
|
245
476
|
env
|
246
477
|
end
|
247
478
|
|
248
|
-
def
|
479
|
+
def resolver_context(*nesting)
|
480
|
+
nesting.inject(nil) {|context, decl| #$ Resolver::context
|
481
|
+
append_context(context, decl)
|
482
|
+
}
|
483
|
+
end
|
484
|
+
|
485
|
+
def append_context(context, decl)
|
486
|
+
if (_, last = context)
|
487
|
+
last or raise
|
488
|
+
[context, last + decl.name]
|
489
|
+
else
|
490
|
+
[nil, decl.name.absolute!]
|
491
|
+
end
|
492
|
+
end
|
493
|
+
|
494
|
+
def resolve_declaration(resolver, map, decl, outer:, prefix:)
|
249
495
|
if decl.is_a?(AST::Declarations::Global)
|
250
496
|
# @type var decl: AST::Declarations::Global
|
251
497
|
return AST::Declarations::Global.new(
|
252
498
|
name: decl.name,
|
253
|
-
type: absolute_type(resolver, decl.type, context:
|
499
|
+
type: absolute_type(resolver, map, decl.type, context: nil),
|
254
500
|
location: decl.location,
|
255
501
|
comment: decl.comment
|
256
502
|
)
|
257
503
|
end
|
258
504
|
|
259
|
-
context = (outer
|
260
|
-
head = array.first or raise
|
261
|
-
array.unshift(head + decl.name.to_namespace)
|
262
|
-
end
|
263
|
-
|
264
|
-
outer_context = context.drop(1)
|
505
|
+
context = resolver_context(*outer)
|
265
506
|
|
266
507
|
case decl
|
267
508
|
when AST::Declarations::Class
|
509
|
+
outer_context = context
|
510
|
+
inner_context = append_context(outer_context, decl)
|
511
|
+
|
268
512
|
outer_ = outer + [decl]
|
269
513
|
prefix_ = prefix + decl.name.to_namespace
|
270
514
|
AST::Declarations::Class.new(
|
271
515
|
name: decl.name.with_prefix(prefix),
|
272
|
-
type_params: resolve_type_params(resolver, decl.type_params, context:
|
516
|
+
type_params: resolve_type_params(resolver, map, decl.type_params, context: inner_context),
|
273
517
|
super_class: decl.super_class&.yield_self do |super_class|
|
274
518
|
AST::Declarations::Class::Super.new(
|
275
|
-
name: absolute_type_name(resolver, super_class.name, context: outer_context),
|
276
|
-
args: super_class.args.map {|type| absolute_type(resolver, type, context: outer_context) },
|
519
|
+
name: absolute_type_name(resolver, map, super_class.name, context: outer_context),
|
520
|
+
args: super_class.args.map {|type| absolute_type(resolver, map, type, context: outer_context) },
|
277
521
|
location: super_class.location
|
278
522
|
)
|
279
523
|
end,
|
280
524
|
members: decl.members.map do |member|
|
281
525
|
case member
|
282
526
|
when AST::Members::Base
|
283
|
-
resolve_member(resolver, member, context:
|
527
|
+
resolve_member(resolver, map, member, context: inner_context)
|
284
528
|
when AST::Declarations::Base
|
285
529
|
resolve_declaration(
|
286
530
|
resolver,
|
531
|
+
map,
|
287
532
|
member,
|
288
533
|
outer: outer_,
|
289
534
|
prefix: prefix_
|
@@ -296,26 +541,31 @@ module RBS
|
|
296
541
|
annotations: decl.annotations,
|
297
542
|
comment: decl.comment
|
298
543
|
)
|
544
|
+
|
299
545
|
when AST::Declarations::Module
|
546
|
+
outer_context = context
|
547
|
+
inner_context = append_context(outer_context, decl)
|
548
|
+
|
300
549
|
outer_ = outer + [decl]
|
301
550
|
prefix_ = prefix + decl.name.to_namespace
|
302
551
|
AST::Declarations::Module.new(
|
303
552
|
name: decl.name.with_prefix(prefix),
|
304
|
-
type_params: resolve_type_params(resolver, decl.type_params, context:
|
553
|
+
type_params: resolve_type_params(resolver, map, decl.type_params, context: inner_context),
|
305
554
|
self_types: decl.self_types.map do |module_self|
|
306
555
|
AST::Declarations::Module::Self.new(
|
307
|
-
name: absolute_type_name(resolver, module_self.name, context:
|
308
|
-
args: module_self.args.map {|type| absolute_type(resolver, type, context:
|
556
|
+
name: absolute_type_name(resolver, map, module_self.name, context: inner_context),
|
557
|
+
args: module_self.args.map {|type| absolute_type(resolver, map, type, context: inner_context) },
|
309
558
|
location: module_self.location
|
310
559
|
)
|
311
560
|
end,
|
312
561
|
members: decl.members.map do |member|
|
313
562
|
case member
|
314
563
|
when AST::Members::Base
|
315
|
-
resolve_member(resolver, member, context:
|
564
|
+
resolve_member(resolver, map, member, context: inner_context)
|
316
565
|
when AST::Declarations::Base
|
317
566
|
resolve_declaration(
|
318
567
|
resolver,
|
568
|
+
map,
|
319
569
|
member,
|
320
570
|
outer: outer_,
|
321
571
|
prefix: prefix_
|
@@ -328,22 +578,24 @@ module RBS
|
|
328
578
|
annotations: decl.annotations,
|
329
579
|
comment: decl.comment
|
330
580
|
)
|
581
|
+
|
331
582
|
when AST::Declarations::Interface
|
332
583
|
AST::Declarations::Interface.new(
|
333
584
|
name: decl.name.with_prefix(prefix),
|
334
|
-
type_params: resolve_type_params(resolver, decl.type_params, context: context),
|
585
|
+
type_params: resolve_type_params(resolver, map, decl.type_params, context: context),
|
335
586
|
members: decl.members.map do |member|
|
336
|
-
resolve_member(resolver, member, context: context)
|
587
|
+
resolve_member(resolver, map, member, context: context)
|
337
588
|
end,
|
338
589
|
comment: decl.comment,
|
339
590
|
location: decl.location,
|
340
591
|
annotations: decl.annotations
|
341
592
|
)
|
342
|
-
|
343
|
-
|
593
|
+
|
594
|
+
when AST::Declarations::TypeAlias
|
595
|
+
AST::Declarations::TypeAlias.new(
|
344
596
|
name: decl.name.with_prefix(prefix),
|
345
|
-
type_params: resolve_type_params(resolver, decl.type_params, context: context),
|
346
|
-
type: absolute_type(resolver, decl.type, context: context),
|
597
|
+
type_params: resolve_type_params(resolver, map, decl.type_params, context: context),
|
598
|
+
type: absolute_type(resolver, map, decl.type, context: context),
|
347
599
|
location: decl.location,
|
348
600
|
annotations: decl.annotations,
|
349
601
|
comment: decl.comment
|
@@ -352,14 +604,30 @@ module RBS
|
|
352
604
|
when AST::Declarations::Constant
|
353
605
|
AST::Declarations::Constant.new(
|
354
606
|
name: decl.name.with_prefix(prefix),
|
355
|
-
type: absolute_type(resolver, decl.type, context: context),
|
607
|
+
type: absolute_type(resolver, map, decl.type, context: context),
|
608
|
+
location: decl.location,
|
609
|
+
comment: decl.comment
|
610
|
+
)
|
611
|
+
|
612
|
+
when AST::Declarations::ClassAlias
|
613
|
+
AST::Declarations::ClassAlias.new(
|
614
|
+
new_name: decl.new_name.with_prefix(prefix),
|
615
|
+
old_name: absolute_type_name(resolver, map, decl.old_name, context: context),
|
616
|
+
location: decl.location,
|
617
|
+
comment: decl.comment
|
618
|
+
)
|
619
|
+
|
620
|
+
when AST::Declarations::ModuleAlias
|
621
|
+
AST::Declarations::ModuleAlias.new(
|
622
|
+
new_name: decl.new_name.with_prefix(prefix),
|
623
|
+
old_name: absolute_type_name(resolver, map, decl.old_name, context: context),
|
356
624
|
location: decl.location,
|
357
625
|
comment: decl.comment
|
358
626
|
)
|
359
627
|
end
|
360
628
|
end
|
361
629
|
|
362
|
-
def resolve_member(resolver, member, context:)
|
630
|
+
def resolve_member(resolver, map, member, context:)
|
363
631
|
case member
|
364
632
|
when AST::Members::MethodDefinition
|
365
633
|
AST::Members::MethodDefinition.new(
|
@@ -367,7 +635,7 @@ module RBS
|
|
367
635
|
kind: member.kind,
|
368
636
|
overloads: member.overloads.map do |overload|
|
369
637
|
overload.update(
|
370
|
-
method_type: resolve_method_type(resolver, overload.method_type, context: context)
|
638
|
+
method_type: resolve_method_type(resolver, map, overload.method_type, context: context)
|
371
639
|
)
|
372
640
|
end,
|
373
641
|
comment: member.comment,
|
@@ -379,7 +647,7 @@ module RBS
|
|
379
647
|
when AST::Members::AttrAccessor
|
380
648
|
AST::Members::AttrAccessor.new(
|
381
649
|
name: member.name,
|
382
|
-
type: absolute_type(resolver, member.type, context: context),
|
650
|
+
type: absolute_type(resolver, map, member.type, context: context),
|
383
651
|
kind: member.kind,
|
384
652
|
annotations: member.annotations,
|
385
653
|
comment: member.comment,
|
@@ -390,7 +658,7 @@ module RBS
|
|
390
658
|
when AST::Members::AttrReader
|
391
659
|
AST::Members::AttrReader.new(
|
392
660
|
name: member.name,
|
393
|
-
type: absolute_type(resolver, member.type, context: context),
|
661
|
+
type: absolute_type(resolver, map, member.type, context: context),
|
394
662
|
kind: member.kind,
|
395
663
|
annotations: member.annotations,
|
396
664
|
comment: member.comment,
|
@@ -401,7 +669,7 @@ module RBS
|
|
401
669
|
when AST::Members::AttrWriter
|
402
670
|
AST::Members::AttrWriter.new(
|
403
671
|
name: member.name,
|
404
|
-
type: absolute_type(resolver, member.type, context: context),
|
672
|
+
type: absolute_type(resolver, map, member.type, context: context),
|
405
673
|
kind: member.kind,
|
406
674
|
annotations: member.annotations,
|
407
675
|
comment: member.comment,
|
@@ -412,44 +680,44 @@ module RBS
|
|
412
680
|
when AST::Members::InstanceVariable
|
413
681
|
AST::Members::InstanceVariable.new(
|
414
682
|
name: member.name,
|
415
|
-
type: absolute_type(resolver, member.type, context: context),
|
683
|
+
type: absolute_type(resolver, map, member.type, context: context),
|
416
684
|
comment: member.comment,
|
417
685
|
location: member.location
|
418
686
|
)
|
419
687
|
when AST::Members::ClassInstanceVariable
|
420
688
|
AST::Members::ClassInstanceVariable.new(
|
421
689
|
name: member.name,
|
422
|
-
type: absolute_type(resolver, member.type, context: context),
|
690
|
+
type: absolute_type(resolver, map, member.type, context: context),
|
423
691
|
comment: member.comment,
|
424
692
|
location: member.location
|
425
693
|
)
|
426
694
|
when AST::Members::ClassVariable
|
427
695
|
AST::Members::ClassVariable.new(
|
428
696
|
name: member.name,
|
429
|
-
type: absolute_type(resolver, member.type, context: context),
|
697
|
+
type: absolute_type(resolver, map, member.type, context: context),
|
430
698
|
comment: member.comment,
|
431
699
|
location: member.location
|
432
700
|
)
|
433
701
|
when AST::Members::Include
|
434
702
|
AST::Members::Include.new(
|
435
|
-
name: absolute_type_name(resolver, member.name, context: context),
|
436
|
-
args: member.args.map {|type| absolute_type(resolver, type, context: context) },
|
703
|
+
name: absolute_type_name(resolver, map, member.name, context: context),
|
704
|
+
args: member.args.map {|type| absolute_type(resolver, map, type, context: context) },
|
437
705
|
comment: member.comment,
|
438
706
|
location: member.location,
|
439
707
|
annotations: member.annotations
|
440
708
|
)
|
441
709
|
when AST::Members::Extend
|
442
710
|
AST::Members::Extend.new(
|
443
|
-
name: absolute_type_name(resolver, member.name, context: context),
|
444
|
-
args: member.args.map {|type| absolute_type(resolver, type, context: context) },
|
711
|
+
name: absolute_type_name(resolver, map, member.name, context: context),
|
712
|
+
args: member.args.map {|type| absolute_type(resolver, map, type, context: context) },
|
445
713
|
comment: member.comment,
|
446
714
|
location: member.location,
|
447
715
|
annotations: member.annotations
|
448
716
|
)
|
449
717
|
when AST::Members::Prepend
|
450
718
|
AST::Members::Prepend.new(
|
451
|
-
name: absolute_type_name(resolver, member.name, context: context),
|
452
|
-
args: member.args.map {|type| absolute_type(resolver, type, context: context) },
|
719
|
+
name: absolute_type_name(resolver, map, member.name, context: context),
|
720
|
+
args: member.args.map {|type| absolute_type(resolver, map, type, context: context) },
|
453
721
|
comment: member.comment,
|
454
722
|
location: member.location,
|
455
723
|
annotations: member.annotations
|
@@ -459,32 +727,33 @@ module RBS
|
|
459
727
|
end
|
460
728
|
end
|
461
729
|
|
462
|
-
def resolve_method_type(resolver, type, context:)
|
730
|
+
def resolve_method_type(resolver, map, type, context:)
|
463
731
|
type.map_type do |ty|
|
464
|
-
absolute_type(resolver, ty, context: context)
|
732
|
+
absolute_type(resolver, map, ty, context: context)
|
465
733
|
end.map_type_bound do |bound|
|
466
|
-
_ = absolute_type(resolver, bound, context: context)
|
734
|
+
_ = absolute_type(resolver, map, bound, context: context)
|
467
735
|
end
|
468
736
|
end
|
469
737
|
|
470
|
-
def resolve_type_params(resolver, params, context:)
|
738
|
+
def resolve_type_params(resolver, map, params, context:)
|
471
739
|
params.map do |param|
|
472
|
-
param.map_type {|type| _ = absolute_type(resolver, type, context: context) }
|
740
|
+
param.map_type {|type| _ = absolute_type(resolver, map, type, context: context) }
|
473
741
|
end
|
474
742
|
end
|
475
743
|
|
476
|
-
def absolute_type_name(resolver, type_name, context:)
|
744
|
+
def absolute_type_name(resolver, map, type_name, context:)
|
745
|
+
type_name = map.resolve(type_name)
|
477
746
|
resolver.resolve(type_name, context: context) || type_name
|
478
747
|
end
|
479
748
|
|
480
|
-
def absolute_type(resolver, type, context:)
|
749
|
+
def absolute_type(resolver, map, type, context:)
|
481
750
|
type.map_type_name do |name, _, _|
|
482
|
-
absolute_type_name(resolver, name, context: context)
|
751
|
+
absolute_type_name(resolver, map, name, context: context)
|
483
752
|
end
|
484
753
|
end
|
485
754
|
|
486
755
|
def inspect
|
487
|
-
ivars = %i[@declarations @class_decls @interface_decls @
|
756
|
+
ivars = %i[@declarations @class_decls @class_alias_decls @interface_decls @type_alias_decls @constant_decls @global_decls]
|
488
757
|
"\#<RBS::Environment #{ivars.map { |iv| "#{iv}=(#{instance_variable_get(iv).size} items)"}.join(' ')}>"
|
489
758
|
end
|
490
759
|
|