rbs-relaxed 3.9.0.1 → 3.9.4.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/.github/workflows/ruby.yml +24 -2
- data/.github/workflows/typecheck.yml +0 -2
- data/.github/workflows/windows.yml +1 -1
- data/.rubocop.yml +4 -0
- data/CHANGELOG.md +93 -0
- data/Rakefile +17 -2
- data/config.yml +4 -0
- data/core/data.rbs +1 -1
- data/core/enumerator.rbs +14 -2
- data/core/exception.rbs +1 -1
- data/core/hash.rbs +2 -2
- data/core/kernel.rbs +4 -4
- data/core/method.rbs +2 -2
- data/core/module.rbs +4 -4
- data/core/object.rbs +1 -1
- data/core/proc.rbs +2 -2
- data/core/rbs/unnamed/argf.rbs +3 -3
- data/core/rubygems/version.rbs +2 -2
- data/core/string.rbs +3 -3
- data/core/unbound_method.rbs +1 -1
- data/ext/rbs_extension/parser.c +59 -50
- data/ext/rbs_extension/parserstate.c +15 -1
- data/include/rbs/ruby_objs.h +4 -4
- data/lib/rbs/ast/declarations.rb +9 -4
- data/lib/rbs/ast/type_param.rb +0 -10
- data/lib/rbs/collection/config/lockfile_generator.rb +29 -3
- data/lib/rbs/definition.rb +40 -31
- data/lib/rbs/definition_builder/ancestor_builder.rb +2 -0
- data/lib/rbs/definition_builder.rb +86 -34
- data/lib/rbs/environment.rb +8 -4
- data/lib/rbs/errors.rb +10 -31
- data/lib/rbs/prototype/rb.rb +2 -1
- data/lib/rbs/prototype/rbi.rb +2 -1
- data/lib/rbs/prototype/runtime.rb +3 -0
- data/lib/rbs/types.rb +3 -7
- data/lib/rbs/unit_test/type_assertions.rb +2 -2
- data/lib/rbs/unit_test/with_aliases.rb +3 -1
- data/lib/rbs/version.rb +1 -1
- data/sig/annotate/rdoc_source.rbs +2 -0
- data/sig/cli.rbs +2 -0
- data/sig/collection/config/lockfile_generator.rbs +1 -1
- data/sig/declarations.rbs +10 -3
- data/sig/definition.rbs +67 -14
- data/sig/definition_builder.rbs +17 -3
- data/sig/errors.rbs +7 -10
- data/sig/namespace.rbs +1 -1
- data/sig/typename.rbs +1 -1
- data/sig/types.rbs +0 -3
- data/src/ruby_objs.c +8 -4
- data/src/util/rbs_constant_pool.c +1 -1
- data/stdlib/cgi/0/core.rbs +10 -0
- data/stdlib/ipaddr/0/ipaddr.rbs +8 -0
- data/stdlib/net-http/0/net-http.rbs +1 -1
- data/stdlib/openssl/0/openssl.rbs +67 -67
- data/stdlib/resolv/0/resolv.rbs +8 -8
- data/stdlib/socket/0/addrinfo.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +1 -1
- data/stdlib/uri/0/common.rbs +17 -0
- metadata +3 -6
|
@@ -82,7 +82,7 @@ module RBS
|
|
|
82
82
|
AST::TypeParam.application(params, args) || Substitution.new()
|
|
83
83
|
end
|
|
84
84
|
|
|
85
|
-
def define_instance(definition, type_name, subst)
|
|
85
|
+
def define_instance(definition, type_name, subst, define_class_vars:)
|
|
86
86
|
one_ancestors = ancestor_builder.one_instance_ancestors(type_name)
|
|
87
87
|
methods = method_builder.build_instance(type_name)
|
|
88
88
|
|
|
@@ -104,7 +104,7 @@ module RBS
|
|
|
104
104
|
validate_type_presence(arg)
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
-
define_instance(definition, mod.name, subst + tapp_subst(mod.name, mod.args))
|
|
107
|
+
define_instance(definition, mod.name, subst + tapp_subst(mod.name, mod.args), define_class_vars: define_class_vars)
|
|
108
108
|
end
|
|
109
109
|
|
|
110
110
|
all_interfaces = one_ancestors.each_included_interface.flat_map do |interface|
|
|
@@ -120,7 +120,7 @@ module RBS
|
|
|
120
120
|
validate_type_presence(arg)
|
|
121
121
|
end
|
|
122
122
|
|
|
123
|
-
define_instance(definition, mod.name, subst + tapp_subst(mod.name, mod.args))
|
|
123
|
+
define_instance(definition, mod.name, subst + tapp_subst(mod.name, mod.args), define_class_vars: define_class_vars)
|
|
124
124
|
end
|
|
125
125
|
|
|
126
126
|
entry = env.class_decls[type_name] or raise "Unknown name for build_instance: #{type_name}"
|
|
@@ -145,23 +145,25 @@ module RBS
|
|
|
145
145
|
type_name,
|
|
146
146
|
definition.instance_variables,
|
|
147
147
|
name: ivar_name,
|
|
148
|
-
type: member.type.sub(subst_)
|
|
148
|
+
type: member.type.sub(subst_),
|
|
149
|
+
source: member
|
|
149
150
|
)
|
|
150
151
|
end
|
|
151
152
|
end
|
|
152
153
|
|
|
153
154
|
when AST::Members::InstanceVariable
|
|
154
|
-
InstanceVariableDuplicationError.check!(variables: definition.instance_variables, member: member, type_name: type_name)
|
|
155
155
|
insert_variable(
|
|
156
156
|
type_name,
|
|
157
157
|
definition.instance_variables,
|
|
158
158
|
name: member.name,
|
|
159
|
-
type: member.type.sub(subst_)
|
|
159
|
+
type: member.type.sub(subst_),
|
|
160
|
+
source: member
|
|
160
161
|
)
|
|
161
162
|
|
|
162
163
|
when AST::Members::ClassVariable
|
|
163
|
-
|
|
164
|
-
|
|
164
|
+
if define_class_vars
|
|
165
|
+
insert_variable(type_name, definition.class_variables, name: member.name, type: member.type, source: member)
|
|
166
|
+
end
|
|
165
167
|
end
|
|
166
168
|
end
|
|
167
169
|
end
|
|
@@ -216,13 +218,13 @@ module RBS
|
|
|
216
218
|
if ans.name.interface?
|
|
217
219
|
define_interface(definition, ans.name, subst)
|
|
218
220
|
else
|
|
219
|
-
define_instance(definition, ans.name, subst)
|
|
221
|
+
define_instance(definition, ans.name, subst, define_class_vars: true)
|
|
220
222
|
end
|
|
221
223
|
end
|
|
222
224
|
end
|
|
223
225
|
end
|
|
224
226
|
|
|
225
|
-
define_instance(definition, type_name, Substitution.new)
|
|
227
|
+
define_instance(definition, type_name, Substitution.new, define_class_vars: true)
|
|
226
228
|
end
|
|
227
229
|
end
|
|
228
230
|
end
|
|
@@ -251,7 +253,6 @@ module RBS
|
|
|
251
253
|
|
|
252
254
|
definition.methods.merge!(defn.methods)
|
|
253
255
|
definition.instance_variables.merge!(defn.instance_variables)
|
|
254
|
-
definition.class_variables.merge!(defn.class_variables)
|
|
255
256
|
end
|
|
256
257
|
|
|
257
258
|
one_ancestors.each_extended_module do |mod|
|
|
@@ -260,7 +261,7 @@ module RBS
|
|
|
260
261
|
end
|
|
261
262
|
|
|
262
263
|
subst = tapp_subst(mod.name, mod.args)
|
|
263
|
-
define_instance(definition, mod.name, subst)
|
|
264
|
+
define_instance(definition, mod.name, subst, define_class_vars: false)
|
|
264
265
|
end
|
|
265
266
|
|
|
266
267
|
all_interfaces = one_ancestors.each_extended_interface.flat_map do |interface|
|
|
@@ -284,20 +285,18 @@ module RBS
|
|
|
284
285
|
end
|
|
285
286
|
|
|
286
287
|
if ivar_name
|
|
287
|
-
insert_variable(type_name, definition.instance_variables, name: ivar_name, type: member.type)
|
|
288
|
+
insert_variable(type_name, definition.instance_variables, name: ivar_name, type: member.type, source: member)
|
|
288
289
|
end
|
|
289
290
|
end
|
|
290
291
|
|
|
291
292
|
when AST::Members::ClassInstanceVariable
|
|
292
|
-
|
|
293
|
-
insert_variable(type_name, definition.instance_variables, name: member.name, type: member.type)
|
|
294
|
-
|
|
295
|
-
when AST::Members::ClassVariable
|
|
296
|
-
ClassVariableDuplicationError.check!(variables: definition.class_variables, member: member, type_name: type_name)
|
|
297
|
-
insert_variable(type_name, definition.class_variables, name: member.name, type: member.type)
|
|
293
|
+
insert_variable(type_name, definition.instance_variables, name: member.name, type: member.type, source: member)
|
|
298
294
|
end
|
|
299
295
|
end
|
|
300
296
|
end
|
|
297
|
+
|
|
298
|
+
instance_definition = build_instance(type_name)
|
|
299
|
+
definition.class_variables.replace(instance_definition.class_variables)
|
|
301
300
|
end
|
|
302
301
|
end
|
|
303
302
|
end
|
|
@@ -390,12 +389,14 @@ module RBS
|
|
|
390
389
|
type: method_type,
|
|
391
390
|
member: initialize_def.member,
|
|
392
391
|
defined_in: initialize_def.defined_in,
|
|
393
|
-
implemented_in: initialize_def.implemented_in
|
|
394
|
-
|
|
395
|
-
|
|
392
|
+
implemented_in: initialize_def.implemented_in
|
|
393
|
+
).tap do |type_def|
|
|
394
|
+
type_def.overload_annotations.replace(initialize_def.overload_annotations)
|
|
395
|
+
end
|
|
396
396
|
end,
|
|
397
397
|
accessibility: :public,
|
|
398
|
-
alias_of: nil
|
|
398
|
+
alias_of: nil,
|
|
399
|
+
alias_member: nil
|
|
399
400
|
)
|
|
400
401
|
|
|
401
402
|
definition.methods[:new] = typed_new
|
|
@@ -539,12 +540,42 @@ module RBS
|
|
|
539
540
|
end
|
|
540
541
|
end
|
|
541
542
|
|
|
542
|
-
def insert_variable(type_name, variables, name:, type:)
|
|
543
|
+
def insert_variable(type_name, variables, name:, type:, source:)
|
|
543
544
|
variables[name] = Definition::Variable.new(
|
|
544
545
|
parent_variable: variables[name],
|
|
545
546
|
type: type,
|
|
546
|
-
declared_in: type_name
|
|
547
|
+
declared_in: type_name,
|
|
548
|
+
source: source
|
|
547
549
|
)
|
|
550
|
+
validate_variable(variables[name])
|
|
551
|
+
end
|
|
552
|
+
|
|
553
|
+
def validate_variable(var)
|
|
554
|
+
return unless var.parent_variable
|
|
555
|
+
|
|
556
|
+
# Ignore attrs
|
|
557
|
+
variables = [] #: Array[Definition::Variable]
|
|
558
|
+
tmp_var = var
|
|
559
|
+
while tmp_var
|
|
560
|
+
variables << tmp_var if tmp_var.source.is_a?(AST::Members::Var)
|
|
561
|
+
tmp_var = tmp_var.parent_variable
|
|
562
|
+
end
|
|
563
|
+
|
|
564
|
+
# Duplicates should be eliminated, so there can't be more than 3.
|
|
565
|
+
return unless variables.length == 2
|
|
566
|
+
|
|
567
|
+
l, r = variables #: [Definition::Variable, Definition::Variable]
|
|
568
|
+
|
|
569
|
+
case l.source
|
|
570
|
+
when AST::Members::InstanceVariable
|
|
571
|
+
if r.source.instance_of?(AST::Members::InstanceVariable) && l.declared_in == r.declared_in
|
|
572
|
+
raise InstanceVariableDuplicationError.new(type_name: l.declared_in, variable_name: l.source.name, location: l.source.location)
|
|
573
|
+
end
|
|
574
|
+
when AST::Members::ClassInstanceVariable
|
|
575
|
+
if r.source.instance_of?(AST::Members::ClassInstanceVariable) && l.declared_in == r.declared_in
|
|
576
|
+
raise ClassInstanceVariableDuplicationError.new(type_name: l.declared_in, variable_name: l.source.name, location: l.source.location)
|
|
577
|
+
end
|
|
578
|
+
end
|
|
548
579
|
end
|
|
549
580
|
|
|
550
581
|
def import_methods(definition, module_name, module_methods, interfaces_methods, subst, self_type_methods)
|
|
@@ -630,8 +661,11 @@ module RBS
|
|
|
630
661
|
defn.update(defined_in: defined_in, implemented_in: implemented_in)
|
|
631
662
|
end,
|
|
632
663
|
accessibility: original_method.accessibility,
|
|
633
|
-
alias_of: original_method
|
|
664
|
+
alias_of: original_method,
|
|
665
|
+
alias_member: original
|
|
634
666
|
)
|
|
667
|
+
|
|
668
|
+
method_definition.annotations.replace(original.annotations)
|
|
635
669
|
when AST::Members::MethodDefinition
|
|
636
670
|
if duplicated_method = methods[method.name]
|
|
637
671
|
raise DuplicatedMethodDefinitionError.new(
|
|
@@ -646,9 +680,11 @@ module RBS
|
|
|
646
680
|
type: subst.empty? ? overload.method_type : overload.method_type.sub(subst),
|
|
647
681
|
member: original,
|
|
648
682
|
defined_in: defined_in,
|
|
649
|
-
implemented_in: implemented_in
|
|
650
|
-
|
|
651
|
-
|
|
683
|
+
implemented_in: implemented_in
|
|
684
|
+
).tap do |type_def|
|
|
685
|
+
# Keep the original annotations given to overloads.
|
|
686
|
+
type_def.overload_annotations.replace(overload.annotations)
|
|
687
|
+
end
|
|
652
688
|
end
|
|
653
689
|
|
|
654
690
|
# @type var accessibility: RBS::Definition::accessibility
|
|
@@ -668,8 +704,11 @@ module RBS
|
|
|
668
704
|
super_method: super_method,
|
|
669
705
|
defs: defs,
|
|
670
706
|
accessibility: accessibility,
|
|
671
|
-
alias_of: nil
|
|
707
|
+
alias_of: nil,
|
|
708
|
+
alias_member: nil
|
|
672
709
|
)
|
|
710
|
+
|
|
711
|
+
method_definition.annotations.replace(original.annotations)
|
|
673
712
|
when AST::Members::AttrReader, AST::Members::AttrWriter, AST::Members::AttrAccessor
|
|
674
713
|
if duplicated_method = methods[method.name]
|
|
675
714
|
raise DuplicatedMethodDefinitionError.new(
|
|
@@ -718,8 +757,11 @@ module RBS
|
|
|
718
757
|
)
|
|
719
758
|
],
|
|
720
759
|
accessibility: method.accessibility,
|
|
721
|
-
alias_of: nil
|
|
760
|
+
alias_of: nil,
|
|
761
|
+
alias_member: nil
|
|
722
762
|
)
|
|
763
|
+
|
|
764
|
+
method_definition.annotations.replace(original.annotations)
|
|
723
765
|
when nil
|
|
724
766
|
# Overloading method definition only
|
|
725
767
|
|
|
@@ -746,8 +788,11 @@ module RBS
|
|
|
746
788
|
defn.update(implemented_in: implemented_in)
|
|
747
789
|
end,
|
|
748
790
|
accessibility: existing_method.accessibility,
|
|
749
|
-
alias_of: existing_method.alias_of
|
|
791
|
+
alias_of: existing_method.alias_of,
|
|
792
|
+
alias_member: nil
|
|
750
793
|
)
|
|
794
|
+
|
|
795
|
+
method_definition.annotations.replace(existing_method.annotations)
|
|
751
796
|
end
|
|
752
797
|
|
|
753
798
|
method.overloads.each do |overloading_def|
|
|
@@ -756,12 +801,19 @@ module RBS
|
|
|
756
801
|
type: subst.empty? ? overload.method_type : overload.method_type.sub(subst),
|
|
757
802
|
member: overloading_def,
|
|
758
803
|
defined_in: defined_in,
|
|
759
|
-
implemented_in: implemented_in
|
|
760
|
-
overload_annotations: overload.annotations
|
|
804
|
+
implemented_in: implemented_in
|
|
761
805
|
)
|
|
762
806
|
|
|
807
|
+
type_def.overload_annotations.replace(overload.annotations)
|
|
808
|
+
|
|
763
809
|
method_definition.defs.unshift(type_def)
|
|
764
810
|
end
|
|
811
|
+
|
|
812
|
+
method_definition.annotations.concat(overloading_def.annotations)
|
|
813
|
+
end
|
|
814
|
+
|
|
815
|
+
method_definition.defs.each do |type_def|
|
|
816
|
+
type_def.member_annotations.replace(method_definition.annotations)
|
|
765
817
|
end
|
|
766
818
|
|
|
767
819
|
methods[method.name] = method_definition
|
data/lib/rbs/environment.rb
CHANGED
|
@@ -552,7 +552,8 @@ module RBS
|
|
|
552
552
|
name: decl.name,
|
|
553
553
|
type: absolute_type(resolver, map, decl.type, context: nil),
|
|
554
554
|
location: decl.location,
|
|
555
|
-
comment: decl.comment
|
|
555
|
+
comment: decl.comment,
|
|
556
|
+
annotations: decl.annotations
|
|
556
557
|
)
|
|
557
558
|
end
|
|
558
559
|
|
|
@@ -660,7 +661,8 @@ module RBS
|
|
|
660
661
|
name: decl.name.with_prefix(prefix),
|
|
661
662
|
type: absolute_type(resolver, map, decl.type, context: context),
|
|
662
663
|
location: decl.location,
|
|
663
|
-
comment: decl.comment
|
|
664
|
+
comment: decl.comment,
|
|
665
|
+
annotations: decl.annotations
|
|
664
666
|
)
|
|
665
667
|
|
|
666
668
|
when AST::Declarations::ClassAlias
|
|
@@ -668,7 +670,8 @@ module RBS
|
|
|
668
670
|
new_name: decl.new_name.with_prefix(prefix),
|
|
669
671
|
old_name: absolute_type_name(resolver, map, decl.old_name, context: context),
|
|
670
672
|
location: decl.location,
|
|
671
|
-
comment: decl.comment
|
|
673
|
+
comment: decl.comment,
|
|
674
|
+
annotations: decl.annotations
|
|
672
675
|
)
|
|
673
676
|
|
|
674
677
|
when AST::Declarations::ModuleAlias
|
|
@@ -676,7 +679,8 @@ module RBS
|
|
|
676
679
|
new_name: decl.new_name.with_prefix(prefix),
|
|
677
680
|
old_name: absolute_type_name(resolver, map, decl.old_name, context: context),
|
|
678
681
|
location: decl.location,
|
|
679
|
-
comment: decl.comment
|
|
682
|
+
comment: decl.comment,
|
|
683
|
+
annotations: decl.annotations
|
|
680
684
|
)
|
|
681
685
|
end
|
|
682
686
|
end
|
data/lib/rbs/errors.rb
CHANGED
|
@@ -325,46 +325,25 @@ module RBS
|
|
|
325
325
|
class VariableDuplicationError < DefinitionError
|
|
326
326
|
include DetailedMessageable
|
|
327
327
|
|
|
328
|
-
attr_reader :
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
@member = member
|
|
328
|
+
attr_reader :type_name
|
|
329
|
+
attr_reader :variable_name
|
|
330
|
+
attr_reader :location
|
|
332
331
|
|
|
333
|
-
|
|
334
|
-
|
|
332
|
+
def initialize(type_name:, variable_name:, location:)
|
|
333
|
+
@type_name = type_name
|
|
334
|
+
@variable_name = variable_name
|
|
335
|
+
@location = location
|
|
335
336
|
|
|
336
|
-
|
|
337
|
-
loc = @member.location or raise
|
|
338
|
-
loc[:name]
|
|
337
|
+
super "#{Location.to_string location}: Duplicated #{kind} variable name `#{variable_name}` in `#{type_name}`"
|
|
339
338
|
end
|
|
340
339
|
end
|
|
341
340
|
|
|
342
341
|
class InstanceVariableDuplicationError < VariableDuplicationError
|
|
343
|
-
def
|
|
344
|
-
if old = variables[member.name]
|
|
345
|
-
if old.declared_in == type_name
|
|
346
|
-
raise new(member: member)
|
|
347
|
-
end
|
|
348
|
-
end
|
|
349
|
-
end
|
|
342
|
+
def kind = 'instance'
|
|
350
343
|
end
|
|
351
344
|
|
|
352
345
|
class ClassInstanceVariableDuplicationError < VariableDuplicationError
|
|
353
|
-
def
|
|
354
|
-
if old = variables[member.name]
|
|
355
|
-
if old.declared_in == type_name
|
|
356
|
-
raise new(member: member)
|
|
357
|
-
end
|
|
358
|
-
end
|
|
359
|
-
end
|
|
360
|
-
end
|
|
361
|
-
|
|
362
|
-
class ClassVariableDuplicationError < VariableDuplicationError
|
|
363
|
-
def self.check!(variables:, member:, type_name:)
|
|
364
|
-
if old = variables[member.name]
|
|
365
|
-
raise new(member: member)
|
|
366
|
-
end
|
|
367
|
-
end
|
|
346
|
+
def kind = 'class instance'
|
|
368
347
|
end
|
|
369
348
|
|
|
370
349
|
class UnknownMethodAliasError < DefinitionError
|
data/lib/rbs/prototype/rb.rb
CHANGED
data/lib/rbs/prototype/rbi.rb
CHANGED
|
@@ -250,6 +250,8 @@ module RBS
|
|
|
250
250
|
method = builder.build_singleton(module_name.absolute!).methods[singleton]
|
|
251
251
|
method_name = singleton
|
|
252
252
|
kind = :singleton
|
|
253
|
+
else
|
|
254
|
+
raise
|
|
253
255
|
end
|
|
254
256
|
|
|
255
257
|
if method
|
|
@@ -462,6 +464,7 @@ module RBS
|
|
|
462
464
|
name: to_type_name(name.to_s),
|
|
463
465
|
type: type,
|
|
464
466
|
location: nil,
|
|
467
|
+
annotations: [],
|
|
465
468
|
comment: nil
|
|
466
469
|
)
|
|
467
470
|
end
|
data/lib/rbs/types.rb
CHANGED
|
@@ -109,18 +109,14 @@ module RBS
|
|
|
109
109
|
class Any < Base
|
|
110
110
|
def initialize(location:, todo: false)
|
|
111
111
|
super(location: location)
|
|
112
|
-
|
|
112
|
+
if todo
|
|
113
|
+
@string = "__todo__"
|
|
114
|
+
end
|
|
113
115
|
end
|
|
114
116
|
|
|
115
117
|
def to_s(level=0)
|
|
116
118
|
@string || "untyped"
|
|
117
119
|
end
|
|
118
|
-
|
|
119
|
-
# @deprecated: this method is now called from the constructor, do not call it from outside
|
|
120
|
-
def todo!
|
|
121
|
-
@string = '__todo__'
|
|
122
|
-
self
|
|
123
|
-
end
|
|
124
120
|
end
|
|
125
121
|
class Nil < Base; end
|
|
126
122
|
class Top < Base; end
|
|
@@ -183,7 +183,7 @@ module RBS
|
|
|
183
183
|
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }, "Call trace does not match with given method type: #{trace.inspect}"
|
|
184
184
|
|
|
185
185
|
method_defs = method_defs(method)
|
|
186
|
-
all_errors = method_defs.map {|t| typecheck.method_call(method, t.type, trace, errors: [], annotations: t.
|
|
186
|
+
all_errors = method_defs.map {|t| typecheck.method_call(method, t.type, trace, errors: [], annotations: t.each_annotation.to_a) }
|
|
187
187
|
assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.inspect}\n #{method_defs.map(&:type).join(" | ")}"
|
|
188
188
|
|
|
189
189
|
raise exception if exception
|
|
@@ -220,7 +220,7 @@ module RBS
|
|
|
220
220
|
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }
|
|
221
221
|
|
|
222
222
|
method_defs = method_defs(method)
|
|
223
|
-
all_errors = method_defs.map {|t| typecheck.method_call(method, t.type, trace, errors: [], annotations: t.
|
|
223
|
+
all_errors = method_defs.map {|t| typecheck.method_call(method, t.type, trace, errors: [], annotations: t.each_annotation.to_a) }
|
|
224
224
|
assert all_errors.all? {|es| es.size > 0 }, "Call trace unexpectedly matches one of method definitions:\n #{trace.inspect}\n #{method_defs.map(&:type).join(" | ")}"
|
|
225
225
|
|
|
226
226
|
result
|
|
@@ -127,7 +127,9 @@ module RBS
|
|
|
127
127
|
|
|
128
128
|
# `Range` requires `begin <=> end` to return non-nil, but doesn't actually
|
|
129
129
|
# end up using the return value of it. This is to add that in when needed.
|
|
130
|
-
|
|
130
|
+
unless defined? lower.<=>
|
|
131
|
+
def lower.<=>(rhs) = :not_nil # steep:ignore MethodDefinitionInUndeclaredModule
|
|
132
|
+
end
|
|
131
133
|
|
|
132
134
|
# If `lower <=> rhs` is defined but nil, then that means we're going to be constructing
|
|
133
135
|
# an illegal range (eg `3..ToInt.new(4)`). So, we need to skip yielding an invalid range
|
data/lib/rbs/version.rb
CHANGED
|
@@ -25,6 +25,8 @@ module RBS
|
|
|
25
25
|
| (TypeName, singleton_method: Symbol) -> Array[RDoc::AnyMethod]?
|
|
26
26
|
|
|
27
27
|
def find_attribute: (TypeName, Symbol, singleton: bool) -> Array[RDoc::Attr]?
|
|
28
|
+
|
|
29
|
+
def class_docs: (TypeName) -> Array[::RDoc::Markup::Document | ::RDoc::Comment | ::String]?
|
|
28
30
|
end
|
|
29
31
|
end
|
|
30
32
|
end
|
data/sig/cli.rbs
CHANGED
data/sig/declarations.rbs
CHANGED
|
@@ -205,8 +205,10 @@ module RBS
|
|
|
205
205
|
attr_reader type: Types::t
|
|
206
206
|
attr_reader location: loc?
|
|
207
207
|
attr_reader comment: Comment?
|
|
208
|
+
attr_reader annotations: Array[Annotation]
|
|
208
209
|
|
|
209
|
-
def initialize: (name: TypeName, type: Types::t, location: loc?, comment: Comment
|
|
210
|
+
def initialize: (name: TypeName, type: Types::t, location: loc?, comment: Comment?, annotations: Array[Annotation]) -> void
|
|
211
|
+
| %a{deprecated} (name: TypeName, type: Types::t, location: loc?, comment: Comment?) -> void
|
|
210
212
|
|
|
211
213
|
include _HashEqual
|
|
212
214
|
include _ToJson
|
|
@@ -223,8 +225,10 @@ module RBS
|
|
|
223
225
|
attr_reader type: Types::t
|
|
224
226
|
attr_reader location: loc?
|
|
225
227
|
attr_reader comment: Comment?
|
|
228
|
+
attr_reader annotations: Array[Annotation]
|
|
226
229
|
|
|
227
|
-
def initialize: (name: Symbol, type: Types::t, location: loc?, comment: Comment
|
|
230
|
+
def initialize: (name: Symbol, type: Types::t, location: loc?, comment: Comment?, annotations: Array[Annotation]) -> void
|
|
231
|
+
| %a{deprecated} (name: Symbol, type: Types::t, location: loc?, comment: Comment?) -> void
|
|
228
232
|
|
|
229
233
|
include _HashEqual
|
|
230
234
|
include _ToJson
|
|
@@ -250,7 +254,10 @@ module RBS
|
|
|
250
254
|
|
|
251
255
|
attr_reader comment: Comment?
|
|
252
256
|
|
|
253
|
-
|
|
257
|
+
attr_reader annotations: Array[Annotation]
|
|
258
|
+
|
|
259
|
+
def initialize: (new_name: TypeName, old_name: TypeName, location: loc?, comment: Comment?, annotations: Array[Annotation]) -> void
|
|
260
|
+
| %a{deprecated} (new_name: TypeName, old_name: TypeName, location: loc?, comment: Comment?) -> void
|
|
254
261
|
|
|
255
262
|
include _HashEqual
|
|
256
263
|
end
|
data/sig/definition.rbs
CHANGED
|
@@ -6,8 +6,15 @@ module RBS
|
|
|
6
6
|
attr_reader parent_variable: Variable?
|
|
7
7
|
attr_reader type: Types::t
|
|
8
8
|
attr_reader declared_in: TypeName
|
|
9
|
+
type source = AST::Members::AttrAccessor
|
|
10
|
+
| AST::Members::AttrReader
|
|
11
|
+
| AST::Members::AttrWriter
|
|
12
|
+
| AST::Members::InstanceVariable
|
|
13
|
+
| AST::Members::ClassVariable
|
|
14
|
+
| AST::Members::ClassInstanceVariable
|
|
15
|
+
attr_reader source: source
|
|
9
16
|
|
|
10
|
-
def initialize: (parent_variable: Variable?, type: Types::t, declared_in: TypeName) -> void
|
|
17
|
+
def initialize: (parent_variable: Variable?, type: Types::t, declared_in: TypeName, source: source) -> void
|
|
11
18
|
|
|
12
19
|
def sub: (Substitution) -> Variable
|
|
13
20
|
end
|
|
@@ -21,22 +28,50 @@ module RBS
|
|
|
21
28
|
attr_reader defined_in: TypeName
|
|
22
29
|
attr_reader implemented_in: TypeName?
|
|
23
30
|
|
|
24
|
-
# Annotations given to
|
|
31
|
+
# Annotations given to the method definition syntax
|
|
32
|
+
#
|
|
33
|
+
# If the method have multiple syntaxes, union of the annotations to the member will be included, without dedup.
|
|
34
|
+
#
|
|
35
|
+
# The value should be updated during setup.
|
|
36
|
+
#
|
|
25
37
|
attr_reader member_annotations: Array[AST::Annotation]
|
|
26
38
|
|
|
27
39
|
# Annotations given to the overload associated to the method type
|
|
40
|
+
#
|
|
41
|
+
# The value should be updated during setup.
|
|
42
|
+
#
|
|
28
43
|
attr_reader overload_annotations: Array[AST::Annotation]
|
|
29
44
|
|
|
30
|
-
#
|
|
31
|
-
attr_reader annotations: Array[AST::Annotation]
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
# Always returns an empty array
|
|
46
|
+
%a{deprecated} attr_reader annotations: Array[AST::Annotation]
|
|
47
|
+
|
|
48
|
+
# `overload_annotations` is ignored.
|
|
49
|
+
def initialize: (
|
|
50
|
+
type: MethodType,
|
|
51
|
+
member: method_member,
|
|
52
|
+
defined_in: TypeName,
|
|
53
|
+
implemented_in: TypeName?
|
|
54
|
+
) -> void
|
|
55
|
+
| %a{deprecated} (
|
|
56
|
+
type: MethodType,
|
|
57
|
+
member: method_member,
|
|
58
|
+
defined_in: TypeName,
|
|
59
|
+
implemented_in: TypeName?,
|
|
60
|
+
overload_annotations: nil
|
|
61
|
+
) -> void
|
|
34
62
|
|
|
35
63
|
def comment: () -> AST::Comment?
|
|
36
64
|
|
|
37
65
|
def update: (?type: MethodType, ?member: method_member, ?defined_in: TypeName, ?implemented_in: TypeName?) -> TypeDef
|
|
38
66
|
|
|
39
67
|
def overload?: () -> bool
|
|
68
|
+
|
|
69
|
+
# Yields member and overload annotations, without dedup
|
|
70
|
+
#
|
|
71
|
+
# Member annotation yields first.
|
|
72
|
+
#
|
|
73
|
+
def each_annotation: () { (AST::Annotation) -> void } -> void
|
|
74
|
+
| () -> Enumerator[AST::Annotation]
|
|
40
75
|
end
|
|
41
76
|
|
|
42
77
|
attr_reader super_method: Method?
|
|
@@ -49,21 +84,38 @@ module RBS
|
|
|
49
84
|
attr_reader comments: Array[AST::Comment]
|
|
50
85
|
|
|
51
86
|
attr_reader members: Array[method_member]
|
|
87
|
+
|
|
88
|
+
# The original method when the method is defined with `alias` syntax
|
|
52
89
|
attr_reader alias_of: Method?
|
|
53
90
|
|
|
91
|
+
# Present if the method is defined with `alias` syntax
|
|
92
|
+
attr_reader alias_member: AST::Members::Alias?
|
|
93
|
+
|
|
54
94
|
# Unused, always returns empty array
|
|
55
|
-
attr_reader extra_annotations: Array[AST::Annotation]
|
|
95
|
+
%a{deprecated} attr_reader extra_annotations: Array[AST::Annotation]
|
|
56
96
|
|
|
57
|
-
# Union of annotations given to `
|
|
97
|
+
# Union of annotations given to `def`s and `alias`, not contains annotations given to each overload
|
|
98
|
+
#
|
|
99
|
+
# The elements will be updated during `Method` object setup.
|
|
100
|
+
#
|
|
58
101
|
attr_reader annotations: Array[AST::Annotation]
|
|
59
102
|
|
|
60
103
|
# Note that the annotations given through `annotations:` keyword is ignored.
|
|
61
104
|
#
|
|
62
|
-
def initialize: (
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
105
|
+
def initialize: (
|
|
106
|
+
super_method: Method?,
|
|
107
|
+
defs: Array[TypeDef],
|
|
108
|
+
accessibility: accessibility,
|
|
109
|
+
alias_of: Method?,
|
|
110
|
+
alias_member: AST::Members::Alias?
|
|
111
|
+
) -> void
|
|
112
|
+
| %a{deprecated} (
|
|
113
|
+
super_method: Method?,
|
|
114
|
+
defs: Array[TypeDef],
|
|
115
|
+
accessibility: accessibility,
|
|
116
|
+
alias_of: Method?,
|
|
117
|
+
annotations: Array[AST::Annotation]
|
|
118
|
+
) -> void
|
|
67
119
|
|
|
68
120
|
def public?: () -> bool
|
|
69
121
|
|
|
@@ -90,7 +142,8 @@ module RBS
|
|
|
90
142
|
?defs: Array[TypeDef],
|
|
91
143
|
?accessibility: accessibility,
|
|
92
144
|
?alias_of: Method?,
|
|
93
|
-
?annotations: Array[AST::Annotation]
|
|
145
|
+
?annotations: Array[AST::Annotation],
|
|
146
|
+
?alias_member: AST::Members::Alias?
|
|
94
147
|
) -> Method
|
|
95
148
|
end
|
|
96
149
|
|