rbs 2.8.4 → 3.0.0.dev.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +0 -3
  3. data/Gemfile +1 -1
  4. data/Gemfile.lock +17 -17
  5. data/README.md +1 -0
  6. data/Rakefile +66 -0
  7. data/core/array.rbs +1 -1
  8. data/core/builtin.rbs +1 -1
  9. data/core/hash.rbs +1 -1
  10. data/core/module.rbs +1 -1
  11. data/ext/rbs_extension/constants.c +18 -2
  12. data/ext/rbs_extension/constants.h +9 -1
  13. data/ext/rbs_extension/lexer.c +834 -777
  14. data/ext/rbs_extension/lexer.h +3 -1
  15. data/ext/rbs_extension/lexer.re +3 -1
  16. data/ext/rbs_extension/lexstate.c +4 -2
  17. data/ext/rbs_extension/parser.c +287 -57
  18. data/ext/rbs_extension/ruby_objs.c +71 -5
  19. data/ext/rbs_extension/ruby_objs.h +9 -2
  20. data/lib/rbs/annotate/rdoc_annotator.rb +1 -1
  21. data/lib/rbs/ast/declarations.rb +49 -2
  22. data/lib/rbs/ast/directives.rb +39 -0
  23. data/lib/rbs/ast/members.rb +49 -15
  24. data/lib/rbs/cli.rb +38 -19
  25. data/lib/rbs/collection/config/lockfile.rb +115 -0
  26. data/lib/rbs/collection/config/lockfile_generator.rb +99 -53
  27. data/lib/rbs/collection/config.rb +12 -40
  28. data/lib/rbs/collection/installer.rb +9 -13
  29. data/lib/rbs/collection/sources/base.rb +2 -2
  30. data/lib/rbs/collection/sources/git.rb +135 -62
  31. data/lib/rbs/collection/sources/rubygems.rb +10 -12
  32. data/lib/rbs/collection/sources/stdlib.rb +10 -13
  33. data/lib/rbs/collection/sources.rb +7 -1
  34. data/lib/rbs/collection.rb +1 -0
  35. data/lib/rbs/definition.rb +1 -1
  36. data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
  37. data/lib/rbs/definition_builder/method_builder.rb +3 -3
  38. data/lib/rbs/definition_builder.rb +456 -579
  39. data/lib/rbs/environment/use_map.rb +77 -0
  40. data/lib/rbs/environment.rb +356 -85
  41. data/lib/rbs/environment_loader.rb +20 -17
  42. data/lib/rbs/environment_walker.rb +1 -1
  43. data/lib/rbs/errors.rb +34 -37
  44. data/lib/rbs/locator.rb +3 -3
  45. data/lib/rbs/parser_aux.rb +8 -6
  46. data/lib/rbs/prototype/helpers.rb +29 -13
  47. data/lib/rbs/prototype/node_usage.rb +99 -0
  48. data/lib/rbs/prototype/rb.rb +3 -2
  49. data/lib/rbs/prototype/rbi.rb +6 -4
  50. data/lib/rbs/prototype/runtime.rb +25 -12
  51. data/lib/rbs/resolver/constant_resolver.rb +23 -7
  52. data/lib/rbs/resolver/type_name_resolver.rb +2 -1
  53. data/lib/rbs/sorter.rb +3 -3
  54. data/lib/rbs/substitution.rb +19 -0
  55. data/lib/rbs/test/setup.rb +1 -1
  56. data/lib/rbs/type_alias_dependency.rb +1 -1
  57. data/lib/rbs/type_alias_regularity.rb +3 -3
  58. data/lib/rbs/types.rb +1 -5
  59. data/lib/rbs/validator.rb +25 -3
  60. data/lib/rbs/variance_calculator.rb +2 -2
  61. data/lib/rbs/version.rb +1 -1
  62. data/lib/rbs/writer.rb +54 -19
  63. data/lib/rbs.rb +3 -2
  64. data/lib/rdoc_plugin/parser.rb +3 -3
  65. data/schema/members.json +15 -10
  66. data/sig/ancestor_graph.rbs +22 -2
  67. data/sig/collection/config/lockfile.rbs +80 -0
  68. data/sig/collection/config/lockfile_generator.rbs +53 -0
  69. data/sig/collection/config.rbs +5 -48
  70. data/sig/collection/installer.rbs +1 -1
  71. data/sig/collection/sources.rbs +76 -33
  72. data/sig/constant.rbs +1 -1
  73. data/sig/declarations.rbs +36 -3
  74. data/sig/definition.rbs +1 -1
  75. data/sig/definition_builder.rbs +94 -82
  76. data/sig/directives.rbs +61 -0
  77. data/sig/environment.rbs +150 -28
  78. data/sig/environment_loader.rbs +2 -2
  79. data/sig/errors.rbs +42 -0
  80. data/sig/members.rbs +31 -7
  81. data/sig/parser.rbs +8 -15
  82. data/sig/prototype/node_usage.rbs +20 -0
  83. data/sig/resolver/constant_resolver.rbs +1 -2
  84. data/sig/shims/bundler.rbs +31 -0
  85. data/sig/shims/rubygems.rbs +15 -0
  86. data/sig/shims.rbs +0 -22
  87. data/sig/substitution.rbs +6 -0
  88. data/sig/use_map.rbs +35 -0
  89. data/sig/validator.rbs +12 -5
  90. data/sig/writer.rbs +6 -2
  91. metadata +16 -9
  92. data/lib/rbs/constant_table.rb +0 -167
  93. data/lib/rbs/type_name_resolver.rb +0 -67
  94. data/sig/constant_table.rbs +0 -30
  95. data/sig/type_name_resolver.rbs +0 -26
@@ -3,7 +3,6 @@
3
3
  module RBS
4
4
  class DefinitionBuilder
5
5
  attr_reader :env
6
- attr_reader :type_name_resolver
7
6
  attr_reader :ancestor_builder
8
7
  attr_reader :method_builder
9
8
 
@@ -14,7 +13,6 @@ module RBS
14
13
 
15
14
  def initialize(env:, ancestor_builder: nil, method_builder: nil)
16
15
  @env = env
17
- @type_name_resolver = TypeNameResolver.from_env(env)
18
16
  @ancestor_builder = ancestor_builder || AncestorBuilder.new(env: env)
19
17
  @method_builder = method_builder || MethodBuilder.new(env: env)
20
18
 
