rbs 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/Rakefile +9 -4
- data/Steepfile +28 -0
- data/bin/steep +4 -0
- data/bin/test_runner.rb +10 -5
- data/lib/rbs/ast/comment.rb +7 -1
- data/lib/rbs/ast/declarations.rb +15 -9
- data/lib/rbs/buffer.rb +1 -1
- data/lib/rbs/definition.rb +22 -13
- data/lib/rbs/definition_builder.rb +79 -55
- data/lib/rbs/environment.rb +24 -10
- data/lib/rbs/location.rb +1 -5
- data/lib/rbs/method_type.rb +5 -5
- data/lib/rbs/namespace.rb +14 -3
- data/lib/rbs/parser.y +0 -8
- data/lib/rbs/prototype/rb.rb +3 -4
- data/lib/rbs/prototype/rbi.rb +1 -2
- data/lib/rbs/substitution.rb +4 -3
- data/lib/rbs/type_name.rb +18 -1
- data/lib/rbs/type_name_resolver.rb +10 -3
- data/lib/rbs/types.rb +27 -21
- data/lib/rbs/variance_calculator.rb +8 -5
- data/lib/rbs/version.rb +1 -1
- data/sig/annotation.rbs +26 -0
- data/sig/buffer.rbs +28 -0
- data/sig/builtin_names.rbs +41 -0
- data/sig/comment.rbs +26 -0
- data/sig/declarations.rbs +202 -0
- data/sig/definition.rbs +129 -0
- data/sig/definition_builder.rbs +95 -0
- data/sig/environment.rbs +94 -0
- data/sig/environment_loader.rbs +4 -0
- data/sig/location.rbs +52 -0
- data/sig/members.rbs +160 -0
- data/sig/method_types.rbs +40 -0
- data/sig/namespace.rbs +124 -0
- data/sig/polyfill.rbs +3 -0
- data/sig/rbs.rbs +3 -0
- data/sig/substitution.rbs +39 -0
- data/sig/type_name_resolver.rbs +24 -0
- data/sig/typename.rbs +70 -0
- data/sig/types.rbs +361 -0
- data/sig/util.rbs +13 -0
- data/sig/variance_calculator.rbs +35 -0
- data/stdlib/bigdecimal/big_decimal.rbs +887 -0
- data/stdlib/bigdecimal/math/big_math.rbs +142 -0
- data/stdlib/builtin/builtin.rbs +0 -3
- data/stdlib/builtin/math.rbs +26 -26
- data/stdlib/builtin/struct.rbs +9 -10
- data/stdlib/forwardable/forwardable.rbs +204 -0
- data/stdlib/set/set.rbs +1 -1
- data/stdlib/uri/file.rbs +167 -0
- data/stdlib/uri/generic.rbs +875 -0
- data/steep/Gemfile +3 -0
- data/steep/Gemfile.lock +55 -0
- metadata +36 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db07b9abb1ed59e789d6a13145e33503f20e37a908826c3c8ba8222f9cf79ec6
|
4
|
+
data.tar.gz: a42440c8542489fd70f24139f24e718b106caa99925a437857867141f730ed9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 606289f49ac2d2934808add204997b7828708b05f2b3d60c10f8de6106cbca06527fd628de445511dfa537976fab551e878a45b5ab03ac41374cf242f90b6244
|
7
|
+
data.tar.gz: 5de0b5b93fd872a69fe25d62eaf72fba3fc4d93b57f04f5da311fc66d3b6eeebe53fb654cea4361da32124861ac21c1ad9547bf9e7c0012b6db704e98164a8d9
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,11 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 0.12.0 (2020-09-15)
|
6
|
+
|
7
|
+
* Signature updates for `forwardable`, `struct`, `set`, `URI::Generic`, `URI::File`, and `BigDecimal`.
|
8
|
+
* Define `.new` methods from `initialize` included from modules [#390](https://github.com/ruby/rbs/pull/390)
|
9
|
+
|
5
10
|
## 0.11.0 (2020-08-31)
|
6
11
|
|
7
12
|
* Signature update for `date/datetime` [#367](https://github.com/ruby/rbs/pull/367)
|
data/Rakefile
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
2
|
require "rake/testtask"
|
3
|
+
require "rbconfig"
|
4
|
+
|
5
|
+
ruby = ENV["RUBY"] || RbConfig.ruby
|
6
|
+
rbs = File.join(__dir__, "exe/rbs")
|
7
|
+
bin = File.join(__dir__, "bin")
|
3
8
|
|
4
9
|
Rake::TestTask.new(:test) do |t|
|
5
10
|
t.libs << "test"
|
@@ -16,21 +21,21 @@ task :test_doc => :parser do
|
|
16
21
|
`git ls-files -z`.split("\x0").select do |file| Pathname(file).extname == ".md" end
|
17
22
|
end
|
18
23
|
|
19
|
-
sh "ruby bin/run_in_md.rb #{files.join(" ")}"
|
24
|
+
sh "#{ruby} #{__dir__}/bin/run_in_md.rb #{files.join(" ")}"
|
20
25
|
end
|
21
26
|
|
22
27
|
task :validate => :parser do
|
23
|
-
sh "rbs validate"
|
28
|
+
sh "#{ruby} #{rbs} validate"
|
24
29
|
|
25
30
|
FileList["stdlib/*"].each do |path|
|
26
31
|
next if path =~ %r{stdlib/builtin}
|
27
|
-
sh "rbs -r#{File.basename(path)} validate"
|
32
|
+
sh "#{ruby} #{rbs} -r#{File.basename(path)} validate"
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
31
36
|
FileList["test/stdlib/**/*_test.rb"].each do |test|
|
32
37
|
multitask test => :parser do
|
33
|
-
sh "ruby bin/test_runner.rb #{test}"
|
38
|
+
sh "#{ruby} -Ilib #{bin}/test_runner.rb #{test}"
|
34
39
|
end
|
35
40
|
multitask stdlib_test: test
|
36
41
|
end
|
data/Steepfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
target :lib do
|
2
|
+
signature "sig"
|
3
|
+
check "lib"
|
4
|
+
|
5
|
+
vendor stdlib: "stdlib"
|
6
|
+
library "set", "pathname", "json", "logger"
|
7
|
+
end
|
8
|
+
|
9
|
+
# target :lib do
|
10
|
+
# signature "sig"
|
11
|
+
#
|
12
|
+
# check "lib" # Directory name
|
13
|
+
# check "Gemfile" # File name
|
14
|
+
# check "app/models/**/*.rb" # Glob
|
15
|
+
# # ignore "lib/templates/*.rb"
|
16
|
+
#
|
17
|
+
# # library "pathname", "set" # Standard libraries
|
18
|
+
# # library "strong_json" # Gems
|
19
|
+
# end
|
20
|
+
|
21
|
+
# target :spec do
|
22
|
+
# signature "sig", "sig-private"
|
23
|
+
#
|
24
|
+
# check "spec"
|
25
|
+
#
|
26
|
+
# # library "pathname", "set" # Standard libraries
|
27
|
+
# # library "rspec"
|
28
|
+
# end
|
data/bin/steep
ADDED
data/bin/test_runner.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
3
|
+
$LOAD_PATH << File.join(__dir__, "../lib")
|
4
|
+
|
5
|
+
STDLIB_TEST = Gem::Version.new(RUBY_VERSION).yield_self do |ruby_version|
|
6
|
+
Gem::Version.new('2.7.0') <= ruby_version &&
|
7
|
+
ruby_version <= Gem::Version.new('2.8.0')
|
5
8
|
end
|
6
9
|
|
7
|
-
unless
|
8
|
-
|
9
|
-
|
10
|
+
unless STDLIB_TEST
|
11
|
+
unless ENV["FORCE_STDLIB_TEST"]
|
12
|
+
STDERR.puts "🚨🚨🚨 stdlib test requires Ruby 2.7 or later but RUBY_VERSION==#{RUBY_VERSION}, exiting... 🚨🚨🚨"
|
13
|
+
exit
|
14
|
+
end
|
10
15
|
end
|
11
16
|
|
12
17
|
ARGV.each do |arg|
|
data/lib/rbs/ast/comment.rb
CHANGED
data/lib/rbs/ast/declarations.rb
CHANGED
@@ -7,7 +7,7 @@ module RBS
|
|
7
7
|
class ModuleTypeParams
|
8
8
|
attr_reader :params
|
9
9
|
|
10
|
-
TypeParam = Struct.new(:name, :variance, :skip_validation, keyword_init: true) do
|
10
|
+
TypeParam = _ = Struct.new(:name, :variance, :skip_validation, keyword_init: true) do
|
11
11
|
def to_json(*a)
|
12
12
|
{
|
13
13
|
name: name,
|
@@ -47,7 +47,11 @@ module RBS
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def each(&block)
|
50
|
-
|
50
|
+
if block
|
51
|
+
params.each(&block)
|
52
|
+
else
|
53
|
+
params.each
|
54
|
+
end
|
51
55
|
end
|
52
56
|
|
53
57
|
def self.empty
|
@@ -55,11 +59,13 @@ module RBS
|
|
55
59
|
end
|
56
60
|
|
57
61
|
def variance(name)
|
58
|
-
self[name]
|
62
|
+
var = self[name] or raise
|
63
|
+
var.variance
|
59
64
|
end
|
60
65
|
|
61
66
|
def skip_validation?(name)
|
62
|
-
self[name]
|
67
|
+
var = self[name] or raise
|
68
|
+
var.skip_validation
|
63
69
|
end
|
64
70
|
|
65
71
|
def empty?
|
@@ -85,7 +91,7 @@ module RBS
|
|
85
91
|
if block_given?
|
86
92
|
members.each do |member|
|
87
93
|
if member.is_a?(Members::Base)
|
88
|
-
yield member
|
94
|
+
yield(_ = member)
|
89
95
|
end
|
90
96
|
end
|
91
97
|
else
|
@@ -96,8 +102,8 @@ module RBS
|
|
96
102
|
def each_decl
|
97
103
|
if block_given?
|
98
104
|
members.each do |member|
|
99
|
-
if member.is_a?(
|
100
|
-
yield member
|
105
|
+
if member.is_a?(Base)
|
106
|
+
yield(_ = member)
|
101
107
|
end
|
102
108
|
end
|
103
109
|
else
|
@@ -108,9 +114,9 @@ module RBS
|
|
108
114
|
|
109
115
|
module MixinHelper
|
110
116
|
def each_mixin(&block)
|
111
|
-
if
|
117
|
+
if block
|
112
118
|
@mixins ||= begin
|
113
|
-
members.select do |member|
|
119
|
+
_ = members.select do |member|
|
114
120
|
case member
|
115
121
|
when Members::Include, Members::Extend, Members::Prepend
|
116
122
|
true
|
data/lib/rbs/buffer.rb
CHANGED
data/lib/rbs/definition.rb
CHANGED
@@ -47,9 +47,9 @@ module RBS
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def overload?
|
50
|
-
case member
|
50
|
+
case mem = member
|
51
51
|
when AST::Members::MethodDefinition
|
52
|
-
|
52
|
+
mem.overload?
|
53
53
|
else
|
54
54
|
false
|
55
55
|
end
|
@@ -69,11 +69,17 @@ module RBS
|
|
69
69
|
end
|
70
70
|
|
71
71
|
def defined_in
|
72
|
-
@defined_in ||=
|
72
|
+
@defined_in ||= begin
|
73
|
+
last_def = defs.last or raise
|
74
|
+
last_def.defined_in
|
75
|
+
end
|
73
76
|
end
|
74
77
|
|
75
78
|
def implemented_in
|
76
|
-
@implemented_in ||=
|
79
|
+
@implemented_in ||= begin
|
80
|
+
last_def = defs.last or raise
|
81
|
+
last_def.implemented_in
|
82
|
+
end
|
77
83
|
end
|
78
84
|
|
79
85
|
def method_types
|
@@ -81,7 +87,7 @@ module RBS
|
|
81
87
|
end
|
82
88
|
|
83
89
|
def comments
|
84
|
-
@comments ||= defs.map(&:comment).compact
|
90
|
+
@comments ||= _ = defs.map(&:comment).compact
|
85
91
|
end
|
86
92
|
|
87
93
|
def annotations
|
@@ -126,8 +132,8 @@ module RBS
|
|
126
132
|
end
|
127
133
|
|
128
134
|
module Ancestor
|
129
|
-
Instance = Struct.new(:name, :args, keyword_init: true)
|
130
|
-
Singleton = Struct.new(:name, keyword_init: true)
|
135
|
+
Instance = _ = Struct.new(:name, :args, keyword_init: true)
|
136
|
+
Singleton = _ = Struct.new(:name, keyword_init: true)
|
131
137
|
end
|
132
138
|
|
133
139
|
class InstanceAncestors
|
@@ -219,7 +225,10 @@ module RBS
|
|
219
225
|
end
|
220
226
|
|
221
227
|
def interface?
|
222
|
-
|
228
|
+
case en = entry
|
229
|
+
when Environment::SingleEntry
|
230
|
+
en.decl.is_a?(AST::Declarations::Interface)
|
231
|
+
end
|
223
232
|
end
|
224
233
|
|
225
234
|
def class_type?
|
@@ -239,16 +248,16 @@ module RBS
|
|
239
248
|
end
|
240
249
|
|
241
250
|
def type_params_decl
|
242
|
-
case entry
|
251
|
+
case en = entry
|
243
252
|
when Environment::ClassEntry, Environment::ModuleEntry
|
244
|
-
|
253
|
+
en.type_params
|
245
254
|
when Environment::SingleEntry
|
246
|
-
|
255
|
+
en.decl.type_params
|
247
256
|
end
|
248
257
|
end
|
249
258
|
|
250
259
|
def sub(s)
|
251
|
-
definition = self.class.new(type_name: type_name, self_type: self_type.sub(s), ancestors: ancestors, entry: entry)
|
260
|
+
definition = self.class.new(type_name: type_name, self_type: _ = self_type.sub(s), ancestors: ancestors, entry: entry)
|
252
261
|
|
253
262
|
definition.methods.merge!(methods.transform_values {|method| method.sub(s) })
|
254
263
|
definition.instance_variables.merge!(instance_variables.transform_values {|v| v.sub(s) })
|
@@ -268,7 +277,7 @@ module RBS
|
|
268
277
|
end
|
269
278
|
|
270
279
|
def each_type(&block)
|
271
|
-
if
|
280
|
+
if block
|
272
281
|
methods.each_value do |method|
|
273
282
|
if method.defined_in == type_name
|
274
283
|
method.method_types.each do |method_type|
|
@@ -36,8 +36,11 @@ module RBS
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def each_ancestor(&block)
|
39
|
-
if
|
40
|
-
|
39
|
+
if block
|
40
|
+
if s = super_class
|
41
|
+
yield s
|
42
|
+
end
|
43
|
+
|
41
44
|
self_types&.each(&block)
|
42
45
|
included_modules&.each(&block)
|
43
46
|
prepended_modules&.each(&block)
|
@@ -108,7 +111,7 @@ module RBS
|
|
108
111
|
return if with_super_classes.size <= 1
|
109
112
|
|
110
113
|
super_types = with_super_classes.map do |d|
|
111
|
-
super_class = d.decl.super_class
|
114
|
+
super_class = d.decl.super_class or raise
|
112
115
|
Types::ClassInstance.new(name: super_class.name, args: super_class.args, location: nil)
|
113
116
|
end
|
114
117
|
|
@@ -159,10 +162,10 @@ module RBS
|
|
159
162
|
|
160
163
|
entry.self_types.each do |module_self|
|
161
164
|
NoSelfTypeFoundError.check!(module_self, env: env)
|
162
|
-
|
165
|
+
|
166
|
+
self_types = ancestors.self_types or raise
|
167
|
+
self_types.push Definition::Ancestor::Instance.new(name: module_self.name, args: module_self.args)
|
163
168
|
end
|
164
|
-
else
|
165
|
-
raise "Unexpected entry for: #{type_name}"
|
166
169
|
end
|
167
170
|
|
168
171
|
mixin_ancestors(entry,
|
@@ -208,9 +211,6 @@ module RBS
|
|
208
211
|
type_name: type_name,
|
209
212
|
super_class: Definition::Ancestor::Instance.new(name: BuiltinNames::Module.name, args: [])
|
210
213
|
)
|
211
|
-
|
212
|
-
else
|
213
|
-
raise "Unexpected entry for: #{type_name}"
|
214
214
|
end
|
215
215
|
|
216
216
|
mixin_ancestors(entry,
|
@@ -285,33 +285,38 @@ module RBS
|
|
285
285
|
|
286
286
|
case entry
|
287
287
|
when Environment::ClassEntry
|
288
|
-
if one_ancestors.super_class
|
289
|
-
|
290
|
-
|
288
|
+
if super_class = one_ancestors.super_class
|
289
|
+
# @type var super_class: Definition::Ancestor::Instance
|
290
|
+
super_name = super_class.name
|
291
|
+
super_args = super_class.args
|
291
292
|
|
292
293
|
super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors)
|
293
294
|
ancestors.unshift(*super_ancestors.apply(super_args, location: entry.primary.decl.location))
|
294
295
|
end
|
295
296
|
end
|
296
297
|
|
297
|
-
one_ancestors.included_modules
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
298
|
+
if included_modules = one_ancestors.included_modules
|
299
|
+
included_modules.each do |mod|
|
300
|
+
if mod.name.class?
|
301
|
+
name = mod.name
|
302
|
+
arg_types = mod.args
|
303
|
+
mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
|
304
|
+
ancestors.unshift(*mod_ancestors.apply(arg_types, location: entry.primary.decl.location))
|
305
|
+
end
|
306
|
+
end
|
304
307
|
end
|
305
308
|
|
306
309
|
ancestors.unshift(self_ancestor)
|
307
310
|
|
308
|
-
one_ancestors.prepended_modules
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
311
|
+
if prepended_modules = one_ancestors.prepended_modules
|
312
|
+
prepended_modules.each do |mod|
|
313
|
+
if mod.name.class?
|
314
|
+
name = mod.name
|
315
|
+
arg_types = mod.args
|
316
|
+
mod_ancestors = instance_ancestors(name, building_ancestors: building_ancestors)
|
317
|
+
ancestors.unshift(*mod_ancestors.apply(arg_types, location: entry.primary.decl.location))
|
318
|
+
end
|
319
|
+
end
|
315
320
|
end
|
316
321
|
|
317
322
|
building_ancestors.pop
|
@@ -338,22 +343,23 @@ module RBS
|
|
338
343
|
|
339
344
|
ancestors = []
|
340
345
|
|
341
|
-
case one_ancestors.super_class
|
346
|
+
case super_class = one_ancestors.super_class
|
342
347
|
when Definition::Ancestor::Instance
|
343
|
-
super_name =
|
344
|
-
super_args =
|
348
|
+
super_name = super_class.name
|
349
|
+
super_args = super_class.args
|
345
350
|
|
346
351
|
super_ancestors = instance_ancestors(super_name, building_ancestors: building_ancestors)
|
347
352
|
ancestors.unshift(*super_ancestors.apply(super_args, location: entry.primary.decl.location))
|
348
353
|
|
349
354
|
when Definition::Ancestor::Singleton
|
350
|
-
super_name =
|
355
|
+
super_name = super_class.name
|
351
356
|
|
352
357
|
super_ancestors = singleton_ancestors(super_name, building_ancestors: [])
|
353
358
|
ancestors.unshift(*super_ancestors.ancestors)
|
354
359
|
end
|
355
360
|
|
356
|
-
one_ancestors.extended_modules
|
361
|
+
extended_modules = one_ancestors.extended_modules or raise
|
362
|
+
extended_modules.each do |mod|
|
357
363
|
if mod.name.class?
|
358
364
|
name = mod.name
|
359
365
|
args = mod.args
|
@@ -406,17 +412,17 @@ module RBS
|
|
406
412
|
location: nil)
|
407
413
|
|
408
414
|
definition_pairs = ancestors.ancestors.map do |ancestor|
|
415
|
+
# @type block: [Definition::Ancestor::t, Definition]
|
409
416
|
case ancestor
|
410
417
|
when Definition::Ancestor::Instance
|
411
418
|
[ancestor, build_one_instance(ancestor.name)]
|
412
419
|
when Definition::Ancestor::Singleton
|
413
420
|
[ancestor, build_one_singleton(ancestor.name)]
|
414
|
-
else
|
415
|
-
raise
|
416
421
|
end
|
417
422
|
end
|
418
423
|
|
419
|
-
|
424
|
+
case entry
|
425
|
+
when Environment::ModuleEntry
|
420
426
|
entry.self_types.each do |module_self|
|
421
427
|
ancestor = Definition::Ancestor::Instance.new(name: module_self.name, args: module_self.args)
|
422
428
|
definition_pairs.push(
|
@@ -433,9 +439,6 @@ module RBS
|
|
433
439
|
end
|
434
440
|
|
435
441
|
merge_definitions(type_name, definition_pairs, entry: entry, self_type: self_type, ancestors: ancestors)
|
436
|
-
|
437
|
-
else
|
438
|
-
raise
|
439
442
|
end
|
440
443
|
end
|
441
444
|
end
|
@@ -456,6 +459,7 @@ module RBS
|
|
456
459
|
)
|
457
460
|
|
458
461
|
definition_pairs = ancestors.ancestors.map do |ancestor|
|
462
|
+
# @type block: [Definition::Ancestor::t, Definition]
|
459
463
|
case ancestor
|
460
464
|
when Definition::Ancestor::Instance
|
461
465
|
[ancestor, build_one_instance(ancestor.name)]
|
@@ -474,20 +478,18 @@ module RBS
|
|
474
478
|
ancestor,
|
475
479
|
definition
|
476
480
|
]
|
477
|
-
else
|
478
|
-
raise
|
479
481
|
end
|
480
482
|
end
|
481
483
|
|
482
484
|
merge_definitions(type_name, definition_pairs, entry: entry, self_type: self_type, ancestors: ancestors)
|
483
|
-
else
|
484
|
-
raise
|
485
485
|
end
|
486
486
|
end
|
487
487
|
end
|
488
488
|
|
489
489
|
def method_definition_members(type_name, entry, kind:)
|
490
|
+
# @type var interface_methods: Hash[Symbol, [Definition::Method, AST::Members::t]]
|
490
491
|
interface_methods = {}
|
492
|
+
# @type var methods: Hash[Symbol, Array[[AST::Members::MethodDefinition, Definition::accessibility]]]
|
491
493
|
methods = {}
|
492
494
|
|
493
495
|
entry.decls.each do |d|
|
@@ -534,11 +536,14 @@ module RBS
|
|
534
536
|
end
|
535
537
|
end
|
536
538
|
|
539
|
+
# @type var result: Hash[Symbol, member_detail]
|
537
540
|
result = {}
|
538
541
|
|
539
542
|
interface_methods.each do |name, pair|
|
540
543
|
method_definition, _ = pair
|
541
|
-
|
544
|
+
# @type var detail: member_detail
|
545
|
+
detail = [:public, method_definition, nil, []]
|
546
|
+
result[name] = detail
|
542
547
|
end
|
543
548
|
|
544
549
|
methods.each do |method_name, array|
|
@@ -562,12 +567,12 @@ module RBS
|
|
562
567
|
)
|
563
568
|
end
|
564
569
|
|
565
|
-
result[method_name]
|
570
|
+
result[method_name][3].push(*array.map(&:first))
|
566
571
|
else
|
567
572
|
case
|
568
573
|
when array.size == 1 && !array[0][0].overload?
|
569
574
|
member, visibility = array[0]
|
570
|
-
result[method_name] = [visibility, nil, member]
|
575
|
+
result[method_name] = [visibility, nil, member, []]
|
571
576
|
|
572
577
|
else
|
573
578
|
visibilities = array.group_by {|pair| pair[1] }
|
@@ -582,7 +587,7 @@ module RBS
|
|
582
587
|
end
|
583
588
|
|
584
589
|
overloads, primary = array.map(&:first).partition(&:overload?)
|
585
|
-
result[method_name] = [array[0][1], nil,
|
590
|
+
result[method_name] = [array[0][1], nil, primary[0], overloads]
|
586
591
|
end
|
587
592
|
end
|
588
593
|
end
|
@@ -601,7 +606,13 @@ module RBS
|
|
601
606
|
|
602
607
|
Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
|
603
608
|
method_definition_members(type_name, entry, kind: :instance).each do |method_name, array|
|
604
|
-
visibility, method_def,
|
609
|
+
visibility, method_def, primary_member, overload_members = array
|
610
|
+
|
611
|
+
members = if primary_member
|
612
|
+
[primary_member, *overload_members]
|
613
|
+
else
|
614
|
+
overload_members
|
615
|
+
end
|
605
616
|
|
606
617
|
m = if method_def
|
607
618
|
Definition::Method.new(
|
@@ -770,9 +781,9 @@ module RBS
|
|
770
781
|
|
771
782
|
errors = []
|
772
783
|
|
773
|
-
|
774
|
-
|
775
|
-
|
784
|
+
case decl
|
785
|
+
when AST::Declarations::Class
|
786
|
+
if super_class = decl.super_class
|
776
787
|
result = calculator.in_inherit(name: super_class.name, args: super_class.args, variables: param_names)
|
777
788
|
|
778
789
|
validate_params_with type_params, result: result do |param|
|
@@ -783,6 +794,8 @@ module RBS
|
|
783
794
|
end
|
784
795
|
end
|
785
796
|
|
797
|
+
# @type var result: VarianceCalculator::Result
|
798
|
+
|
786
799
|
decl.members.each do |member|
|
787
800
|
case member
|
788
801
|
when AST::Members::Include
|
@@ -830,7 +843,13 @@ module RBS
|
|
830
843
|
|
831
844
|
Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
|
832
845
|
method_definition_members(type_name, entry, kind: :singleton).each do |method_name, array|
|
833
|
-
visibility, method_def,
|
846
|
+
visibility, method_def, primary_member, overload_members = array
|
847
|
+
|
848
|
+
members = if primary_member
|
849
|
+
[primary_member, *overload_members]
|
850
|
+
else
|
851
|
+
overload_members
|
852
|
+
end
|
834
853
|
|
835
854
|
m = Definition::Method.new(
|
836
855
|
super_method: nil,
|
@@ -882,7 +901,7 @@ module RBS
|
|
882
901
|
end
|
883
902
|
|
884
903
|
unless definition.methods.key?(:new)
|
885
|
-
instance =
|
904
|
+
instance = build_instance(type_name)
|
886
905
|
initialize = instance.methods[:initialize]
|
887
906
|
|
888
907
|
if initialize
|
@@ -957,7 +976,7 @@ module RBS
|
|
957
976
|
|
958
977
|
def merge_definitions(type_name, pairs, entry:, self_type:, ancestors:)
|
959
978
|
Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
|
960
|
-
pairs.reverse_each do |
|
979
|
+
pairs.reverse_each do |ancestor, current_definition|
|
961
980
|
sub = case ancestor
|
962
981
|
when Definition::Ancestor::Instance
|
963
982
|
Substitution.build(current_definition.type_params, ancestor.args)
|
@@ -965,6 +984,7 @@ module RBS
|
|
965
984
|
Substitution.build([], [])
|
966
985
|
end
|
967
986
|
|
987
|
+
# @type var kind: method_kind
|
968
988
|
kind = case ancestor
|
969
989
|
when Definition::Ancestor::Instance
|
970
990
|
:instance
|
@@ -1015,7 +1035,7 @@ module RBS
|
|
1015
1035
|
end
|
1016
1036
|
|
1017
1037
|
def try_cache(type_name, cache:)
|
1018
|
-
cached = cache[type_name]
|
1038
|
+
cached = _ = cache[type_name]
|
1019
1039
|
|
1020
1040
|
case cached
|
1021
1041
|
when Definition
|
@@ -1027,9 +1047,11 @@ module RBS
|
|
1027
1047
|
begin
|
1028
1048
|
cache[type_name] = yield
|
1029
1049
|
rescue => ex
|
1030
|
-
cache
|
1050
|
+
cache.delete(type_name)
|
1031
1051
|
raise ex
|
1032
1052
|
end
|
1053
|
+
else
|
1054
|
+
raise
|
1033
1055
|
end
|
1034
1056
|
end
|
1035
1057
|
|
@@ -1067,7 +1089,9 @@ module RBS
|
|
1067
1089
|
mixin = build_interface(member.name)
|
1068
1090
|
|
1069
1091
|
args = member.args
|
1070
|
-
|
1092
|
+
# @type var interface_entry: Environment::SingleEntry[TypeName, AST::Declarations::Interface]
|
1093
|
+
interface_entry = _ = mixin.entry
|
1094
|
+
type_params = interface_entry.decl.type_params
|
1071
1095
|
|
1072
1096
|
InvalidTypeApplicationError.check!(
|
1073
1097
|
type_name: type_name,
|