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.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +0 -3
- data/Gemfile +1 -1
- data/Gemfile.lock +17 -17
- data/README.md +1 -0
- data/Rakefile +66 -0
- 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 +18 -2
- data/ext/rbs_extension/constants.h +9 -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 +287 -57
- data/ext/rbs_extension/ruby_objs.c +71 -5
- data/ext/rbs_extension/ruby_objs.h +9 -2
- 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/ast/members.rb +49 -15
- data/lib/rbs/cli.rb +38 -19
- data/lib/rbs/collection/config/lockfile.rb +115 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +99 -53
- data/lib/rbs/collection/config.rb +12 -40
- data/lib/rbs/collection/installer.rb +9 -13
- data/lib/rbs/collection/sources/base.rb +2 -2
- data/lib/rbs/collection/sources/git.rb +135 -62
- data/lib/rbs/collection/sources/rubygems.rb +10 -12
- data/lib/rbs/collection/sources/stdlib.rb +10 -13
- data/lib/rbs/collection/sources.rb +7 -1
- data/lib/rbs/collection.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +24 -8
- data/lib/rbs/definition_builder/method_builder.rb +3 -3
- data/lib/rbs/definition_builder.rb +456 -579
- data/lib/rbs/environment/use_map.rb +77 -0
- data/lib/rbs/environment.rb +356 -85
- data/lib/rbs/environment_loader.rb +20 -17
- data/lib/rbs/environment_walker.rb +1 -1
- data/lib/rbs/errors.rb +34 -37
- data/lib/rbs/locator.rb +3 -3
- data/lib/rbs/parser_aux.rb +8 -6
- data/lib/rbs/prototype/helpers.rb +29 -13
- data/lib/rbs/prototype/node_usage.rb +99 -0
- data/lib/rbs/prototype/rb.rb +3 -2
- data/lib/rbs/prototype/rbi.rb +6 -4
- data/lib/rbs/prototype/runtime.rb +25 -12
- 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/substitution.rb +19 -0
- 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/types.rb +1 -5
- data/lib/rbs/validator.rb +25 -3
- data/lib/rbs/variance_calculator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +54 -19
- data/lib/rbs.rb +3 -2
- data/lib/rdoc_plugin/parser.rb +3 -3
- data/schema/members.json +15 -10
- data/sig/ancestor_graph.rbs +22 -2
- data/sig/collection/config/lockfile.rbs +80 -0
- data/sig/collection/config/lockfile_generator.rbs +53 -0
- data/sig/collection/config.rbs +5 -48
- data/sig/collection/installer.rbs +1 -1
- data/sig/collection/sources.rbs +76 -33
- data/sig/constant.rbs +1 -1
- data/sig/declarations.rbs +36 -3
- data/sig/definition.rbs +1 -1
- data/sig/definition_builder.rbs +94 -82
- data/sig/directives.rbs +61 -0
- data/sig/environment.rbs +150 -28
- data/sig/environment_loader.rbs +2 -2
- data/sig/errors.rbs +42 -0
- data/sig/members.rbs +31 -7
- data/sig/parser.rbs +8 -15
- data/sig/prototype/node_usage.rbs +20 -0
- data/sig/resolver/constant_resolver.rbs +1 -2
- data/sig/shims/bundler.rbs +31 -0
- data/sig/shims/rubygems.rbs +15 -0
- data/sig/shims.rbs +0 -22
- data/sig/substitution.rbs +6 -0
- data/sig/use_map.rbs +35 -0
- data/sig/validator.rbs +12 -5
- data/sig/writer.rbs +6 -2
- metadata +16 -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
@@ -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
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
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
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
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
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
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
|
-
|
105
|
+
define_instance(definition, mod.name, subst + tapp_subst(mod.name, mod.args))
|
106
|
+
end
|
112
107
|
|
113
|
-
|
114
|
-
|
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
|
-
|
111
|
+
entry.decls.each do |d|
|
112
|
+
subst_ = subst + Substitution.build(d.decl.type_params.each.map(&:name), args)
|
117
113
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
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
|
-
|
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
|
138
|
-
|
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
|
-
|
143
|
-
|
144
|
-
|
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
|
-
|
149
|
-
|
150
|
-
|
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
|
-
|
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
|
-
|
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
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
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
|
-
|
210
|
-
|
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
|
-
|
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
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
-
|
260
|
-
|
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
|
-
|
284
|
-
|
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
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
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
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
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
|
-
|
323
|
-
|
236
|
+
one_ancestors = ancestor_builder.one_singleton_ancestors(type_name)
|
237
|
+
methods = method_builder.build_singleton(type_name)
|
324
238
|
|
325
|
-
|
326
|
-
|
327
|
-
|
239
|
+
one_ancestors.each_extended_module do |mod|
|
240
|
+
mod.args.each do |arg|
|
241
|
+
validate_type_presence(arg)
|
242
|
+
end
|
328
243
|
|
329
|
-
|
244
|
+
subst = tapp_subst(mod.name, mod.args)
|
245
|
+
define_instance(definition, mod.name, subst)
|
246
|
+
end
|
330
247
|
|
331
|
-
|
332
|
-
|
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
|
-
|
339
|
-
|
340
|
-
|
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
|
-
|
343
|
-
|
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
|
-
|
363
|
-
|
268
|
+
when AST::Members::ClassInstanceVariable
|
269
|
+
insert_variable(type_name, definition.instance_variables, name: member.name, type: member.type)
|
364
270
|
|
365
|
-
|
366
|
-
|
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
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
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
|
-
|
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
|
-
|
412
|
-
|
317
|
+
if initialize
|
318
|
+
class_params = entry.type_params
|
413
319
|
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
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
|
-
|
422
|
-
|
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
|
-
|
425
|
-
|
426
|
-
|
427
|
-
|
428
|
-
|
429
|
-
|
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
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
339
|
+
sub = Substitution.build(
|
340
|
+
method_type.type_params.map(&:name),
|
341
|
+
Types::Variable.build(new_method_param_names)
|
342
|
+
)
|
437
343
|
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
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
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
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
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
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
|
-
|
375
|
+
definition.methods[:new] = typed_new
|
471
376
|
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
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.
|
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
|
601
|
-
|
602
|
-
|
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
|
-
|
611
|
-
|
612
|
-
|
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
|
-
|
615
|
-
|
616
|
-
|
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
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
540
|
+
subst_ = subst + Substitution.build(params, interface.args)
|
541
|
+
else
|
542
|
+
subst_ = subst
|
543
|
+
end
|
628
544
|
|
629
|
-
|
630
|
-
|
631
|
-
|
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
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
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
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
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
|
-
|
654
|
-
|
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
|
-
|
666
|
-
|
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
|
-
|
579
|
+
definition.methods.merge!(new_methods)
|
580
|
+
end
|
669
581
|
|
670
|
-
|
671
|
-
|
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
|
-
|
682
|
-
|
683
|
-
|
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
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
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
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
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
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
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
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
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
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
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
|
-
|
761
|
-
|
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:
|
685
|
+
member: original,
|
765
686
|
defined_in: definition.type_name,
|
766
687
|
implemented_in: definition.type_name
|
767
688
|
)
|
768
|
-
|
769
|
-
|
770
|
-
|
771
|
-
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
776
|
-
|
777
|
-
|
778
|
-
|
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
|
-
|
789
|
-
|
790
|
-
|
791
|
-
|
792
|
-
|
793
|
-
|
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
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
806
|
-
|
807
|
-
|
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
|
-
|
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
|
-
|
855
|
-
|
856
|
-
# @type var key: untyped
|
857
|
-
key ||= type_name
|
858
|
-
cc = _ = cache
|
736
|
+
methods[method.name] = method_definition
|
737
|
+
end
|
859
738
|
|
860
|
-
|
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.
|
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.
|
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(
|
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
|
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
|