rbs 0.6.0 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ce3b2807a94277727870ef841bdb1e3a96567098948930ab6885e9fba2fc3ccf
4
- data.tar.gz: 5d4a01b26887124240ec757b8a0374c79d56c3daf8b32431a571a3ba401112cc
3
+ metadata.gz: 29535fcd236ba4d658d2c975b5084aa58b125203c4aaa1ec4704881b92ed89c7
4
+ data.tar.gz: 71e165ea5cb1ccbf1b48e9683201f6058dc7c95c7a7619865bf26af2cb6485ad
5
5
  SHA512:
6
- metadata.gz: 7978edfd75f809eb604edb58e0c35ff9a1e85b0e34f7462399f76deb36c5a6a0c61030d1fc3a3bb42d689395a0372995e03e41dd47223063084703dc207294d6
7
- data.tar.gz: e1216599f496cd883e8b301d1040f395984d3fc3029ba65fa6c2f63ab3e431a96bc8369ff06bd3f97390dd78e0a10279e1e556ba2c25ac4ef5af6dfaf9aafa77
6
+ metadata.gz: 236e10d6a7372a1c9b3c07a343a4620048c3f269f750e74f82539fd819f690475deb52090eec0cf38bc338344d240586f44941339bea7759066f68f90c5a3bdb
7
+ data.tar.gz: 8ef6ef34e9b39c310f70138135589611c31c8840fdea06eaa606b5004fc5d6634882ddd169b030dd4140645ad9d18c7a4a796a8bba88cd917ea1a69b461efdd1
@@ -2,6 +2,38 @@
2
2
 
3
3
  ## master
4
4
 
