rbs 0.10.0 → 0.13.0
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 +9 -9
- data/CHANGELOG.md +29 -0
- data/Gemfile +1 -0
- data/README.md +1 -1
- data/Rakefile +16 -6
- data/Steepfile +28 -0
- data/bin/steep +4 -0
- data/bin/test_runner.rb +7 -5
- data/docs/syntax.md +14 -1
- data/lib/rbs/ast/comment.rb +7 -1
- data/lib/rbs/ast/declarations.rb +15 -9
- data/lib/rbs/ast/members.rb +3 -8
- data/lib/rbs/buffer.rb +1 -1
- data/lib/rbs/cli.rb +72 -3
- data/lib/rbs/constant.rb +1 -1
- data/lib/rbs/constant_table.rb +9 -8
- data/lib/rbs/definition.rb +31 -14
- data/lib/rbs/definition_builder.rb +97 -67
- data/lib/rbs/environment.rb +28 -11
- data/lib/rbs/environment_loader.rb +67 -47
- 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 +2 -12
- data/lib/rbs/prototype/rb.rb +3 -5
- data/lib/rbs/prototype/rbi.rb +1 -4
- data/lib/rbs/prototype/runtime.rb +0 -4
- data/lib/rbs/substitution.rb +4 -3
- data/lib/rbs/test/setup.rb +5 -1
- data/lib/rbs/test/setup_helper.rb +15 -0
- data/lib/rbs/test/tester.rb +7 -5
- data/lib/rbs/test/type_check.rb +14 -2
- 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 +9 -6
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +26 -17
- 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/constant.rbs +21 -0
- data/sig/constant_table.rbs +30 -0
- data/sig/declarations.rbs +202 -0
- data/sig/definition.rbs +129 -0
- data/sig/definition_builder.rbs +94 -0
- data/sig/environment.rbs +94 -0
- data/sig/environment_loader.rbs +58 -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/sig/version.rbs +3 -0
- data/sig/writer.rbs +40 -0
- data/stdlib/bigdecimal/big_decimal.rbs +887 -0
- data/stdlib/bigdecimal/math/big_math.rbs +142 -0
- data/stdlib/builtin/array.rbs +2 -1
- data/stdlib/builtin/builtin.rbs +0 -3
- data/stdlib/builtin/hash.rbs +1 -1
- data/stdlib/builtin/kernel.rbs +2 -0
- data/stdlib/builtin/math.rbs +26 -26
- data/stdlib/builtin/struct.rbs +9 -10
- data/stdlib/date/date.rbs +1056 -0
- data/stdlib/date/date_time.rbs +582 -0
- data/stdlib/forwardable/forwardable.rbs +204 -0
- data/stdlib/pathname/pathname.rbs +2 -0
- data/stdlib/pty/pty.rbs +5 -29
- data/stdlib/set/set.rbs +1 -1
- data/stdlib/uri/file.rbs +167 -0
- data/stdlib/uri/generic.rbs +875 -0
- data/stdlib/uri/http.rbs +158 -0
- data/stdlib/uri/https.rbs +108 -0
- data/stdlib/uri/ldap.rbs +224 -0
- data/stdlib/uri/ldaps.rbs +108 -0
- data/stdlib/zlib/zlib.rbs +1 -1
- data/steep/Gemfile +3 -0
- data/steep/Gemfile.lock +51 -0
- metadata +45 -5
data/lib/rbs/constant.rb
CHANGED
data/lib/rbs/constant_table.rb
CHANGED
@@ -47,6 +47,8 @@ module RBS
|
|
47
47
|
|
48
48
|
head, *tail = split_name(name)
|
49
49
|
|
50
|
+
raise unless head
|
51
|
+
|
50
52
|
head_constant = case
|
51
53
|
when name.absolute?
|
52
54
|
name_to_constant(TypeName.new(name: head, namespace: Namespace.root))
|
@@ -57,11 +59,13 @@ module RBS
|
|
57
59
|
resolve_constant_reference_inherit(head, scopes: constant_scopes(context.first.to_type_name))
|
58
60
|
end
|
59
61
|
|
60
|
-
|
61
|
-
|
62
|
-
resolve_constant_reference_inherit
|
63
|
-
|
64
|
-
|
62
|
+
tail.inject(head_constant) do |constant, name|
|
63
|
+
if constant
|
64
|
+
resolve_constant_reference_inherit(
|
65
|
+
name,
|
66
|
+
scopes: constant_scopes(constant.name),
|
67
|
+
no_object: constant.name != BuiltinNames::Object.name
|
68
|
+
)
|
65
69
|
end
|
66
70
|
end
|
67
71
|
end
|
@@ -150,9 +154,6 @@ module RBS
|
|
150
154
|
when Environment::ModuleEntry
|
151
155
|
constant_scopes0 BuiltinNames::Module.name, scopes: scopes
|
152
156
|
constant_scopes_module name, scopes: scopes
|
153
|
-
|
154
|
-
else
|
155
|
-
raise "Unexpected declaration: #{name} (#{entry.class})"
|
156
157
|
end
|
157
158
|
|
158
159
|
scopes
|
data/lib/rbs/definition.rb
CHANGED
@@ -45,6 +45,15 @@ module RBS
|
|
45
45
|
def update(type: self.type, member: self.member, defined_in: self.defined_in, implemented_in: self.implemented_in)
|
46
46
|
TypeDef.new(type: type, member: member, defined_in: defined_in, implemented_in: implemented_in)
|
47
47
|
end
|
48
|
+
|
49
|
+
def overload?
|
50
|
+
case mem = member
|
51
|
+
when AST::Members::MethodDefinition
|
52
|
+
mem.overload?
|
53
|
+
else
|
54
|
+
false
|
55
|
+
end
|
56
|
+
end
|
48
57
|
end
|
49
58
|
|
50
59
|
attr_reader :super_method
|
@@ -60,11 +69,17 @@ module RBS
|
|
60
69
|
end
|
61
70
|
|
62
71
|
def defined_in
|
63
|
-
@defined_in ||=
|
72
|
+
@defined_in ||= begin
|
73
|
+
last_def = defs.last or raise
|
74
|
+
last_def.defined_in
|
75
|
+
end
|
64
76
|
end
|
65
77
|
|
66
78
|
def implemented_in
|
67
|
-
@implemented_in ||=
|
79
|
+
@implemented_in ||= begin
|
80
|
+
last_def = defs.last or raise
|
81
|
+
last_def.implemented_in
|
82
|
+
end
|
68
83
|
end
|
69
84
|
|
70
85
|
def method_types
|
@@ -72,16 +87,15 @@ module RBS
|
|
72
87
|
end
|
73
88
|
|
74
89
|
def comments
|
75
|
-
@comments ||= defs.map(&:comment).compact
|
90
|
+
@comments ||= _ = defs.map(&:comment).compact
|
76
91
|
end
|
77
92
|
|
78
93
|
def annotations
|
79
94
|
@annotations ||= @extra_annotations + defs.flat_map(&:annotations)
|
80
95
|
end
|
81
96
|
|
82
|
-
|
83
|
-
|
84
|
-
[]
|
97
|
+
def members
|
98
|
+
@members ||= defs.map(&:member).uniq
|
85
99
|
end
|
86
100
|
|
87
101
|
def public?
|
@@ -118,8 +132,8 @@ module RBS
|
|
118
132
|
end
|
119
133
|
|
120
134
|
module Ancestor
|
121
|
-
Instance = Struct.new(:name, :args, keyword_init: true)
|
122
|
-
Singleton = Struct.new(:name, keyword_init: true)
|
135
|
+
Instance = _ = Struct.new(:name, :args, keyword_init: true)
|
136
|
+
Singleton = _ = Struct.new(:name, keyword_init: true)
|
123
137
|
end
|
124
138
|
|
125
139
|
class InstanceAncestors
|
@@ -211,7 +225,10 @@ module RBS
|
|
211
225
|
end
|
212
226
|
|
213
227
|
def interface?
|
214
|
-
|
228
|
+
case en = entry
|
229
|
+
when Environment::SingleEntry
|
230
|
+
en.decl.is_a?(AST::Declarations::Interface)
|
231
|
+
end
|
215
232
|
end
|
216
233
|
|
217
234
|
def class_type?
|
@@ -231,16 +248,16 @@ module RBS
|
|
231
248
|
end
|
232
249
|
|
233
250
|
def type_params_decl
|
234
|
-
case entry
|
251
|
+
case en = entry
|
235
252
|
when Environment::ClassEntry, Environment::ModuleEntry
|
236
|
-
|
253
|
+
en.type_params
|
237
254
|
when Environment::SingleEntry
|
238
|
-
|
255
|
+
en.decl.type_params
|
239
256
|
end
|
240
257
|
end
|
241
258
|
|
242
259
|
def sub(s)
|
243
|
-
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)
|
244
261
|
|
245
262
|
definition.methods.merge!(methods.transform_values {|method| method.sub(s) })
|
246
263
|
definition.instance_variables.merge!(instance_variables.transform_values {|v| v.sub(s) })
|
@@ -260,7 +277,7 @@ module RBS
|
|
260
277
|
end
|
261
278
|
|
262
279
|
def each_type(&block)
|
263
|
-
if
|
280
|
+
if block
|
264
281
|
methods.each_value do |method|
|
265
282
|
if method.defined_in == type_name
|
266
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,14 +567,14 @@ 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] }
|
574
579
|
|
575
580
|
if visibilities.size > 1
|
@@ -582,15 +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,
|
586
|
-
|
587
|
-
else
|
588
|
-
raise InvalidOverloadMethodError.new(
|
589
|
-
type_name: type_name,
|
590
|
-
method_name: method_name,
|
591
|
-
kind: :instance,
|
592
|
-
members: array.map(&:first)
|
593
|
-
)
|
590
|
+
result[method_name] = [array[0][1], nil, primary[0], overloads]
|
594
591
|
end
|
595
592
|
end
|
596
593
|
end
|
@@ -609,7 +606,13 @@ module RBS
|
|
609
606
|
|
610
607
|
Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
|
611
608
|
method_definition_members(type_name, entry, kind: :instance).each do |method_name, array|
|
612
|
-
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
|
613
616
|
|
614
617
|
m = if method_def
|
615
618
|
Definition::Method.new(
|
@@ -778,9 +781,9 @@ module RBS
|
|
778
781
|
|
779
782
|
errors = []
|
780
783
|
|
781
|
-
|
782
|
-
|
783
|
-
|
784
|
+
case decl
|
785
|
+
when AST::Declarations::Class
|
786
|
+
if super_class = decl.super_class
|
784
787
|
result = calculator.in_inherit(name: super_class.name, args: super_class.args, variables: param_names)
|
785
788
|
|
786
789
|
validate_params_with type_params, result: result do |param|
|
@@ -791,6 +794,8 @@ module RBS
|
|
791
794
|
end
|
792
795
|
end
|
793
796
|
|
797
|
+
# @type var result: VarianceCalculator::Result
|
798
|
+
|
794
799
|
decl.members.each do |member|
|
795
800
|
case member
|
796
801
|
when AST::Members::Include
|
@@ -838,7 +843,13 @@ module RBS
|
|
838
843
|
|
839
844
|
Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
|
840
845
|
method_definition_members(type_name, entry, kind: :singleton).each do |method_name, array|
|
841
|
-
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
|
842
853
|
|
843
854
|
m = Definition::Method.new(
|
844
855
|
super_method: nil,
|
@@ -890,7 +901,7 @@ module RBS
|
|
890
901
|
end
|
891
902
|
|
892
903
|
unless definition.methods.key?(:new)
|
893
|
-
instance =
|
904
|
+
instance = build_instance(type_name)
|
894
905
|
initialize = instance.methods[:initialize]
|
895
906
|
|
896
907
|
if initialize
|
@@ -965,7 +976,7 @@ module RBS
|
|
965
976
|
|
966
977
|
def merge_definitions(type_name, pairs, entry:, self_type:, ancestors:)
|
967
978
|
Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
|
968
|
-
pairs.reverse_each do |
|
979
|
+
pairs.reverse_each do |ancestor, current_definition|
|
969
980
|
sub = case ancestor
|
970
981
|
when Definition::Ancestor::Instance
|
971
982
|
Substitution.build(current_definition.type_params, ancestor.args)
|
@@ -973,8 +984,16 @@ module RBS
|
|
973
984
|
Substitution.build([], [])
|
974
985
|
end
|
975
986
|
|
987
|
+
# @type var kind: method_kind
|
988
|
+
kind = case ancestor
|
989
|
+
when Definition::Ancestor::Instance
|
990
|
+
:instance
|
991
|
+
when Definition::Ancestor::Singleton
|
992
|
+
:singleton
|
993
|
+
end
|
994
|
+
|
976
995
|
current_definition.methods.each do |name, method|
|
977
|
-
merge_method definition.methods, name, method, sub
|
996
|
+
merge_method type_name, definition.methods, name, method, sub, kind: kind
|
978
997
|
end
|
979
998
|
|
980
999
|
current_definition.instance_variables.each do |name, variable|
|
@@ -998,18 +1017,25 @@ module RBS
|
|
998
1017
|
)
|
999
1018
|
end
|
1000
1019
|
|
1001
|
-
def merge_method(methods, name, method, sub)
|
1020
|
+
def merge_method(type_name, methods, name, method, sub, kind:)
|
1002
1021
|
super_method = methods[name]
|
1003
1022
|
|
1023
|
+
defs = if method.defs.all? {|d| d.overload? }
|
1024
|
+
raise InvalidOverloadMethodError.new(type_name: type_name, method_name: name, kind: kind, members: method.members) unless super_method
|
1025
|
+
method.defs + super_method.defs
|
1026
|
+
else
|
1027
|
+
method.defs
|
1028
|
+
end
|
1029
|
+
|
1004
1030
|
methods[name] = Definition::Method.new(
|
1005
1031
|
super_method: super_method,
|
1006
1032
|
accessibility: method.accessibility,
|
1007
|
-
defs: sub.mapping.empty? ?
|
1033
|
+
defs: sub.mapping.empty? ? defs : defs.map {|defn| defn.update(type: defn.type.sub(sub)) }
|
1008
1034
|
)
|
1009
1035
|
end
|
1010
1036
|
|
1011
1037
|
def try_cache(type_name, cache:)
|
1012
|
-
cached = cache[type_name]
|
1038
|
+
cached = _ = cache[type_name]
|
1013
1039
|
|
1014
1040
|
case cached
|
1015
1041
|
when Definition
|
@@ -1021,9 +1047,11 @@ module RBS
|
|
1021
1047
|
begin
|
1022
1048
|
cache[type_name] = yield
|
1023
1049
|
rescue => ex
|
1024
|
-
cache
|
1050
|
+
cache.delete(type_name)
|
1025
1051
|
raise ex
|
1026
1052
|
end
|
1053
|
+
else
|
1054
|
+
raise
|
1027
1055
|
end
|
1028
1056
|
end
|
1029
1057
|
|
@@ -1061,7 +1089,9 @@ module RBS
|
|
1061
1089
|
mixin = build_interface(member.name)
|
1062
1090
|
|
1063
1091
|
args = member.args
|
1064
|
-
|
1092
|
+
# @type var interface_entry: Environment::SingleEntry[TypeName, AST::Declarations::Interface]
|
1093
|
+
interface_entry = _ = mixin.entry
|
1094
|
+
type_params = interface_entry.decl.type_params
|
1065
1095
|
|
1066
1096
|
InvalidTypeApplicationError.check!(
|
1067
1097
|
type_name: type_name,
|