steep 0.16.0 → 0.16.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitmodules +0 -3
- data/CHANGELOG.md +6 -0
- data/Rakefile +0 -13
- data/bin/setup +0 -2
- data/bin/smoke_runner.rb +0 -1
- data/exe/steep +0 -1
- data/lib/steep/project/file.rb +1 -1
- data/lib/steep/project/hover_content.rb +1 -1
- data/lib/steep/server/code_worker.rb +1 -1
- data/lib/steep/server/signature_worker.rb +4 -4
- data/lib/steep/type_construction.rb +10 -16
- data/lib/steep/type_inference/constant_env.rb +2 -10
- data/lib/steep/type_inference/context.rb +1 -0
- data/lib/steep/version.rb +1 -1
- data/steep.gemspec +1 -5
- metadata +17 -135
- data/exe/rbs +0 -3
- data/vendor/ruby-signature/.github/workflows/ruby.yml +0 -27
- data/vendor/ruby-signature/.gitignore +0 -12
- data/vendor/ruby-signature/.rubocop.yml +0 -15
- data/vendor/ruby-signature/BSDL +0 -22
- data/vendor/ruby-signature/COPYING +0 -56
- data/vendor/ruby-signature/Gemfile +0 -6
- data/vendor/ruby-signature/README.md +0 -93
- data/vendor/ruby-signature/Rakefile +0 -142
- data/vendor/ruby-signature/bin/annotate-with-rdoc +0 -157
- data/vendor/ruby-signature/bin/console +0 -14
- data/vendor/ruby-signature/bin/query-rdoc +0 -103
- data/vendor/ruby-signature/bin/setup +0 -10
- data/vendor/ruby-signature/bin/sort +0 -89
- data/vendor/ruby-signature/bin/test_runner.rb +0 -16
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +0 -97
- data/vendor/ruby-signature/docs/sigs.md +0 -148
- data/vendor/ruby-signature/docs/stdlib.md +0 -152
- data/vendor/ruby-signature/docs/syntax.md +0 -528
- data/vendor/ruby-signature/exe/rbs +0 -7
- data/vendor/ruby-signature/lib/rbs.rb +0 -64
- data/vendor/ruby-signature/lib/rbs/ast/annotation.rb +0 -27
- data/vendor/ruby-signature/lib/rbs/ast/comment.rb +0 -27
- data/vendor/ruby-signature/lib/rbs/ast/declarations.rb +0 -395
- data/vendor/ruby-signature/lib/rbs/ast/members.rb +0 -362
- data/vendor/ruby-signature/lib/rbs/buffer.rb +0 -50
- data/vendor/ruby-signature/lib/rbs/builtin_names.rb +0 -55
- data/vendor/ruby-signature/lib/rbs/cli.rb +0 -558
- data/vendor/ruby-signature/lib/rbs/constant.rb +0 -26
- data/vendor/ruby-signature/lib/rbs/constant_table.rb +0 -150
- data/vendor/ruby-signature/lib/rbs/definition.rb +0 -170
- data/vendor/ruby-signature/lib/rbs/definition_builder.rb +0 -919
- data/vendor/ruby-signature/lib/rbs/environment.rb +0 -281
- data/vendor/ruby-signature/lib/rbs/environment_loader.rb +0 -136
- data/vendor/ruby-signature/lib/rbs/environment_walker.rb +0 -124
- data/vendor/ruby-signature/lib/rbs/errors.rb +0 -187
- data/vendor/ruby-signature/lib/rbs/location.rb +0 -102
- data/vendor/ruby-signature/lib/rbs/method_type.rb +0 -123
- data/vendor/ruby-signature/lib/rbs/namespace.rb +0 -91
- data/vendor/ruby-signature/lib/rbs/parser.y +0 -1344
- data/vendor/ruby-signature/lib/rbs/prototype/rb.rb +0 -553
- data/vendor/ruby-signature/lib/rbs/prototype/rbi.rb +0 -587
- data/vendor/ruby-signature/lib/rbs/prototype/runtime.rb +0 -381
- data/vendor/ruby-signature/lib/rbs/substitution.rb +0 -46
- data/vendor/ruby-signature/lib/rbs/test.rb +0 -26
- data/vendor/ruby-signature/lib/rbs/test/errors.rb +0 -61
- data/vendor/ruby-signature/lib/rbs/test/hook.rb +0 -294
- data/vendor/ruby-signature/lib/rbs/test/setup.rb +0 -58
- data/vendor/ruby-signature/lib/rbs/test/spy.rb +0 -325
- data/vendor/ruby-signature/lib/rbs/test/test_helper.rb +0 -183
- data/vendor/ruby-signature/lib/rbs/test/type_check.rb +0 -254
- data/vendor/ruby-signature/lib/rbs/type_name.rb +0 -70
- data/vendor/ruby-signature/lib/rbs/types.rb +0 -936
- data/vendor/ruby-signature/lib/rbs/variance_calculator.rb +0 -138
- data/vendor/ruby-signature/lib/rbs/vendorer.rb +0 -47
- data/vendor/ruby-signature/lib/rbs/version.rb +0 -3
- data/vendor/ruby-signature/lib/rbs/writer.rb +0 -269
- data/vendor/ruby-signature/lib/ruby/signature.rb +0 -7
- data/vendor/ruby-signature/rbs.gemspec +0 -46
- data/vendor/ruby-signature/stdlib/abbrev/abbrev.rbs +0 -60
- data/vendor/ruby-signature/stdlib/base64/base64.rbs +0 -71
- data/vendor/ruby-signature/stdlib/benchmark/benchmark.rbs +0 -372
- data/vendor/ruby-signature/stdlib/builtin/array.rbs +0 -1997
- data/vendor/ruby-signature/stdlib/builtin/basic_object.rbs +0 -280
- data/vendor/ruby-signature/stdlib/builtin/binding.rbs +0 -177
- data/vendor/ruby-signature/stdlib/builtin/builtin.rbs +0 -45
- data/vendor/ruby-signature/stdlib/builtin/class.rbs +0 -145
- data/vendor/ruby-signature/stdlib/builtin/comparable.rbs +0 -116
- data/vendor/ruby-signature/stdlib/builtin/complex.rbs +0 -400
- data/vendor/ruby-signature/stdlib/builtin/constants.rbs +0 -37
- data/vendor/ruby-signature/stdlib/builtin/data.rbs +0 -5
- data/vendor/ruby-signature/stdlib/builtin/deprecated.rbs +0 -2
- data/vendor/ruby-signature/stdlib/builtin/dir.rbs +0 -413
- data/vendor/ruby-signature/stdlib/builtin/encoding.rbs +0 -607
- data/vendor/ruby-signature/stdlib/builtin/enumerable.rbs +0 -404
- data/vendor/ruby-signature/stdlib/builtin/enumerator.rbs +0 -260
- data/vendor/ruby-signature/stdlib/builtin/errno.rbs +0 -781
- data/vendor/ruby-signature/stdlib/builtin/errors.rbs +0 -582
- data/vendor/ruby-signature/stdlib/builtin/exception.rbs +0 -194
- data/vendor/ruby-signature/stdlib/builtin/false_class.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/fiber.rbs +0 -68
- data/vendor/ruby-signature/stdlib/builtin/fiber_error.rbs +0 -12
- data/vendor/ruby-signature/stdlib/builtin/file.rbs +0 -1076
- data/vendor/ruby-signature/stdlib/builtin/file_test.rbs +0 -59
- data/vendor/ruby-signature/stdlib/builtin/float.rbs +0 -696
- data/vendor/ruby-signature/stdlib/builtin/gc.rbs +0 -243
- data/vendor/ruby-signature/stdlib/builtin/hash.rbs +0 -1029
- data/vendor/ruby-signature/stdlib/builtin/integer.rbs +0 -707
- data/vendor/ruby-signature/stdlib/builtin/io.rbs +0 -683
- data/vendor/ruby-signature/stdlib/builtin/kernel.rbs +0 -576
- data/vendor/ruby-signature/stdlib/builtin/marshal.rbs +0 -161
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +0 -271
- data/vendor/ruby-signature/stdlib/builtin/math.rbs +0 -369
- data/vendor/ruby-signature/stdlib/builtin/method.rbs +0 -185
- data/vendor/ruby-signature/stdlib/builtin/module.rbs +0 -1104
- data/vendor/ruby-signature/stdlib/builtin/nil_class.rbs +0 -82
- data/vendor/ruby-signature/stdlib/builtin/numeric.rbs +0 -409
- data/vendor/ruby-signature/stdlib/builtin/object.rbs +0 -824
- data/vendor/ruby-signature/stdlib/builtin/proc.rbs +0 -429
- data/vendor/ruby-signature/stdlib/builtin/process.rbs +0 -1227
- data/vendor/ruby-signature/stdlib/builtin/random.rbs +0 -267
- data/vendor/ruby-signature/stdlib/builtin/range.rbs +0 -226
- data/vendor/ruby-signature/stdlib/builtin/rational.rbs +0 -424
- data/vendor/ruby-signature/stdlib/builtin/rb_config.rbs +0 -57
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +0 -1083
- data/vendor/ruby-signature/stdlib/builtin/ruby_vm.rbs +0 -14
- data/vendor/ruby-signature/stdlib/builtin/signal.rbs +0 -55
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +0 -1901
- data/vendor/ruby-signature/stdlib/builtin/string_io.rbs +0 -284
- data/vendor/ruby-signature/stdlib/builtin/struct.rbs +0 -40
- data/vendor/ruby-signature/stdlib/builtin/symbol.rbs +0 -228
- data/vendor/ruby-signature/stdlib/builtin/thread.rbs +0 -1108
- data/vendor/ruby-signature/stdlib/builtin/thread_group.rbs +0 -23
- data/vendor/ruby-signature/stdlib/builtin/time.rbs +0 -1047
- data/vendor/ruby-signature/stdlib/builtin/trace_point.rbs +0 -290
- data/vendor/ruby-signature/stdlib/builtin/true_class.rbs +0 -46
- data/vendor/ruby-signature/stdlib/builtin/unbound_method.rbs +0 -153
- data/vendor/ruby-signature/stdlib/builtin/warning.rbs +0 -17
- data/vendor/ruby-signature/stdlib/coverage/coverage.rbs +0 -62
- data/vendor/ruby-signature/stdlib/csv/csv.rbs +0 -773
- data/vendor/ruby-signature/stdlib/erb/erb.rbs +0 -392
- data/vendor/ruby-signature/stdlib/find/find.rbs +0 -40
- data/vendor/ruby-signature/stdlib/ipaddr/ipaddr.rbs +0 -247
- data/vendor/ruby-signature/stdlib/json/json.rbs +0 -335
- data/vendor/ruby-signature/stdlib/pathname/pathname.rbs +0 -1093
- data/vendor/ruby-signature/stdlib/prime/integer-extension.rbs +0 -23
- data/vendor/ruby-signature/stdlib/prime/prime.rbs +0 -188
- data/vendor/ruby-signature/stdlib/securerandom/securerandom.rbs +0 -9
- data/vendor/ruby-signature/stdlib/set/set.rbs +0 -301
- data/vendor/ruby-signature/stdlib/tmpdir/tmpdir.rbs +0 -53
@@ -1,381 +0,0 @@
|
|
1
|
-
module RBS
|
2
|
-
module Prototype
|
3
|
-
class Runtime
|
4
|
-
attr_reader :patterns
|
5
|
-
attr_reader :env
|
6
|
-
attr_reader :merge
|
7
|
-
attr_reader :owners_included
|
8
|
-
|
9
|
-
def initialize(patterns:, env:, merge:, owners_included: [])
|
10
|
-
@patterns = patterns
|
11
|
-
@decls = nil
|
12
|
-
@env = env
|
13
|
-
@merge = merge
|
14
|
-
@owners_included = owners_included.map do |name|
|
15
|
-
Object.const_get(name)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def target?(const)
|
20
|
-
patterns.any? do |pattern|
|
21
|
-
if pattern.end_with?("*")
|
22
|
-
(const.name || "").start_with?(pattern.chop)
|
23
|
-
else
|
24
|
-
const.name == pattern
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def builder
|
30
|
-
@builder ||= DefinitionBuilder.new(env: env)
|
31
|
-
end
|
32
|
-
|
33
|
-
def parse(file)
|
34
|
-
require file
|
35
|
-
end
|
36
|
-
|
37
|
-
def decls
|
38
|
-
unless @decls
|
39
|
-
@decls = []
|
40
|
-
ObjectSpace.each_object(Module).select {|mod| target?(mod) }.sort_by(&:name).each do |mod|
|
41
|
-
case mod
|
42
|
-
when Class
|
43
|
-
generate_class mod
|
44
|
-
when Module
|
45
|
-
generate_module mod
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
@decls
|
50
|
-
end
|
51
|
-
|
52
|
-
def to_type_name(name)
|
53
|
-
*prefix, last = name.split(/::/)
|
54
|
-
|
55
|
-
if prefix.empty?
|
56
|
-
TypeName.new(name: last.to_sym, namespace: Namespace.empty)
|
57
|
-
else
|
58
|
-
TypeName.new(name: last.to_sym, namespace: Namespace.parse(prefix.join("::")))
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def each_mixin(mixins, *super_mixes)
|
63
|
-
supers = Set.new(super_mixes)
|
64
|
-
mixins.each do |mix|
|
65
|
-
unless supers.include?(mix)
|
66
|
-
yield mix
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
def method_type(method)
|
72
|
-
untyped = Types::Bases::Any.new(location: nil)
|
73
|
-
|
74
|
-
required_positionals = []
|
75
|
-
optional_positionals = []
|
76
|
-
rest = nil
|
77
|
-
trailing_positionals = []
|
78
|
-
required_keywords = {}
|
79
|
-
optional_keywords = {}
|
80
|
-
rest_keywords = nil
|
81
|
-
|
82
|
-
requireds = required_positionals
|
83
|
-
|
84
|
-
block = nil
|
85
|
-
|
86
|
-
method.parameters.each do |kind, name|
|
87
|
-
case kind
|
88
|
-
when :req
|
89
|
-
requireds << Types::Function::Param.new(name: name, type: untyped)
|
90
|
-
when :opt
|
91
|
-
requireds = trailing_positionals
|
92
|
-
optional_positionals << Types::Function::Param.new(name: name, type: untyped)
|
93
|
-
when :rest
|
94
|
-
requireds = trailing_positionals
|
95
|
-
rest = Types::Function::Param.new(name: name, type: untyped)
|
96
|
-
when :keyreq
|
97
|
-
required_keywords[name] = Types::Function::Param.new(name: nil, type: untyped)
|
98
|
-
when :key
|
99
|
-
optional_keywords[name] = Types::Function::Param.new(name: nil, type: untyped)
|
100
|
-
when :keyrest
|
101
|
-
rest_keywords = Types::Function::Param.new(name: nil, type: untyped)
|
102
|
-
when :block
|
103
|
-
block = MethodType::Block.new(
|
104
|
-
type: Types::Function.empty(untyped).update(rest_positionals: Types::Function::Param.new(name: nil, type: untyped)),
|
105
|
-
required: true
|
106
|
-
)
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
method_type = Types::Function.new(
|
111
|
-
required_positionals: required_positionals,
|
112
|
-
optional_positionals: optional_positionals,
|
113
|
-
rest_positionals: rest,
|
114
|
-
trailing_positionals: trailing_positionals,
|
115
|
-
required_keywords: required_keywords,
|
116
|
-
optional_keywords: optional_keywords,
|
117
|
-
rest_keywords: rest_keywords,
|
118
|
-
return_type: untyped
|
119
|
-
)
|
120
|
-
|
121
|
-
MethodType.new(
|
122
|
-
location: nil,
|
123
|
-
type_params: [],
|
124
|
-
type: method_type,
|
125
|
-
block: block
|
126
|
-
)
|
127
|
-
end
|
128
|
-
|
129
|
-
def merge_rbs(module_name, members, instance: nil, singleton: nil)
|
130
|
-
if merge
|
131
|
-
if env.class?(module_name.absolute!)
|
132
|
-
case
|
133
|
-
when instance
|
134
|
-
method = builder.build_instance(module_name.absolute!).methods[instance]
|
135
|
-
method_name = instance
|
136
|
-
kind = :instance
|
137
|
-
when singleton
|
138
|
-
method = builder.build_singleton(module_name.absolute!).methods[singleton]
|
139
|
-
method_name = singleton
|
140
|
-
kind = :singleton
|
141
|
-
end
|
142
|
-
|
143
|
-
if method
|
144
|
-
members << AST::Members::MethodDefinition.new(
|
145
|
-
name: method_name,
|
146
|
-
types: method.method_types.map {|type|
|
147
|
-
type.update.tap do |ty|
|
148
|
-
def ty.to_s
|
149
|
-
location.source
|
150
|
-
end
|
151
|
-
end
|
152
|
-
},
|
153
|
-
kind: kind,
|
154
|
-
location: nil,
|
155
|
-
comment: method.comment,
|
156
|
-
annotations: method.annotations,
|
157
|
-
attributes: method.attributes
|
158
|
-
)
|
159
|
-
return
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
yield
|
164
|
-
else
|
165
|
-
yield
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
def target_method?(mod, instance: nil, singleton: nil)
|
170
|
-
case
|
171
|
-
when instance
|
172
|
-
method = mod.instance_method(instance)
|
173
|
-
method.owner == mod || owners_included.any? {|m| method.owner == m }
|
174
|
-
when singleton
|
175
|
-
method = mod.singleton_class.instance_method(singleton)
|
176
|
-
method.owner == mod.singleton_class || owners_included.any? {|m| method.owner == m.singleton_class }
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
def generate_methods(mod, module_name, members)
|
181
|
-
mod.singleton_methods.select {|name| target_method?(mod, singleton: name) }.sort.each do |name|
|
182
|
-
method = mod.singleton_class.instance_method(name)
|
183
|
-
|
184
|
-
if method.name == method.original_name
|
185
|
-
merge_rbs(module_name, members, singleton: name) do
|
186
|
-
RBS.logger.info "missing #{module_name}.#{name} #{method.source_location}"
|
187
|
-
|
188
|
-
members << AST::Members::MethodDefinition.new(
|
189
|
-
name: method.name,
|
190
|
-
types: [method_type(method)],
|
191
|
-
kind: :singleton,
|
192
|
-
location: nil,
|
193
|
-
comment: nil,
|
194
|
-
annotations: [],
|
195
|
-
attributes: []
|
196
|
-
)
|
197
|
-
end
|
198
|
-
else
|
199
|
-
members << AST::Members::Alias.new(
|
200
|
-
new_name: method.name,
|
201
|
-
old_name: method.original_name,
|
202
|
-
kind: :singleton,
|
203
|
-
location: nil,
|
204
|
-
comment: nil,
|
205
|
-
annotations: [],
|
206
|
-
)
|
207
|
-
end
|
208
|
-
end
|
209
|
-
|
210
|
-
public_instance_methods = mod.public_instance_methods.select {|name| target_method?(mod, instance: name) }
|
211
|
-
unless public_instance_methods.empty?
|
212
|
-
members << AST::Members::Public.new(location: nil)
|
213
|
-
|
214
|
-
public_instance_methods.sort.each do |name|
|
215
|
-
method = mod.instance_method(name)
|
216
|
-
|
217
|
-
if method.name == method.original_name
|
218
|
-
merge_rbs(module_name, members, instance: name) do
|
219
|
-
RBS.logger.info "missing #{module_name}##{name} #{method.source_location}"
|
220
|
-
|
221
|
-
members << AST::Members::MethodDefinition.new(
|
222
|
-
name: method.name,
|
223
|
-
types: [method_type(method)],
|
224
|
-
kind: :instance,
|
225
|
-
location: nil,
|
226
|
-
comment: nil,
|
227
|
-
annotations: [],
|
228
|
-
attributes: []
|
229
|
-
)
|
230
|
-
end
|
231
|
-
else
|
232
|
-
members << AST::Members::Alias.new(
|
233
|
-
new_name: method.name,
|
234
|
-
old_name: method.original_name,
|
235
|
-
kind: :instance,
|
236
|
-
location: nil,
|
237
|
-
comment: nil,
|
238
|
-
annotations: [],
|
239
|
-
)
|
240
|
-
end
|
241
|
-
end
|
242
|
-
end
|
243
|
-
|
244
|
-
private_instance_methods = mod.private_instance_methods.select {|name| target_method?(mod, instance: name) }
|
245
|
-
unless private_instance_methods.empty?
|
246
|
-
members << AST::Members::Private.new(location: nil)
|
247
|
-
|
248
|
-
private_instance_methods.sort.each do |name|
|
249
|
-
method = mod.instance_method(name)
|
250
|
-
|
251
|
-
if method.name == method.original_name
|
252
|
-
merge_rbs(module_name, members, instance: name) do
|
253
|
-
RBS.logger.info "missing #{module_name}##{name} #{method.source_location}"
|
254
|
-
|
255
|
-
members << AST::Members::MethodDefinition.new(
|
256
|
-
name: method.name,
|
257
|
-
types: [method_type(method)],
|
258
|
-
kind: :instance,
|
259
|
-
location: nil,
|
260
|
-
comment: nil,
|
261
|
-
annotations: [],
|
262
|
-
attributes: []
|
263
|
-
)
|
264
|
-
end
|
265
|
-
else
|
266
|
-
members << AST::Members::Alias.new(
|
267
|
-
new_name: method.name,
|
268
|
-
old_name: method.original_name,
|
269
|
-
kind: :instance,
|
270
|
-
location: nil,
|
271
|
-
comment: nil,
|
272
|
-
annotations: [],
|
273
|
-
)
|
274
|
-
end
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
|
279
|
-
def generate_constants(mod)
|
280
|
-
mod.constants(false).sort.each do |name|
|
281
|
-
value = mod.const_get(name)
|
282
|
-
|
283
|
-
next if value.is_a?(Class) || value.is_a?(Module)
|
284
|
-
type = case value
|
285
|
-
when true, false
|
286
|
-
Types::Bases::Bool.new(location: nil)
|
287
|
-
when nil
|
288
|
-
Types::Optional.new(
|
289
|
-
type: Types::Bases::Any.new(location: nil),
|
290
|
-
location: nil
|
291
|
-
)
|
292
|
-
else
|
293
|
-
Types::ClassInstance.new(name: to_type_name(value.class.to_s), args: [], location: nil)
|
294
|
-
end
|
295
|
-
|
296
|
-
@decls << AST::Declarations::Constant.new(
|
297
|
-
name: "#{mod.to_s}::#{name}",
|
298
|
-
type: type,
|
299
|
-
location: nil,
|
300
|
-
comment: nil
|
301
|
-
)
|
302
|
-
end
|
303
|
-
end
|
304
|
-
|
305
|
-
def generate_class(mod)
|
306
|
-
type_name = to_type_name(mod.name)
|
307
|
-
super_class = if mod.superclass == ::Object
|
308
|
-
nil
|
309
|
-
else
|
310
|
-
AST::Declarations::Class::Super.new(name: to_type_name(mod.superclass.name), args: [])
|
311
|
-
end
|
312
|
-
|
313
|
-
decl = AST::Declarations::Class.new(
|
314
|
-
name: type_name,
|
315
|
-
type_params: AST::Declarations::ModuleTypeParams.empty,
|
316
|
-
super_class: super_class,
|
317
|
-
members: [],
|
318
|
-
annotations: [],
|
319
|
-
location: nil,
|
320
|
-
comment: nil
|
321
|
-
)
|
322
|
-
|
323
|
-
each_mixin(mod.included_modules, *mod.superclass.included_modules, *mod.included_modules.flat_map(&:included_modules)) do |included_module|
|
324
|
-
module_name = to_type_name(included_module.name)
|
325
|
-
if module_name.namespace == type_name.namespace
|
326
|
-
module_name = TypeName.new(name: module_name.name, namespace: Namespace.empty)
|
327
|
-
end
|
328
|
-
|
329
|
-
decl.members << AST::Members::Include.new(
|
330
|
-
name: module_name,
|
331
|
-
args: [],
|
332
|
-
location: nil,
|
333
|
-
comment: nil,
|
334
|
-
annotations: []
|
335
|
-
)
|
336
|
-
end
|
337
|
-
|
338
|
-
generate_methods(mod, type_name, decl.members)
|
339
|
-
|
340
|
-
@decls << decl
|
341
|
-
|
342
|
-
generate_constants mod
|
343
|
-
end
|
344
|
-
|
345
|
-
def generate_module(mod)
|
346
|
-
type_name = to_type_name(mod.name)
|
347
|
-
|
348
|
-
decl = AST::Declarations::Module.new(
|
349
|
-
name: type_name,
|
350
|
-
type_params: AST::Declarations::ModuleTypeParams.empty,
|
351
|
-
self_type: nil,
|
352
|
-
members: [],
|
353
|
-
annotations: [],
|
354
|
-
location: nil,
|
355
|
-
comment: nil
|
356
|
-
)
|
357
|
-
|
358
|
-
each_mixin(mod.included_modules, *mod.included_modules.flat_map(&:included_modules), namespace: type_name.namespace) do |included_module|
|
359
|
-
module_name = to_type_name(included_module.name)
|
360
|
-
if module_name.namespace == type_name.namespace
|
361
|
-
module_name = TypeName.new(name: module_name.name, namespace: Namespace.empty)
|
362
|
-
end
|
363
|
-
|
364
|
-
decl.members << AST::Members::Include.new(
|
365
|
-
name: module_name,
|
366
|
-
args: [],
|
367
|
-
location: nil,
|
368
|
-
comment: nil,
|
369
|
-
annotations: []
|
370
|
-
)
|
371
|
-
end
|
372
|
-
|
373
|
-
generate_methods(mod, type_name, decl.members)
|
374
|
-
|
375
|
-
@decls << decl
|
376
|
-
|
377
|
-
generate_constants mod
|
378
|
-
end
|
379
|
-
end
|
380
|
-
end
|
381
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
module RBS
|
2
|
-
class Substitution
|
3
|
-
attr_reader :mapping
|
4
|
-
|
5
|
-
def initialize()
|
6
|
-
@mapping = {}
|
7
|
-
end
|
8
|
-
|
9
|
-
def add(from:, to:)
|
10
|
-
mapping[from] = to
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.build(variables, types, &block)
|
14
|
-
unless variables.size == types.size
|
15
|
-
raise "Broken substitution: variables=#{variables}, types=#{types}"
|
16
|
-
end
|
17
|
-
|
18
|
-
mapping = variables.zip(types).to_h
|
19
|
-
|
20
|
-
self.new.tap do |subst|
|
21
|
-
mapping.each do |v, t|
|
22
|
-
type = block_given? ? yield(t) : t
|
23
|
-
subst.add(from: v, to: type)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def apply(ty)
|
29
|
-
case ty
|
30
|
-
when Types::Variable
|
31
|
-
mapping[ty.name] || ty
|
32
|
-
else
|
33
|
-
ty
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def without(*vars)
|
38
|
-
self.class.new.tap do |subst|
|
39
|
-
subst.mapping.merge!(mapping)
|
40
|
-
vars.each do |var|
|
41
|
-
subst.mapping.delete(var)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
require "rbs/test/spy"
|
2
|
-
require "rbs/test/errors"
|
3
|
-
require "rbs/test/type_check"
|
4
|
-
require "rbs/test/hook"
|
5
|
-
|
6
|
-
module RBS
|
7
|
-
module Test
|
8
|
-
IS_AP = Kernel.instance_method(:is_a?)
|
9
|
-
DEFINE_METHOD = Module.instance_method(:define_method)
|
10
|
-
INSTANCE_EVAL = BasicObject.instance_method(:instance_eval)
|
11
|
-
INSTANCE_EXEC = BasicObject.instance_method(:instance_exec)
|
12
|
-
METHOD = Kernel.instance_method(:method)
|
13
|
-
CLASS = Kernel.instance_method(:class)
|
14
|
-
SINGLETON_CLASS = Kernel.instance_method(:singleton_class)
|
15
|
-
PP = Kernel.instance_method(:pp)
|
16
|
-
INSPECT = Kernel.instance_method(:inspect)
|
17
|
-
METHODS = Kernel.instance_method(:methods)
|
18
|
-
|
19
|
-
ArgumentsReturn = Struct.new(:arguments, :return_value, :exception, keyword_init: true)
|
20
|
-
CallTrace = Struct.new(:method_name, :method_call, :block_calls, :block_given, keyword_init: true)
|
21
|
-
|
22
|
-
def self.call(receiver, method, *args, **kwargs, &block)
|
23
|
-
method.bind_call(receiver, *args, **kwargs, &block)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|