5
+ ## 0.10.0 (2020-08-10)
6
+
7
+ * Signature update for `Zlib`
8
+ * Make "no type checker installed" message a debug print [#363](https://github.com/ruby/rbs/pull/363)
9
+ * Print `...` for overloading method definitions [#362](https://github.com/ruby/rbs/pull/362)
10
+ * Allow missing method implementation in Ruby code [#359](https://github.com/ruby/rbs/pull/359)
11
+ * Runtime testing improvements [#356](https://github.com/ruby/rbs/pull/356)
12
+
13
+ ## 0.9.1 (2020-08-04)
14
+
15
+ * Ensure using Module#name [#354](https://github.com/ruby/rbs/pull/354)
16
+ * Fix runtime test setup [#353](https://github.com/ruby/rbs/pull/353)
17
+
18
+ ## 0.9.0 (2020-08-03)
19
+
20
+ * Fix signature validation [#351](https://github.com/ruby/rbs/pull/351), [#352](https://github.com/ruby/rbs/pull/352)
21
+ * Parsing performance improvement [#350](https://github.com/ruby/rbs/pull/350)
22
+
23
+ ## 0.8.0 (2020-08-01)
24
+
25
+ * Signature updates for `Enumerator` and `PTY`
26
+ * Fix prototype rb/rbi error handling [#349](https://github.com/ruby/rbs/pull/349)
27
+ * Runtime test improvements [#344](https://github.com/ruby/rbs/pull/344), [#343](https://github.com/ruby/rbs/pull/343)
28
+ * Add `...` syntax [#342](https://github.com/ruby/rbs/pull/342)
29
+
30
+ ## 0.7.0 (2020-07-20)
31
+
32
+ * Add `DefinitionBuilder#one_instance_ancestors` and `DefinitionBuilder#one_singleton_ancestors` [#341](https://github.com/ruby/rbs/pull/341)
33
+ * Bug fix in ConstantTable [#340](https://github.com/ruby/rbs/pull/340)
34
+ * Make `rbs validate` faster [#338](https://github.com/ruby/rbs/pull/338)
35
+ * Dedup methods generated by `rbs prototype rb` [#334](https://github.com/ruby/rbs/pull/334)
36
+
5
37
  ## 0.6.0 (2020-07-12)
6
38
 
7
39
  * Signature update for `Logger`.
@@ -22,6 +22,12 @@ module RBS
22
22
  def to_json(*a)
23
23
  { string: string, location: location }.to_json(*a)
24
24
  end
25
+
26
+ def concat(string:, location:)
27
+ @string.concat string
28
+ @location.concat location
29
+ self
30
+ end
25
31
  end
26
32
  end
27
33
  end
@@ -66,6 +66,10 @@ module RBS
66
66
  opts
67
67
  end
68
68
 
69
+ def has_parser?
70
+ defined?(RubyVM::AbstractSyntaxTree)
71
+ end
72
+
69
73
  def run(args)
70
74
  options = LibraryOptions.new
71
75
 
@@ -409,6 +413,7 @@ EOU
409
413
  env.constant_decls.each do |name, const|
410
414
  stdout.puts "Validating constant: `#{name}`..."
411
415
  validator.validate_type const.decl.type, context: const.context
416
+ builder.ensure_namespace!(name.namespace, location: const.decl.location)
412
417
  end
413
418
 
414
419
  env.global_decls.each do |name, global|
@@ -418,7 +423,9 @@ EOU
418
423
 
419
424
  env.alias_decls.each do |name, decl|
420
425
  stdout.puts "Validating alias: `#{name}`..."
421
- validator.validate_type decl.decl.type, context: decl.context
426
+ builder.expand_alias(name).tap do |type|
427
+ validator.validate_type type, context: [Namespace.root]
428
+ end
422
429
  end
423
430
  end
424
431
 
@@ -599,12 +606,18 @@ EOU
599
606
  end
600
607
 
601
608
  def run_prototype_file(format, args)
609
+ availability = unless has_parser?
610
+ "\n** This command does not work on this interpreter (#{RUBY_ENGINE}) **\n"
611
+ end
612
+
602
613
  opts = OptionParser.new
603
614
  opts.banner = <<EOU
604
615
  Usage: rbs prototype #{format} [options...] [files...]
605
-
616
+ #{availability}
606
617
  Generate RBS prototype from source code.
607
- It parses specified Ruby code and and generates RBS prototypes.
618
+ It parses specified Ruby code and and generates RBS prototypes.
619
+
620
+ It only works on MRI because it parses Ruby code with `RubyVM::AbstractSyntaxTree`.
608
621
 
609
622
  Examples:
610
623
 
@@ -613,6 +626,11 @@ Examples:
613
626
  EOU
614
627
  opts.parse!(args)
615
628
 
629
+ unless has_parser?
630
+ stdout.puts "Not supported on this interpreter (#{RUBY_ENGINE})."
631
+ exit 1
632
+ end
633
+
616
634
  if args.empty?
617
635
  stdout.puts opts
618
636
  return nil
@@ -152,7 +152,7 @@ module RBS
152
152
  constant_scopes_module name, scopes: scopes
153
153
 
154
154
  else
155
- raise "Unexpected declaration: #{name} (#{decl.class})"
155
+ raise "Unexpected declaration: #{name} (#{entry.class})"
156
156
  end
157
157
 
158
158
  scopes
@@ -50,11 +50,13 @@ module RBS
50
50
  attr_reader :super_method
51
51
  attr_reader :defs
52
52
  attr_reader :accessibility
53
+ attr_reader :extra_annotations
53
54
 
54
- def initialize(super_method:, defs:, accessibility:)
55
+ def initialize(super_method:, defs:, accessibility:, annotations: [])
55
56
  @super_method = super_method
56
57
  @defs = defs
57
58
  @accessibility = accessibility
59
+ @extra_annotations = annotations
58
60
  end
59
61
 
60
62
  def defined_in
@@ -74,7 +76,7 @@ module RBS
74
76
  end
75
77
 
76
78
  def annotations
77
- @annotations ||= defs.flat_map(&:annotations)
79
+ @annotations ||= @extra_annotations + defs.flat_map(&:annotations)
78
80
  end
79
81
 
80
82
  # @deprecated
@@ -13,6 +13,77 @@ module RBS
13
13
  attr_reader :instance_ancestors_cache
14
14
  attr_reader :singleton_ancestor_cache
15
15
 
16
+ attr_reader :one_instance_ancestors_cache
17
+ attr_reader :one_singleton_ancestors_cache
18
+
19
+ class OneAncestors
20
+ attr_reader :type_name
21
+ attr_reader :params
22
+ attr_reader :super_class
23
+ attr_reader :self_types
24
+ attr_reader :included_modules
25
+ attr_reader :prepended_modules
26
+ attr_reader :extended_modules
27
+
28
+ def initialize(type_name:, params:, super_class:, self_types:, included_modules:, prepended_modules:, extended_modules:)
29
+ @type_name = type_name
30
+ @params = params
31
+ @super_class = super_class
32
+ @self_types = self_types
33
+ @included_modules = included_modules
34
+ @prepended_modules = prepended_modules
35
+ @extended_modules = extended_modules
36
+ end
37
+
38
+ def each_ancestor(&block)
39
+ if block_given?
40
+ yield super_class if super_class
41
+ self_types&.each(&block)
42
+ included_modules&.each(&block)
43
+ prepended_modules&.each(&block)
44
+ extended_modules&.each(&block)
45
+ else
46
+ enum_for :each_ancestor
47
+ end
48
+ end
49
+
50
+ def self.class_instance(type_name:, params:, super_class:)
51
+ new(
52
+ type_name: type_name,
53
+ params: params,
54
+ super_class: super_class,
55
+ self_types: nil,
56
+ included_modules: [],
57
+ prepended_modules: [],
58
+ extended_modules: nil
59
+ )
60
+ end
61
+
62
+ def self.singleton(type_name:, super_class:)
63
+ new(
64
+ type_name: type_name,
65
+ params: nil,
66
+ super_class: super_class,
67
+ self_types: nil,
68
+ included_modules: nil,
69
+ prepended_modules: nil,
70
+ extended_modules: []
71
+ )
72
+ end
73
+
74
+ def self.module_instance(type_name:, params:)
75
+ new(
76
+ type_name: type_name,
77
+ params: params,
78
+ self_types: [],
79
+ included_modules: [],
80
+ prepended_modules: [],
81
+ super_class: nil,
82
+ extended_modules: nil
83
+ )
84
+ end
85
+ end
86
+
16
87
  def initialize(env:)
17
88
  @env = env
18
89
  @type_name_resolver = TypeNameResolver.from_env(env)
@@ -26,6 +97,9 @@ module RBS
26
97
 
27
98
  @instance_ancestors_cache = {}
28
99
  @singleton_ancestor_cache = {}
100
+
101
+ @one_instance_ancestors_cache = {}
102
+ @one_singleton_ancestors_cache = {}
29
103
  end
30
104
 
31
105
  def validate_super_class!(type_name, entry)
@@ -45,30 +119,19 @@ module RBS
45
119
  raise SuperclassMismatchError.new(name: type_name, super_classes: super_types, entry: entry)
46
120
  end
47
121
 
48
- def instance_ancestors(type_name, building_ancestors: [])
49
- as = instance_ancestors_cache[type_name] and return as
122
+ def one_instance_ancestors(type_name)
123
+ as = one_instance_ancestors_cache[type_name] and return as
50
124
 
51
- entry = env.class_decls[type_name] or raise "Unknown name for instance_ancestors: #{type_name}"
125
+ entry = env.class_decls[type_name] or raise "Unknown name for one_instance_ancestors: #{type_name}"
52
126
  params = entry.type_params.each.map(&:name)
53
- args = Types::Variable.build(params)
54
- self_ancestor = Definition::Ancestor::Instance.new(name: type_name, args: args)
55
-
56
- RecursiveAncestorError.check!(self_ancestor,
57
- ancestors: building_ancestors,
58
- location: entry.primary.decl.location)
59
- building_ancestors.push self_ancestor
60
-
61
- ancestors = []
62
127
 
63
128
  case entry
64
129
  when Environment::ClassEntry
65
130
  validate_super_class!(type_name, entry)
131
+ primary = entry.primary
132
+ super_class = primary.decl.super_class
66
133
 
67
- # Super class comes last
68
- if self_ancestor.name != BuiltinNames::BasicObject.name
69
- primary = entry.primary
70
- super_class = primary.decl.super_class
71
-
134
+ if type_name != BuiltinNames::BasicObject.name
72
135
  if super_class
73
136
  super_name = super_class.name
74
137
  super_args = super_class.args
@@ -79,46 +142,49 @@ module RBS
79
142
 
80
143
  NoSuperclassFoundError.check!(super_name, env: env, location: primary.decl.location)
81
144
 
82
- super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors)
83
- ancestors.unshift(*super_ancestors.apply(super_args, location: primary.decl.location))
145
+ ancestors = OneAncestors.class_instance(
146
+ type_name: type_name,
147
+ params: params,
148
+ super_class: Definition::Ancestor::Instance.new(name: super_name, args: super_args)
149
+ )
150
+ else
151
+ ancestors = OneAncestors.class_instance(
152
+ type_name: type_name,
153
+ params: params,
154
+ super_class: nil
155
+ )
84
156
  end
85
-
86
- build_ancestors_mixin_self(self_ancestor, entry, ancestors: ancestors, building_ancestors: building_ancestors)
87
-
88
157
  when Environment::ModuleEntry
89
- build_ancestors_mixin_self(self_ancestor, entry, ancestors: ancestors, building_ancestors: building_ancestors)
158
+ ancestors = OneAncestors.module_instance(type_name: type_name, params: params)
90
159
 
160
+ entry.self_types.each do |module_self|
161
+ NoSelfTypeFoundError.check!(module_self, env: env)
162
+ ancestors.self_types.push Definition::Ancestor::Instance.new(name: module_self.name, args: module_self.args)
163
+ end
164
+ else
165
+ raise "Unexpected entry for: #{type_name}"
91
166
  end
92
167
 
93
- building_ancestors.pop
168
+ mixin_ancestors(entry,
169
+ included_modules: ancestors.included_modules,
170
+ prepended_modules: ancestors.prepended_modules,
171
+ extended_modules: nil)
94
172
 
95
- instance_ancestors_cache[type_name] = Definition::InstanceAncestors.new(
96
- type_name: type_name,
97
- params: params,
98
- ancestors: ancestors
99
- )
173
+ one_instance_ancestors_cache[type_name] = ancestors
100
174
  end
101
175
 
102
- def singleton_ancestors(type_name, building_ancestors: [])
103
- as = singleton_ancestor_cache[type_name] and return as
176
+ def one_singleton_ancestors(type_name)
177
+ as = one_singleton_ancestors_cache[type_name] and return as
104
178
 
105
- entry = env.class_decls[type_name] or raise "Unknown name for singleton_ancestors: #{type_name}"
106
- self_ancestor = Definition::Ancestor::Singleton.new(name: type_name)
107
-
108
- RecursiveAncestorError.check!(self_ancestor,
109
- ancestors: building_ancestors,
110
- location: entry.primary.decl.location)
111
- building_ancestors.push self_ancestor
112
-
113
- ancestors = []
179
+ entry = env.class_decls[type_name] or raise "Unknown name for one_singleton_ancestors: #{type_name}"
114
180
 
115
181
  case entry
116
182
  when Environment::ClassEntry
117
- # Super class comes last
118
- if self_ancestor.name != BuiltinNames::BasicObject.name
119
- primary = entry.primary
120
- super_class = primary.decl.super_class
183
+ validate_super_class!(type_name, entry)
184
+ primary = entry.primary
185
+ super_class = primary.decl.super_class
121
186
 
187
+ if type_name != BuiltinNames::BasicObject.name
122
188
  if super_class
123
189
  super_name = super_class.name
124
190
  else
@@ -127,47 +193,35 @@ module RBS
127
193
 
128
194
  NoSuperclassFoundError.check!(super_name, env: env, location: primary.decl.location)
129
195
 
130
- super_ancestors = singleton_ancestors(super_name, building_ancestors: building_ancestors)
131
- ancestors.unshift(*super_ancestors.ancestors)
196
+ ancestors = OneAncestors.singleton(
197
+ type_name: type_name,
198
+ super_class: Definition::Ancestor::Singleton.new(name: super_name)
199
+ )
132
200
  else
133
- as = instance_ancestors(BuiltinNames::Class.name, building_ancestors: building_ancestors)
134
- ancestors.unshift(*as.apply([], location: entry.primary.decl.location))
201
+ ancestors = OneAncestors.singleton(
202
+ type_name: type_name,
203
+ super_class: Definition::Ancestor::Instance.new(name: BuiltinNames::Class.name, args: [])
204
+ )
135
205
  end
136
-
137
206
  when Environment::ModuleEntry
138
- as = instance_ancestors(BuiltinNames::Module.name, building_ancestors: building_ancestors)
139
- ancestors.unshift(*as.apply([], location: entry.primary.decl.location))
140
- end
141
-
142
- # Extend comes next
143
- entry.decls.each do |d|
144
- decl = d.decl
145
-
146
- decl.each_mixin do |member|
147
- case member
148
- when AST::Members::Extend
149
- if member.name.class?
150
- NoMixinFoundError.check!(member.name, env: env, member: member)
207
+ ancestors = OneAncestors.singleton(
208
+ type_name: type_name,
209
+ super_class: Definition::Ancestor::Instance.new(name: BuiltinNames::Module.name, args: [])
210
+ )
151
211
 
152
- module_ancestors = instance_ancestors(member.name, building_ancestors: building_ancestors)
153
- ancestors.unshift(*module_ancestors.apply(member.args, location: member.location))
154
- end
155
- end
156
- end
212
+ else
213
+ raise "Unexpected entry for: #{type_name}"
157
214
  end
158
215
 
159
- ancestors.unshift self_ancestor
160
-
161
- building_ancestors.pop
216
+ mixin_ancestors(entry,
217
+ included_modules: nil,
218
+ prepended_modules: nil,
219
+ extended_modules: ancestors.extended_modules)
162
220
 
163
- singleton_ancestor_cache[type_name] = Definition::SingletonAncestors.new(
164
- type_name: type_name,
165
- ancestors: ancestors
166
- )
221
+ one_singleton_ancestors_cache[type_name] = ancestors
167
222
  end
168
223
 
169
- def build_ancestors_mixin_self(self_ancestor, entry, ancestors:, building_ancestors:)
170
- # Include comes next
224
+ def mixin_ancestors(entry, included_modules:, extended_modules:, prepended_modules:)
171
225
  entry.decls.each do |d|
172
226
  decl = d.decl
173
227
 
@@ -179,42 +233,143 @@ module RBS
179
233
  decl.each_mixin do |member|
180
234
  case member
181
235
  when AST::Members::Include
182
- if member.name.class?
236
+ if included_modules
237
+ NoMixinFoundError.check!(member.name, env: env, member: member)
238
+
239
+ module_name = member.name
240
+ module_args = member.args.map {|type| type.sub(align_params) }
241
+
242
+ included_modules << Definition::Ancestor::Instance.new(name: module_name, args: module_args)
243
+ end
244
+
245
+ when AST::Members::Prepend
246
+ if prepended_modules
183
247
  NoMixinFoundError.check!(member.name, env: env, member: member)
184
248
 
185
249
  module_name = member.name
186
250
  module_args = member.args.map {|type| type.sub(align_params) }
187
251
 
188
- module_ancestors = instance_ancestors(module_name, building_ancestors: building_ancestors)
189
- ancestors.unshift(*module_ancestors.apply(module_args, location: member.location))
252
+ prepended_modules << Definition::Ancestor::Instance.new(name: module_name, args: module_args)
253
+ end
254
+
255
+ when AST::Members::Extend
256
+ if extended_modules
257
+ NoMixinFoundError.check!(member.name, env: env, member: member)
258
+
259
+ module_name = member.name
260
+ module_args = member.args
261
+
262
+ extended_modules << Definition::Ancestor::Instance.new(name: module_name, args: module_args)
190
263
  end
191
264
  end
192
265
  end
193
266
  end
267
+ end
268
+
269
+ def instance_ancestors(type_name, building_ancestors: [])
270
+ as = instance_ancestors_cache[type_name] and return as
271
+
272
+ entry = env.class_decls[type_name] or raise "Unknown name for instance_ancestors: #{type_name}"
273
+ params = entry.type_params.each.map(&:name)
274
+ args = Types::Variable.build(params)
275
+ self_ancestor = Definition::Ancestor::Instance.new(name: type_name, args: args)
276
+
277
+ RecursiveAncestorError.check!(self_ancestor,
278
+ ancestors: building_ancestors,
279
+ location: entry.primary.decl.location)
280
+ building_ancestors.push self_ancestor
281
+
282
+ one_ancestors = one_instance_ancestors(type_name)
283
+
284
+ ancestors = []
285
+
286
+ case entry
287
+ when Environment::ClassEntry
288
+ if one_ancestors.super_class
289
+ super_name = one_ancestors.super_class.name
290
+ super_args = one_ancestors.super_class.args
291
+
292
+ super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors)
293
+ ancestors.unshift(*super_ancestors.apply(super_args, location: entry.primary.decl.location))
294
+ end
295
+ end
296
+
297
+ one_ancestors.included_modules.each do |mod|
298
+ if mod.name.class?
299
+ name = mod.name
300
+ args = mod.args
301
+ mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
302
+ ancestors.unshift(*mod_ancestors.apply(args, location: entry.primary.decl.location))
303
+ end
304
+ end
194
305
 
195
- # Self
196
306
  ancestors.unshift(self_ancestor)
197
307
 
198
- # Prepends
199
- entry.decls.each do |d|
200
- decl = d.decl
308
+ one_ancestors.prepended_modules.each do |mod|
309
+ if mod.name.class?
310
+ name = mod.name
311
+ args = mod.args
312
+ mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
313
+ ancestors.unshift(*mod_ancestors.apply(args, location: entry.primary.decl.location))
314
+ end
315
+ end
201
316
 
202
- align_params = Substitution.build(decl.type_params.each.map(&:name),
203
- Types::Variable.build(entry.type_params.each.map(&:name)))
317
+ building_ancestors.pop
204
318
 
205
- decl.each_mixin do |member|
206
- case member
207
- when AST::Members::Prepend
208
- NoMixinFoundError.check!(member.name, env: env, member: member)
319
+ instance_ancestors_cache[type_name] = Definition::InstanceAncestors.new(
320
+ type_name: type_name,
321
+ params: params,
322
+ ancestors: ancestors
323
+ )
324
+ end
209
325
 
210
- module_name = member.name
211
- module_args = member.args.map {|type| type.sub(align_params) }
326
+ def singleton_ancestors(type_name, building_ancestors: [])
327
+ as = singleton_ancestor_cache[type_name] and return as
212
328
 
213
- module_ancestors = instance_ancestors(module_name, building_ancestors: building_ancestors)
214
- ancestors.unshift(*module_ancestors.apply(module_args))
215
- end
329
+ entry = env.class_decls[type_name] or raise "Unknown name for singleton_ancestors: #{type_name}"
330
+ self_ancestor = Definition::Ancestor::Singleton.new(name: type_name)
331
+
332
+ RecursiveAncestorError.check!(self_ancestor,
333
+ ancestors: building_ancestors,
334
+ location: entry.primary.decl.location)
335
+ building_ancestors.push self_ancestor
336
+
337
+ one_ancestors = one_singleton_ancestors(type_name)
338
+
339
+ ancestors = []
340
+
341
+ case one_ancestors.super_class
342
+ when Definition::Ancestor::Instance
343
+ super_name = one_ancestors.super_class.name
344
+ super_args = one_ancestors.super_class.args
345
+
346
+ super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors)
347
+ ancestors.unshift(*super_ancestors.apply(super_args, location: entry.primary.decl.location))
348
+
349
+ when Definition::Ancestor::Singleton
350
+ super_name = one_ancestors.super_class.name
351
+
352
+ super_ancestors = singleton_ancestors(super_name, building_ancestors: [])
353
+ ancestors.unshift(*super_ancestors.ancestors)
354
+ end
355
+
356
+ one_ancestors.extended_modules.each do |mod|
357
+ if mod.name.class?
358
+ name = mod.name
359
+ args = mod.args
360
+ mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
361
+ ancestors.unshift(*mod_ancestors.apply(args, location: entry.primary.decl.location))
216
362
  end
217
363
  end
364
+
365
+ ancestors.unshift(self_ancestor)
366
+
367
+ building_ancestors.pop
368
+
369
+ singleton_ancestor_cache[type_name] = Definition::SingletonAncestors.new(
370
+ type_name: type_name,
371
+ ancestors: ancestors
372
+ )
218
373
  end
219
374
 
220
375
  def each_member_with_accessibility(members, accessibility: :public)
@@ -230,9 +385,18 @@ module RBS
230
385
  end
231
386
  end
232
387
 
388
+ def ensure_namespace!(namespace, location:)
389
+ namespace.ascend do |ns|
390
+ unless ns.empty?
391
+ NoTypeFoundError.check!(ns.to_type_name, env: env, location: location)
392
+ end
393
+ end
394
+ end
395
+
233
396
  def build_instance(type_name)
234
397
  try_cache type_name, cache: instance_cache do
235
398
  entry = env.class_decls[type_name] or raise "Unknown name for build_instance: #{type_name}"
399
+ ensure_namespace!(type_name.namespace, location: entry.decls[0].decl.location)
236
400
 
237
401
  case entry
238
402
  when Environment::ClassEntry, Environment::ModuleEntry
@@ -279,6 +443,7 @@ module RBS
279
443
  def build_singleton(type_name)
280
444
  try_cache type_name, cache: singleton_cache do
281
445
  entry = env.class_decls[type_name] or raise "Unknown name for build_singleton: #{type_name}"
446
+ ensure_namespace!(type_name.namespace, location: entry.decls[0].decl.location)
282
447
 
283
448
  case entry
284
449
  when Environment::ClassEntry, Environment::ModuleEntry
@@ -769,7 +934,8 @@ module RBS
769
934
  implemented_in: nil
770
935
  )
771
936
  end,
772
- accessibility: :public
937
+ accessibility: :public,
938
+ annotations: [AST::Annotation.new(location: nil, string: "rbs:test:target")]
773
939
  )
774
940
  end
775
941
  end
@@ -838,7 +1004,7 @@ module RBS
838
1004
  methods[name] = Definition::Method.new(
839
1005
  super_method: super_method,
840
1006
  accessibility: method.accessibility,
841
- defs: method.defs.map {|defn| defn.update(type: defn.type.sub(sub)) }
1007
+ defs: sub.mapping.empty? ? method.defs : method.defs.map {|defn| defn.update(type: defn.type.sub(sub)) }
842
1008
  )
843
1009
  end
844
1010
 
@@ -865,6 +1031,7 @@ module RBS
865
1031
  try_cache(type_name, cache: interface_cache) do
866
1032
  entry = env.interface_decls[type_name] or raise "Unknown name for build_interface: #{type_name}"
867
1033
  declaration = entry.decl
1034
+ ensure_namespace!(type_name.namespace, location: declaration.location)
868
1035
 
869
1036
  self_type = Types::Interface.new(
870
1037
  name: type_name,
@@ -956,6 +1123,7 @@ module RBS
956
1123
 
957
1124
  def expand_alias(type_name)
958
1125
  entry = env.alias_decls[type_name] or raise "Unknown name for expand_alias: #{type_name}"
1126
+ ensure_namespace!(type_name.namespace, location: entry.decl.location)
959
1127
  entry.decl.type
960
1128
  end
961
1129
  end