@@ -32,243 +30,179 @@ module RBS
32
30
  end
33
31
  end
34
32
 
33
+ def define_interface(definition, type_name, subst)
34
+ included_interfaces = ancestor_builder.one_interface_ancestors(type_name).included_interfaces or raise
35
+ interface_methods = interface_methods(included_interfaces)
36
+
37
+ methods = method_builder.build_interface(type_name)
38
+
39
+ import_methods(definition, type_name, methods, interface_methods, subst)
40
+ end
41
+
35
42
  def build_interface(type_name)
36
43
  try_cache(type_name, cache: interface_cache) do
37
44
  entry = env.interface_decls[type_name] or raise "Unknown name for build_interface: #{type_name}"
38
45
  declaration = entry.decl
39
46
  ensure_namespace!(type_name.namespace, location: declaration.location)
40
47
 
41
- self_type = Types::Interface.new(
42
- name: type_name,
43
- args: Types::Variable.build(declaration.type_params.each.map(&:name)),
44
- location: nil
45
- )
48
+ type_params = declaration.type_params.each.map(&:name)
49
+ type_args = Types::Variable.build(type_params)
50
+ self_type = Types::Interface.new(name: type_name, args: type_args, location: nil)
51
+
52
+ subst = Substitution.build(type_params, type_args)
46
53
 
47
54
  ancestors = ancestor_builder.interface_ancestors(type_name)
48
55
  Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
49
- included_interfaces = ancestor_builder.one_interface_ancestors(type_name).included_interfaces or raise
50
- included_interfaces.each do |mod|
51
- defn = build_interface(mod.name)
52
- subst = Substitution.build(defn.type_params, mod.args)
53
-
54
- defn.methods.each do |name, method|
55
- definition.methods[name] = method.sub(subst)
56
- end
57
- end
58
-
59
56
  methods = method_builder.build_interface(type_name)
60
57
  one_ancestors = ancestor_builder.one_interface_ancestors(type_name)
61
58
 
62
59
  validate_type_params(definition, methods: methods, ancestors: one_ancestors)
63
60
 
64
- methods.each do |defn|
65
- method = case original = defn.original
66
- when AST::Members::MethodDefinition
67
- defs = original.types.map do |method_type|
68
- Definition::Method::TypeDef.new(
69
- type: method_type,
70
- member: original,
71
- defined_in: type_name,
72
- implemented_in: nil
73
- )
74
- end
61
+ define_interface(definition, type_name, subst)
62
+ end
63
+ end
64
+ end
75
65
 
76
- Definition::Method.new(
77
- super_method: nil,
78
- defs: defs,
79
- accessibility: :public,
80
- alias_of: nil
81
- )
82
- when AST::Members::Alias
83
- unless definition.methods.key?(original.old_name)
84
- raise UnknownMethodAliasError.new(
85
- type_name: type_name,
86
- original_name: original.old_name,
87
- aliased_name: original.new_name,
88
- location: original.location
89
- )
90
- end
66
+ def tapp_subst(name, args)
67
+ params =
68
+ case
69
+ when name.interface?
70
+ entry = env.interface_decls[name] or raise "Unknown interface name: #{name}"
71
+ entry.decl.type_params
72
+ when name.alias?
73
+ entry = env.type_alias_decls[name] or raise "Unknown alias name: #{name}"
74
+ entry.decl.type_params
75
+ when name.class?
76
+ entry = env.class_decls[name] or raise "Unknown module name: #{name}"
77
+ entry.type_params
78
+ else
79
+ raise
80
+ end
91
81
 
92
- original_method = definition.methods[original.old_name]
93
- Definition::Method.new(
94
- super_method: nil,
95
- defs: original_method.defs.map do |defn|
96
- defn.update(implemented_in: nil, defined_in: type_name)
97
- end,
98
- accessibility: :public,
99
- alias_of: original_method
100
- )
101
- when nil
102
- unless definition.methods.key?(defn.name)
103
- raise InvalidOverloadMethodError.new(
104
- type_name: type_name,
105
- method_name: defn.name,
106
- kind: :instance,
107
- members: defn.overloads
108
- )
109
- end
82
+ Substitution.build(params.map(&:name), args)
83
+ end
84
+
85
+ def define_instance(definition, type_name, subst)
86
+ one_ancestors = ancestor_builder.one_instance_ancestors(type_name)
87
+ methods = method_builder.build_instance(type_name)
88
+
89
+ one_ancestors.each_included_module do |mod|
90
+ mod.args.each do |arg|
91
+ validate_type_presence(arg)
92
+ end
93
+
94
+ define_instance(definition, mod.name, subst + tapp_subst(mod.name, mod.args))
95
+ end
96
+
97
+ interface_methods = interface_methods(one_ancestors.each_included_interface.to_a)
98
+ import_methods(definition, type_name, methods, interface_methods, subst)
99
+
100
+ one_ancestors.each_prepended_module do |mod|
101
+ mod.args.each do |arg|
102
+ validate_type_presence(arg)
103
+ end
110
104
 
111
- definition.methods[defn.name]
105
+ define_instance(definition, mod.name, subst + tapp_subst(mod.name, mod.args))
106
+ end
112
107
 
113
- when AST::Members::AttrReader, AST::Members::AttrWriter, AST::Members::AttrAccessor
114
- raise
108
+ entry = env.class_decls[type_name] or raise "Unknown name for build_instance: #{type_name}"
109
+ args = entry.type_params.map {|param| Types::Variable.new(name: param.name, location: param.location) }
115
110
 
116
- end
111
+ entry.decls.each do |d|
112
+ subst_ = subst + Substitution.build(d.decl.type_params.each.map(&:name), args)
117
113
 
118
- defn.overloads.each do |overload|
119
- overload_defs = overload.types.map do |method_type|
120
- Definition::Method::TypeDef.new(
121
- type: method_type,
122
- member: overload,
123
- defined_in: type_name,
124
- implemented_in: nil
114
+ d.decl.members.each do |member|
115
+ case member
116
+ when AST::Members::AttrReader, AST::Members::AttrAccessor, AST::Members::AttrWriter
117
+ if member.kind == :instance
118
+ ivar_name = case member.ivar_name
119
+ when false
120
+ nil
121
+ else
122
+ member.ivar_name || :"@#{member.name}"
123
+ end
124
+
125
+ if ivar_name
126
+ insert_variable(
127
+ type_name,
128
+ definition.instance_variables,
129
+ name: ivar_name,
130
+ type: member.type.sub(subst_)
125
131
  )
126
132
  end
127
-
128
- method.defs.unshift(*overload_defs)
129
133
  end
130
134
 
131
- definition.methods[defn.name] = method
135
+ when AST::Members::InstanceVariable
136
+ insert_variable(
137
+ type_name,
138
+ definition.instance_variables,
139
+ name: member.name,
140
+ type: member.type.sub(subst_)
141
+ )
142
+
143
+ when AST::Members::ClassVariable
144
+ insert_variable(type_name, definition.class_variables, name: member.name, type: member.type)
132
145
  end
133
146
  end
134
147
  end
135
148
  end
136
149
 
137
- def build_instance(type_name, no_self_types: false)
138
- try_cache(type_name, cache: instance_cache, key: [type_name, no_self_types]) do
150
+ def build_instance(type_name)
151
+ type_name = env.normalize_module_name(type_name)
152
+
153
+ try_cache(type_name, cache: instance_cache) do
139
154
  entry = env.class_decls[type_name] or raise "Unknown name for build_instance: #{type_name}"
140
155
  ensure_namespace!(type_name.namespace, location: entry.decls[0].decl.location)
141
156
 
142
- case entry
143
- when Environment::ClassEntry, Environment::ModuleEntry
144
- ancestors = ancestor_builder.instance_ancestors(type_name)
145
- args = entry.type_params.map {|param| Types::Variable.new(name: param.name, location: param.location) }
146
- self_type = Types::ClassInstance.new(name: type_name, args: args, location: nil)
157
+ ancestors = ancestor_builder.instance_ancestors(type_name)
158
+ args = entry.type_params.map {|param| Types::Variable.new(name: param.name, location: param.location) }
159
+ self_type = Types::ClassInstance.new(name: type_name, args: args, location: nil)
147
160
 
148
- Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
149
- one_ancestors = ancestor_builder.one_instance_ancestors(type_name)
150
- methods = method_builder.build_instance(type_name)
161
+ Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
162
+ one_ancestors = ancestor_builder.one_instance_ancestors(type_name)
163
+ methods = method_builder.build_instance(type_name)
151
164
 
152
- validate_type_params definition, methods: methods, ancestors: one_ancestors
165
+ validate_type_params definition, methods: methods, ancestors: one_ancestors
153
166
 
167
+ if entry.is_a?(Environment::ClassEntry)
154
168
  if super_class = one_ancestors.super_class
155
- case super_class
156
- when Definition::Ancestor::Instance
157
- build_instance(super_class.name).yield_self do |defn|
158
- merge_definition(src: defn,
159
- dest: definition,
160
- subst: Substitution.build(defn.type_params, super_class.args),
161
- keep_super: true)
162
- end
163
- else
164
- raise
165
- end
166
- end
167
-
168
- if self_types = one_ancestors.self_types
169
- unless no_self_types
170
- self_types.each do |ans|
171
- defn = if ans.name.interface?
172
- build_interface(ans.name)
173
- else
174
- build_instance(ans.name)
175
- end
176
-
177
- # Successor interface method overwrites.
178
- merge_definition(
179
- src: defn,
180
- dest: definition,
181
- subst: Substitution.build(defn.type_params, ans.args),
182
- keep_super: true
183
- )
184
- end
185
- else
186
- methods_with_self = build_instance(type_name, no_self_types: false).methods
187
- end
188
- end
189
-
190
- one_ancestors.each_included_module do |mod|
191
- defn = build_instance(mod.name, no_self_types: true)
192
- merge_definition(src: defn,
193
- dest: definition,
194
- subst: Substitution.build(defn.type_params, mod.args))
195
- end
196
-
197
- interface_methods = {}
198
-
199
- one_ancestors.each_included_interface do |mod|
200
- defn = build_interface(mod.name)
201
- subst = Substitution.build(defn.type_params, mod.args)
169
+ super_class.is_a?(Definition::Ancestor::Instance) or raise
202
170
 
203
- defn.methods.each do |name, method|
204
- if interface_methods.key?(name)
205
- include_member = mod.source
206
-
207
- raise unless include_member.is_a?(AST::Members::Include)
171
+ build_instance(super_class.name).tap do |defn|
172
+ unless super_class.args.empty?
173
+ super_class.args.each do |arg|
174
+ validate_type_presence(arg)
175
+ end
208
176
 
209
- raise DuplicatedInterfaceMethodDefinitionError.new(
210
- type: self_type,
211
- method_name: name,
212
- member: include_member
213
- )
177
+ subst = tapp_subst(super_class.name, super_class.args)
178
+ defn = defn.sub(subst)
214
179
  end
215
180
 
216
- merge_method(type_name, interface_methods, name, method, subst, implemented_in: type_name)
181
+ definition.methods.merge!(defn.methods)
182
+ definition.instance_variables.merge!(defn.instance_variables)
183
+ definition.class_variables.merge!(defn.class_variables)
217
184
  end
218
185
  end
186
+ end
219
187
 
220
- if entry.is_a?(Environment::ModuleEntry)
221
- define_methods_module_instance(
222
- definition,
223
- methods: methods,
224
- interface_methods: interface_methods,
225
- module_self_methods: methods_with_self
226
- )
227
- else
228
- define_methods_instance(definition, methods: methods, interface_methods: interface_methods)
229
- end
230
-
231
- entry.decls.each do |d|
232
- subst = Substitution.build(d.decl.type_params.each.map(&:name), args)
233
-
234
- d.decl.members.each do |member|
235
- case member
236
- when AST::Members::AttrReader, AST::Members::AttrAccessor, AST::Members::AttrWriter
237
- if member.kind == :instance
238
- ivar_name = case member.ivar_name
239
- when false
240
- nil
241
- else
242
- member.ivar_name || :"@#{member.name}"
243
- end
244
-
245
- if ivar_name
246
- insert_variable(type_name,
247
- definition.instance_variables,
248
- name: ivar_name,
249
- type: member.type.sub(subst))
250
- end
251
- end
252
-
253
- when AST::Members::InstanceVariable
254
- insert_variable(type_name,
255
- definition.instance_variables,
256
- name: member.name,
257
- type: member.type.sub(subst))
188
+ if entry.is_a?(Environment::ModuleEntry)
189
+ if self_types = one_ancestors.self_types
190
+ self_types.each do |ans|
191
+ ans.args.each do |arg|
192
+ validate_type_presence(arg)
193
+ end
258
194
 
259
- when AST::Members::ClassVariable
260
- insert_variable(type_name, definition.class_variables, name: member.name, type: member.type)
195
+ subst = tapp_subst(ans.name, ans.args)
196
+ if ans.name.interface?
197
+ define_interface(definition, ans.name, subst)
198
+ else
199
+ define_instance(definition, ans.name, subst)
261
200
  end
262
201
  end
263
202
  end
264
-
265
- one_ancestors.each_prepended_module do |mod|
266
- defn = build_instance(mod.name, no_self_types: true)
267
- merge_definition(src: defn,
268
- dest: definition,
269
- subst: Substitution.build(defn.type_params, mod.args))
270
- end
271
203
  end
204
+
205
+ define_instance(definition, type_name, Substitution.new)
272
206
  end
273
207
  end
274
208
  end
@@ -280,91 +214,62 @@ module RBS
280
214
  entry = env.class_decls[type_name] or raise "Unknown name for build_singleton0: #{type_name}"
281
215
  ensure_namespace!(type_name.namespace, location: entry.decls[0].decl.location)
282
216
 
283
- case entry
284
- when Environment::ClassEntry, Environment::ModuleEntry
285
- ancestors = ancestor_builder.singleton_ancestors(type_name)
286
- self_type = Types::ClassSingleton.new(name: type_name, location: nil)
287
-
288
- Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
289
- one_ancestors = ancestor_builder.one_singleton_ancestors(type_name)
290
-
291
- if super_class = one_ancestors.super_class
292
- case super_class
293
- when Definition::Ancestor::Instance
294
- defn = build_instance(super_class.name)
295
- merge_definition(src: defn,
296
- dest: definition,
297
- subst: Substitution.build(defn.type_params, super_class.args),
298
- keep_super: true)
299
- when Definition::Ancestor::Singleton
300
- defn = build_singleton0(super_class.name)
301
- merge_definition(src: defn, dest: definition, subst: Substitution.new, keep_super: true)
302
- end
303
- end
217
+ ancestors = ancestor_builder.singleton_ancestors(type_name)
218
+ self_type = Types::ClassSingleton.new(name: type_name, location: nil)
304
219
 
305
- one_ancestors.each_extended_module do |mod|
306
- mod.args.each do |arg|
307
- validate_type_presence(arg)
308
- end
309
-
310
- mod_defn = build_instance(mod.name, no_self_types: true)
311
- merge_definition(src: mod_defn,
312
- dest: definition,
313
- subst: Substitution.build(mod_defn.type_params, mod.args))
220
+ Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
221
+ one_ancestors = ancestor_builder.one_singleton_ancestors(type_name)
222
+
223
+ if super_class = one_ancestors.super_class
224
+ case super_class
225
+ when Definition::Ancestor::Instance
226
+ defn = build_instance(super_class.name)
227
+ when Definition::Ancestor::Singleton
228
+ defn = build_singleton0(super_class.name)
314
229
  end
315
230
 
316
- interface_methods = {}
317
- one_ancestors.each_extended_interface do |mod|
318
- mod.args.each do |arg|
319
- validate_type_presence(arg)
320
- end
231
+ definition.methods.merge!(defn.methods)
232
+ definition.instance_variables.merge!(defn.instance_variables)
233
+ definition.class_variables.merge!(defn.class_variables)
234
+ end
321
235
 
322
- mod_defn = build_interface(mod.name)
323
- subst = Substitution.build(mod_defn.type_params, mod.args)
236
+ one_ancestors = ancestor_builder.one_singleton_ancestors(type_name)
237
+ methods = method_builder.build_singleton(type_name)
324
238
 
325
- mod_defn.methods.each do |name, method|
326
- if interface_methods.key?(name)
327
- src_member = mod.source
239
+ one_ancestors.each_extended_module do |mod|
240
+ mod.args.each do |arg|
241
+ validate_type_presence(arg)
242
+ end
328
243
 
329
- raise unless src_member.is_a?(AST::Members::Extend)
244
+ subst = tapp_subst(mod.name, mod.args)
245
+ define_instance(definition, mod.name, subst)
246
+ end
330
247
 
331
- raise DuplicatedInterfaceMethodDefinitionError.new(
332
- type: self_type,
333
- method_name: name,
334
- member: src_member
335
- )
336
- end
248
+ interface_methods = interface_methods(one_ancestors.each_extended_interface.to_a)
249
+ import_methods(definition, type_name, methods, interface_methods, Substitution.new)
337
250
 
338
- merge_method(type_name, interface_methods, name, method, subst, implemented_in: type_name)
339
- end
340
- end
251
+ entry.decls.each do |d|
252
+ d.decl.members.each do |member|
253
+ case member
254
+ when AST::Members::AttrReader, AST::Members::AttrAccessor, AST::Members::AttrWriter
255
+ if member.kind == :singleton
256
+ ivar_name = case member.ivar_name
257
+ when false
258
+ nil
259
+ else
260
+ member.ivar_name || :"@#{member.name}"
261
+ end
341
262
 
342
- methods = method_builder.build_singleton(type_name)
343
- define_methods_singleton(definition, methods: methods, interface_methods: interface_methods)
344
-
345
- entry.decls.each do |d|
346
- d.decl.members.each do |member|
347
- case member
348
- when AST::Members::AttrReader, AST::Members::AttrAccessor, AST::Members::AttrWriter
349
- if member.kind == :singleton
350
- ivar_name = case member.ivar_name
351
- when false
352
- nil
353
- else
354
- member.ivar_name || :"@#{member.name}"
355
- end
356
-
357
- if ivar_name
358
- insert_variable(type_name, definition.instance_variables, name: ivar_name, type: member.type)
359
- end
263
+ if ivar_name
264
+ insert_variable(type_name, definition.instance_variables, name: ivar_name, type: member.type)
360
265
  end
266
+ end
361
267
 
362
- when AST::Members::ClassInstanceVariable
363
- insert_variable(type_name, definition.instance_variables, name: member.name, type: member.type)
268
+ when AST::Members::ClassInstanceVariable
269
+ insert_variable(type_name, definition.instance_variables, name: member.name, type: member.type)
364
270
 
365
- when AST::Members::ClassVariable
366
- insert_variable(type_name, definition.class_variables, name: member.name, type: member.type)
367
- end
271
+ when AST::Members::ClassVariable
272
+ insert_variable(type_name, definition.class_variables, name: member.name, type: member.type)
368
273
  end
369
274
  end
370
275
  end
@@ -373,108 +278,107 @@ module RBS
373
278
  end
374
279
 
375
280
  def build_singleton(type_name)
281
+ type_name = env.normalize_module_name(type_name)
282
+
376
283
  try_cache type_name, cache: singleton_cache do
377
284
  entry = env.class_decls[type_name] or raise "Unknown name for build_singleton: #{type_name}"
378
285
  ensure_namespace!(type_name.namespace, location: entry.decls[0].decl.location)
379
286
 
380
- case entry
381
- when Environment::ClassEntry, Environment::ModuleEntry
382
- ancestors = ancestor_builder.singleton_ancestors(type_name)
383
- self_type = Types::ClassSingleton.new(name: type_name, location: nil)
384
-
385
- Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
386
- def0 = build_singleton0(type_name)
387
- subst = Substitution.new
388
-
389
- merge_definition(src: def0, dest: definition, subst: subst, keep_super: true)
390
-
391
- if entry.is_a?(Environment::ClassEntry)
392
- new_method = definition.methods[:new]
393
- if new_method.defs.all? {|d| d.defined_in == BuiltinNames::Class.name }
394
- alias_methods = definition.methods.each.with_object([]) do |entry, array|
395
- # @type var method: Definition::Method?
396
- name, method = entry
397
- while method
398
- if method.alias_of == new_method
399
- array << name
400
- break
401
- end
402
- method = method.alias_of
287
+ ancestors = ancestor_builder.singleton_ancestors(type_name)
288
+ self_type = Types::ClassSingleton.new(name: type_name, location: nil)
289
+
290
+ Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
291
+ definition0 = build_singleton0(type_name)
292
+ definition.methods.merge!(definition0.methods)
293
+ definition.instance_variables.merge!(definition0.instance_variables)
294
+ definition.class_variables.merge!(definition0.class_variables)
295
+
296
+ if entry.is_a?(Environment::ClassEntry)
297
+ new_method = definition.methods[:new]
298
+
299
+ if new_method.defs.all? {|d| d.defined_in == BuiltinNames::Class.name }
300
+ # The method is _untyped new_.
301
+
302
+ alias_methods = definition.methods.each.with_object([]) do |entry, array|
303
+ # @type var method: Definition::Method?
304
+ name, method = entry
305
+ while method
306
+ if method.alias_of == new_method
307
+ array << name
308
+ break
403
309
  end
310
+ method = method.alias_of
404
311
  end
312
+ end
405
313
 
406
- # The method is _untyped new_.
407
-
408
- instance = build_instance(type_name)
409
- initialize = instance.methods[:initialize]
314
+ instance = build_instance(type_name)
315
+ initialize = instance.methods[:initialize]
410
316
 
411
- if initialize
412
- class_params = entry.type_params
317
+ if initialize
318
+ class_params = entry.type_params
413
319
 
414
- # Inject a virtual _typed new_.
415
- initialize_defs = initialize.defs
416
- typed_new = Definition::Method.new(
417
- super_method: new_method,
418
- defs: initialize_defs.map do |initialize_def|
419
- method_type = initialize_def.type
320
+ # Inject a virtual _typed new_.
321
+ initialize_defs = initialize.defs
322
+ typed_new = Definition::Method.new(
323
+ super_method: new_method,
324
+ defs: initialize_defs.map do |initialize_def|
325
+ method_type = initialize_def.type
420
326
 
421
- class_type_param_vars = Set.new(class_params.map(&:name))
422
- method_type_param_vars = Set.new(method_type.type_params.map(&:name))
327
+ class_type_param_vars = Set.new(class_params.map(&:name))
328
+ method_type_param_vars = Set.new(method_type.type_params.map(&:name))
423
329
 
424
- if class_type_param_vars.intersect?(method_type_param_vars)
425
- new_method_param_names = method_type.type_params.map do |method_param|
426
- if class_type_param_vars.include?(method_param.name)
427
- Types::Variable.fresh(method_param.name).name
428
- else
429
- method_param.name
430
- end
330
+ if class_type_param_vars.intersect?(method_type_param_vars)
331
+ new_method_param_names = method_type.type_params.map do |method_param|
332
+ if class_type_param_vars.include?(method_param.name)
333
+ Types::Variable.fresh(method_param.name).name
334
+ else
335
+ method_param.name
431
336
  end
337
+ end
432
338
 
433
- sub = Substitution.build(
434
- method_type.type_params.map(&:name),
435
- Types::Variable.build(new_method_param_names)
436
- )
339
+ sub = Substitution.build(
340
+ method_type.type_params.map(&:name),
341
+ Types::Variable.build(new_method_param_names)
342
+ )
437
343
 
438
- method_params = class_params + AST::TypeParam.rename(method_type.type_params, new_names: new_method_param_names)
439
- method_type = method_type
440
- .update(type_params: [])
441
- .sub(sub)
442
- .update(type_params: method_params)
443
- else
444
- method_type = method_type
445
- .update(type_params: class_params + method_type.type_params)
446
- end
344
+ method_params = class_params + AST::TypeParam.rename(method_type.type_params, new_names: new_method_param_names)
345
+ method_type = method_type
346
+ .update(type_params: [])
347
+ .sub(sub)
348
+ .update(type_params: method_params)
349
+ else
350
+ method_type = method_type
351
+ .update(type_params: class_params + method_type.type_params)
352
+ end
447
353
 
448
- method_type = method_type.update(
449
- type: method_type.type.with_return_type(
450
- Types::ClassInstance.new(
451
- name: type_name,
452
- args: entry.type_params.map {|param| Types::Variable.new(name: param.name, location: param.location) },
453
- location: nil
454
- )
354
+ method_type = method_type.update(
355
+ type: method_type.type.with_return_type(
356
+ Types::ClassInstance.new(
357
+ name: type_name,
358
+ args: entry.type_params.map {|param| Types::Variable.new(name: param.name, location: param.location) },
359
+ location: nil
455
360
  )
456
361
  )
362
+ )
457
363
 
458
- Definition::Method::TypeDef.new(
459
- type: method_type,
460
- member: initialize_def.member,
461
- defined_in: initialize_def.defined_in,
462
- implemented_in: initialize_def.implemented_in
463
- )
464
- end,
465
- accessibility: :public,
466
- annotations: [],
467
- alias_of: nil
468
- )
364
+ Definition::Method::TypeDef.new(
365
+ type: method_type,
366
+ member: initialize_def.member,
367
+ defined_in: initialize_def.defined_in,
368
+ implemented_in: initialize_def.implemented_in
369
+ )
370
+ end,
371
+ accessibility: :public,
372
+ alias_of: nil
373
+ )
469
374
 
470
- definition.methods[:new] = typed_new
375
+ definition.methods[:new] = typed_new
471
376
 
472
- alias_methods.each do |alias_name|
473
- definition.methods[alias_name] = definition.methods[alias_name].update(
474
- alias_of: typed_new,
475
- defs: typed_new.defs
476
- )
477
- end
377
+ alias_methods.each do |alias_name|
378
+ definition.methods[alias_name] = definition.methods[alias_name].update(
379
+ alias_of: typed_new,
380
+ defs: typed_new.defs
381
+ )
478
382
  end
479
383
  end
480
384
  end
@@ -483,6 +387,26 @@ module RBS
483
387
  end
484
388
  end
485
389
 
390
+ def interface_methods(interface_ancestors)
391
+ interface_methods = {} #: interface_methods
392
+
393
+ interface_ancestors.each do |mod|
394
+ source =
395
+ case mod.source
396
+ when AST::Members::Include, AST::Members::Extend
397
+ mod.source
398
+ else
399
+ raise "Interface mixin must be include/extend: #{mod.source.inspect}"
400
+ end
401
+
402
+ methods = method_builder.build_interface(mod.name)
403
+
404
+ interface_methods[mod] = [methods, source]
405
+ end
406
+
407
+ interface_methods
408
+ end
409
+
486
410
  def validate_params_with(type_params, result:)
487
411
  type_params.each do |param|
488
412
  unless param.unchecked?
@@ -539,7 +463,7 @@ module RBS
539
463
 
540
464
  method_types = case original = defn.original
541
465
  when AST::Members::MethodDefinition
542
- original.types
466
+ original.overloads.map(&:method_type)
543
467
  when AST::Members::AttrWriter, AST::Members::AttrReader, AST::Members::AttrAccessor
544
468
  if defn.name.to_s.end_with?("=")
545
469
  [
@@ -597,267 +521,223 @@ module RBS
597
521
  )
598
522
  end
599
523
 
600
- def define_methods_instance(definition, methods:, interface_methods:)
601
- define_methods(
602
- definition,
603
- methods: methods,
604
- interface_methods: interface_methods,
605
- methods_with_self: nil,
606
- super_interface_method: false
607
- )
608
- end
524
+ def import_methods(definition, module_name, module_methods, interfaces_methods, subst)
525
+ new_methods = {} #: Hash[Symbol, Definition::Method]
526
+ interface_method_duplicates = Set[] #: Set[Symbol]
609
527
 
610
- def define_methods_module_instance(definition, methods:, interface_methods:, module_self_methods:)
611
- define_methods(definition, methods: methods, interface_methods: interface_methods, methods_with_self: module_self_methods, super_interface_method: true)
612
- end
528
+ interfaces_methods.each do |interface, (methods, member)|
529
+ unless interface.args.empty?
530
+ methods.type.is_a?(Types::Interface) or raise
531
+ params = methods.type.args.map do |arg|
532
+ arg.is_a?(Types::Variable) or raise
533
+ arg.name
534
+ end
613
535
 
614
- def define_methods_singleton(definition, methods:, interface_methods:)
615
- define_methods(
616
- definition,
617
- methods: methods,
618
- interface_methods: interface_methods,
619
- methods_with_self: nil,
620
- super_interface_method: false
621
- )
622
- end
536
+ interface.args.each do |arg|
537
+ validate_type_presence(arg)
538
+ end
623
539
 
624
- def define_methods(definition, methods:, interface_methods:, methods_with_self:, super_interface_method:)
625
- methods.each do |method_def|
626
- method_name = method_def.name
627
- original = method_def.original
540
+ subst_ = subst + Substitution.build(params, interface.args)
541
+ else
542
+ subst_ = subst
543
+ end
628
544
 
629
- if original.is_a?(AST::Members::Alias)
630
- existing_method = interface_methods[method_name] || definition.methods[method_name]
631
- original_method =
632
- interface_methods[original.old_name] ||
633
- methods_with_self&.[](original.old_name) ||
634
- definition.methods[original.old_name]
545
+ methods.each do |method|
546
+ if interface_method_duplicates.include?(method.name)
547
+ member.is_a?(AST::Members::Include) || member.is_a?(AST::Members::Extend) or raise
635
548
 
636
- unless original_method
637
- raise UnknownMethodAliasError.new(
638
- type_name: definition.type_name,
639
- original_name: original.old_name,
640
- aliased_name: original.new_name,
641
- location: original.location
549
+ raise DuplicatedInterfaceMethodDefinitionError.new(
550
+ type: definition.self_type,
551
+ method_name: method.name,
552
+ member: member
642
553
  )
643
554
  end
644
555
 
645
- method = Definition::Method.new(
646
- super_method: existing_method,
647
- defs: original_method.defs.map do |defn|
648
- defn.update(defined_in: definition.type_name, implemented_in: definition.type_name)
649
- end,
650
- accessibility: original_method.accessibility,
651
- alias_of: original_method
556
+ interface_method_duplicates << method.name
557
+ define_method(
558
+ new_methods,
559
+ definition,
560
+ method,
561
+ subst_,
562
+ defined_in: interface.name,
563
+ implemented_in: module_name
652
564
  )
653
- else
654
- if interface_methods.key?(method_name)
655
- interface_method = interface_methods[method_name]
656
-
657
- if original = method_def.original
658
- raise DuplicatedMethodDefinitionError.new(
659
- type: definition.self_type,
660
- method_name: method_name,
661
- members: [original]
662
- )
663
- end
565
+ end
566
+ end
664
567
 
665
- definition.methods[method_name] = interface_method
666
- end
568
+ module_methods.each do |method|
569
+ define_method(
570
+ new_methods,
571
+ definition,
572
+ method,
573
+ subst,
574
+ defined_in: module_name,
575
+ implemented_in: module_name.interface? ? nil : module_name
576
+ )
577
+ end
667
578
 
668
- existing_method = definition.methods[method_name]
579
+ definition.methods.merge!(new_methods)
580
+ end
669
581
 
670
- case original
671
- when AST::Members::MethodDefinition
672
- defs = original.types.map do |method_type|
673
- Definition::Method::TypeDef.new(
674
- type: method_type,
675
- member: original,
676
- defined_in: definition.type_name,
677
- implemented_in: definition.type_name
678
- )
679
- end
582
+ def define_method(methods, definition, method, subst, defined_in:, implemented_in: defined_in)
583
+ existing_method = methods[method.name] || definition.methods[method.name]
680
584
 
681
- # @type var accessibility: RBS::Definition::accessibility
682
- accessibility = if method_name == :initialize
683
- :private
684
- else
685
- method_def.accessibility
686
- end
687
-
688
- method = Definition::Method.new(
689
- super_method: existing_method,
690
- defs: defs,
691
- accessibility: accessibility,
692
- alias_of: nil
693
- )
585
+ case original = method.original
586
+ when AST::Members::Alias
587
+ original_method = methods[original.old_name] || definition.methods[original.old_name]
694
588
 
695
- when AST::Members::AttrReader, AST::Members::AttrWriter, AST::Members::AttrAccessor
696
- method_type = if method_name.to_s.end_with?("=")
697
- # setter
698
- MethodType.new(
699
- type_params: [],
700
- type: Types::Function.empty(original.type).update(
701
- required_positionals: [
702
- Types::Function::Param.new(type: original.type, name: original.name)
703
- ]
704
- ),
705
- block: nil,
706
- location: nil
707
- )
708
- else
709
- # getter
710
- MethodType.new(
711
- type_params: [],
712
- type: Types::Function.empty(original.type),
713
- block: nil,
714
- location: nil
715
- )
716
- end
717
- defs = [
718
- Definition::Method::TypeDef.new(
719
- type: method_type,
720
- member: original,
721
- defined_in: definition.type_name,
722
- implemented_in: definition.type_name
723
- )
724
- ]
589
+ unless original_method
590
+ raise UnknownMethodAliasError.new(
591
+ type_name: definition.type_name,
592
+ original_name: original.old_name,
593
+ aliased_name: original.new_name,
594
+ location: original.location
595
+ )
596
+ end
725
597
 
726
- method = Definition::Method.new(
727
- super_method: existing_method,
728
- defs: defs,
729
- accessibility: method_def.accessibility,
730
- alias_of: nil
731
- )
598
+ method_definition = Definition::Method.new(
599
+ super_method: existing_method,
600
+ defs: original_method.defs.map do |defn|
601
+ defn.update(defined_in: defined_in, implemented_in: implemented_in)
602
+ end,
603
+ accessibility: original_method.accessibility,
604
+ alias_of: original_method
605
+ )
606
+ when AST::Members::MethodDefinition
607
+ if duplicated_method = methods[method.name]
608
+ raise DuplicatedMethodDefinitionError.new(
609
+ type: definition.self_type,
610
+ method_name: method.name,
611
+ members: [original, *duplicated_method.members]
612
+ )
613
+ end
732
614
 
733
- when nil
734
- unless definition.methods.key?(method_name)
735
- raise InvalidOverloadMethodError.new(
736
- type_name: definition.type_name,
737
- method_name: method_name,
738
- kind: :instance,
739
- members: method_def.overloads
740
- )
741
- end
615
+ defs = original.overloads.map do |overload|
616
+ Definition::Method::TypeDef.new(
617
+ type: subst.empty? ? overload.method_type : overload.method_type.sub(subst),
618
+ member: original,
619
+ defined_in: defined_in,
620
+ implemented_in: implemented_in
621
+ )
622
+ end
742
623
 
743
- if !super_interface_method && existing_method.defs.any? {|defn| defn.defined_in.interface? }
744
- super_method = existing_method.super_method
745
- else
746
- super_method = existing_method
747
- end
624
+ # @type var accessibility: RBS::Definition::accessibility
625
+ accessibility = if method.name == :initialize
626
+ :private
627
+ else
628
+ method.accessibility
629
+ end
630
+
631
+ # Skip setting up `super_method` if `implemented_in` is `nil`, that means the type doesn't have implementation.
632
+ # This typically happens if the type is an interface.
633
+ if implemented_in
634
+ super_method = existing_method
635
+ end
748
636
 
749
- method = Definition::Method.new(
750
- super_method: super_method,
751
- defs: existing_method.defs.map do |defn|
752
- defn.update(implemented_in: definition.type_name)
753
- end,
754
- accessibility: existing_method.accessibility,
755
- alias_of: existing_method.alias_of
637
+ method_definition = Definition::Method.new(
638
+ super_method: super_method,
639
+ defs: defs,
640
+ accessibility: accessibility,
641
+ alias_of: nil
642
+ )
643
+ when AST::Members::AttrReader, AST::Members::AttrWriter, AST::Members::AttrAccessor
644
+ if duplicated_method = methods[method.name]
645
+ raise DuplicatedMethodDefinitionError.new(
646
+ type: definition.self_type,
647
+ method_name: method.name,
648
+ members: [*duplicated_method.members, original]
649
+ )
650
+ end
651
+
652
+ attr_type = original.type.sub(subst)
653
+ method_type =
654
+ if method.name.to_s.end_with?("=")
655
+ # setter
656
+ MethodType.new(
657
+ type_params: [],
658
+ type: Types::Function.empty(attr_type).update(
659
+ required_positionals: [
660
+ Types::Function::Param.new(type: attr_type, name: original.name)
661
+ ]
662
+ ),
663
+ block: nil,
664
+ location: nil
665
+ )
666
+ else
667
+ # getter
668
+ MethodType.new(
669
+ type_params: [],
670
+ type: Types::Function.empty(attr_type),
671
+ block: nil,
672
+ location: nil
756
673
  )
757
674
  end
675
+
676
+ if implemented_in
677
+ super_method = existing_method
758
678
  end
759
679
 
760
- method_def.overloads.each do |overload|
761
- type_defs = overload.types.map do |method_type|
680
+ method_definition = Definition::Method.new(
681
+ super_method: super_method,
682
+ defs: [
762
683
  Definition::Method::TypeDef.new(
763
684
  type: method_type,
764
- member: overload,
685
+ member: original,
765
686
  defined_in: definition.type_name,
766
687
  implemented_in: definition.type_name
767
688
  )
768
- end
769
-
770
- method.defs.unshift(*type_defs)
771
- end
772
-
773
- definition.methods[method_name] = method
774
- end
775
-
776
- interface_methods.each do |name, method|
777
- unless methods.methods.key?(name)
778
- merge_method(definition.type_name, definition.methods, name, method, Substitution.new)
689
+ ],
690
+ accessibility: method.accessibility,
691
+ alias_of: nil
692
+ )
693
+ when nil
694
+ # Overloading method definition only
695
+
696
+ case
697
+ when methods.key?(method.name)
698
+ # The method is defined in an interface
699
+ super_method = methods[method.name].super_method
700
+ when definition.methods.key?(method.name)
701
+ # The method is defined in the super class
702
+ super_method = existing_method
703
+ else
704
+ # Cannot find any non-overloading method
705
+ raise InvalidOverloadMethodError.new(
706
+ type_name: definition.type_name,
707
+ method_name: method.name,
708
+ kind: :instance,
709
+ members: method.overloads
710
+ )
779
711
  end
780
- end
781
- end
782
-
783
- def merge_definition(src:, dest:, subst:, implemented_in: :keep, keep_super: false)
784
- src.methods.each do |name, method|
785
- merge_method(dest.type_name, dest.methods, name, method, subst, implemented_in: implemented_in, keep_super: keep_super)
786
- end
787
712
 
788
- src.instance_variables.each do |name, variable|
789
- merge_variable(dest.instance_variables, name, variable, subst, keep_super: keep_super)
790
- end
791
-
792
- src.class_variables.each do |name, variable|
793
- merge_variable(dest.class_variables, name, variable, subst, keep_super: keep_super)
713
+ method_definition = Definition::Method.new(
714
+ super_method: super_method,
715
+ defs: existing_method.defs.map do |defn|
716
+ defn.update(implemented_in: definition.type_name)
717
+ end,
718
+ accessibility: existing_method.accessibility,
719
+ alias_of: existing_method.alias_of
720
+ )
794
721
  end
795
- end
796
-
797
- def merge_variable(variables, name, variable, sub, keep_super: false)
798
- super_variable = variables[name]
799
722
 
800
- variables[name] = Definition::Variable.new(
801
- parent_variable: keep_super ? variable.parent_variable : super_variable,
802
- type: sub.empty? ? variable.type : variable.type.sub(sub),
803
- declared_in: variable.declared_in
804
- )
805
- end
806
-
807
- def merge_method(type_name, methods, name, method, sub, implemented_in: :keep, keep_super: false)
808
- if sub.empty? && implemented_in == :keep && keep_super
809
- methods[name] = method
810
- else
811
- if sub.empty? && implemented_in == :keep
812
- defs = method.defs
813
- else
814
- defs = method.defs.map do |defn|
815
- defn.update(
816
- type: sub.empty? ? defn.type : defn.type.sub(sub),
817
- implemented_in: case implemented_in
818
- when :keep
819
- defn.implemented_in
820
- when nil
821
- nil
822
- else
823
- implemented_in
824
- end
825
- )
826
- end
723
+ method.overloads.each do |overloading_def|
724
+ overloading_def.overloads.reverse_each do |overload|
725
+ type_def = Definition::Method::TypeDef.new(
726
+ type: subst.empty? ? overload.method_type : overload.method_type.sub(subst),
727
+ member: overloading_def,
728
+ defined_in: definition.type_name,
729
+ implemented_in: definition.type_name
730
+ )
827
731
 
828
- defs = method.defs.map do |defn|
829
- defn.update(
830
- type: sub.empty? ? defn.type : defn.type.sub(sub),
831
- implemented_in: case implemented_in
832
- when :keep
833
- defn.implemented_in
834
- when nil
835
- nil
836
- else
837
- implemented_in
838
- end
839
- )
840
- end
732
+ method_definition.defs.unshift(type_def)
841
733
  end
842
-
843
- super_method = methods[name]
844
-
845
- methods[name] = Definition::Method.new(
846
- super_method: keep_super ? method.super_method : super_method,
847
- accessibility: method.accessibility,
848
- defs: defs,
849
- alias_of: method.alias_of
850
- )
851
734
  end
852
- end
853
735
 
854
- def try_cache(type_name, cache:, key: nil)
855
- # @type var cc: Hash[untyped, Definition | nil]
856
- # @type var key: untyped
857
- key ||= type_name
858
- cc = _ = cache
736
+ methods[method.name] = method_definition
737
+ end
859
738
 
860
- cc[key] ||= yield
739
+ def try_cache(type_name, cache:)
740
+ cache[type_name] ||= yield
861
741
  end
862
742
 
863
743
  def expand_alias(type_name)
@@ -865,13 +745,13 @@ module RBS
865
745
  end
866
746
 
867
747
  def expand_alias1(type_name)
868
- entry = env.alias_decls[type_name] or raise "Unknown alias name: #{type_name}"
748
+ entry = env.type_alias_decls[type_name] or raise "Unknown alias name: #{type_name}"
869
749
  as = entry.decl.type_params.each.map { Types::Bases::Any.new(location: nil) }
870
750
  expand_alias2(type_name, as)
871
751
  end
872
752
 
873
753
  def expand_alias2(type_name, args)
874
- entry = env.alias_decls[type_name] or raise "Unknown alias name: #{type_name}"
754
+ entry = env.type_alias_decls[type_name] or raise "Unknown alias name: #{type_name}"
875
755
 
876
756
  ensure_namespace!(type_name.namespace, location: entry.decl.location)
877
757
  params = entry.decl.type_params.each.map(&:name)
@@ -903,8 +783,7 @@ module RBS
903
783
  builder.interface_cache.merge!(interface_cache)
904
784
 
905
785
  except.each do |name|
906
- builder.instance_cache.delete([name, true])
907
- builder.instance_cache.delete([name, false])
786
+ builder.instance_cache.delete(name)
908
787
  builder.singleton_cache.delete(name)
909
788
  builder.singleton0_cache.delete(name)
910
789
  builder.interface_cache.delete(name)
@@ -926,9 +805,7 @@ module RBS
926
805
  def validate_type_name(name, location)
927
806
  name = name.absolute!
928
807
 
929
- return if name.class? && env.class_decls.key?(name)
930
- return if name.interface? && env.interface_decls.key?(name)
931
- return if name.alias? && env.alias_decls.key?(name)
808
+ return if env.type_name?(name)
932
809
 
933
810
  raise NoTypeFoundError.new(type_name: name, location: location)
934
811
  end