rbs 3.8.1 → 3.9.2
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/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +26 -0
- data/.github/workflows/typecheck.yml +2 -0
- data/.github/workflows/windows.yml +15 -0
- data/.rubocop.yml +13 -1
- data/CHANGELOG.md +80 -0
- data/Rakefile +20 -3
- data/config.yml +6 -0
- data/core/data.rbs +1 -1
- data/core/enumerator.rbs +14 -2
- data/core/exception.rbs +1 -1
- data/core/gc.rbs +1 -1
- data/core/hash.rbs +2 -2
- data/core/io.rbs +7 -3
- 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/docs/syntax.md +10 -5
- data/ext/rbs_extension/extconf.rb +2 -1
- data/ext/rbs_extension/location.c +32 -10
- data/ext/rbs_extension/location.h +4 -3
- data/ext/rbs_extension/main.c +22 -1
- data/ext/rbs_extension/parser.c +171 -150
- data/ext/rbs_extension/parserstate.c +54 -9
- data/ext/rbs_extension/parserstate.h +6 -4
- data/include/rbs/ruby_objs.h +6 -6
- data/include/rbs/util/rbs_constant_pool.h +219 -0
- data/lib/rbs/ast/declarations.rb +9 -4
- data/lib/rbs/ast/directives.rb +10 -0
- data/lib/rbs/ast/members.rb +2 -0
- data/lib/rbs/ast/type_param.rb +2 -12
- data/lib/rbs/cli/validate.rb +1 -0
- data/lib/rbs/cli.rb +3 -3
- data/lib/rbs/collection/config/lockfile_generator.rb +28 -7
- data/lib/rbs/collection/sources/rubygems.rb +1 -1
- data/lib/rbs/definition.rb +46 -31
- data/lib/rbs/definition_builder/ancestor_builder.rb +2 -0
- data/lib/rbs/definition_builder.rb +86 -30
- data/lib/rbs/environment.rb +33 -18
- data/lib/rbs/errors.rb +24 -0
- data/lib/rbs/locator.rb +2 -0
- data/lib/rbs/method_type.rb +2 -0
- data/lib/rbs/parser_aux.rb +38 -1
- 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/subtractor.rb +3 -3
- data/lib/rbs/test/hook.rb +2 -2
- data/lib/rbs/test/type_check.rb +7 -5
- data/lib/rbs/types.rb +45 -10
- data/lib/rbs/unit_test/spy.rb +4 -2
- data/lib/rbs/unit_test/type_assertions.rb +17 -11
- data/lib/rbs/unit_test/with_aliases.rb +3 -1
- data/lib/rbs/validator.rb +4 -0
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +10 -5
- data/lib/rbs.rb +1 -0
- data/rbs.gemspec +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/directives.rbs +17 -1
- data/sig/environment.rbs +2 -0
- data/sig/errors.rbs +19 -0
- data/sig/namespace.rbs +1 -1
- data/sig/parser.rbs +5 -1
- data/sig/subtractor.rbs +1 -1
- data/sig/test/type_check.rbs +2 -2
- data/sig/type_param.rbs +1 -1
- data/sig/typename.rbs +1 -1
- data/sig/types.rbs +1 -1
- data/sig/unit_test/spy.rbs +2 -0
- data/sig/unit_test/type_assertions.rbs +2 -0
- data/sig/validator.rbs +4 -0
- data/sig/writer.rbs +1 -1
- data/src/ruby_objs.c +12 -6
- data/src/util/rbs_constant_pool.c +342 -0
- data/stdlib/cgi/0/core.rbs +10 -0
- data/stdlib/ipaddr/0/ipaddr.rbs +8 -0
- data/stdlib/json/0/json.rbs +52 -50
- data/stdlib/net-http/0/net-http.rbs +3 -3
- data/stdlib/openssl/0/openssl.rbs +73 -73
- data/stdlib/resolv/0/resolv.rbs +8 -8
- data/stdlib/socket/0/addrinfo.rbs +1 -1
- data/stdlib/socket/0/unix_socket.rbs +4 -2
- data/stdlib/stringio/0/stringio.rbs +1 -1
- data/stdlib/uri/0/common.rbs +17 -0
- metadata +4 -7
- data/templates/include/rbs/constants.h.erb +0 -20
- data/templates/include/rbs/ruby_objs.h.erb +0 -10
- data/templates/src/constants.c.erb +0 -36
- data/templates/src/ruby_objs.c.erb +0 -27
- data/templates/template.rb +0 -122
data/lib/rbs/subtractor.rb
CHANGED
@@ -40,7 +40,7 @@ module RBS
|
|
40
40
|
name = absolute_typename(decl.new_name, context: context)
|
41
41
|
decl unless @subtrahend.module_alias?(name) || @subtrahend.module_decl?(name)
|
42
42
|
else
|
43
|
-
raise "
|
43
|
+
raise "unknown decl: #{(_ = decl).class}"
|
44
44
|
end
|
45
45
|
end.compact
|
46
46
|
end
|
@@ -51,7 +51,7 @@ module RBS
|
|
51
51
|
context = _ = [context, decl.name]
|
52
52
|
children = call(decl.each_decl.to_a, context: context) +
|
53
53
|
decl.each_member.reject { |m| member_exist?(owner, m, context: context) }
|
54
|
-
children =
|
54
|
+
children = filter_redundant_access_modifiers(children)
|
55
55
|
return nil if children.empty?
|
56
56
|
|
57
57
|
update_decl(decl, members: children)
|
@@ -145,7 +145,7 @@ module RBS
|
|
145
145
|
end
|
146
146
|
end
|
147
147
|
|
148
|
-
private def
|
148
|
+
private def filter_redundant_access_modifiers(decls)
|
149
149
|
decls = decls.dup
|
150
150
|
decls.pop while access_modifier?(decls.last)
|
151
151
|
decls = decls.map.with_index do |decl, i|
|
data/lib/rbs/test/hook.rb
CHANGED
data/lib/rbs/test/type_check.rb
CHANGED
@@ -22,8 +22,8 @@ module RBS
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def overloaded_call(method, method_name, call, errors:)
|
25
|
-
es = method.
|
26
|
-
es = method_call(method_name,
|
25
|
+
es = method.defs.map do |type_def|
|
26
|
+
es = method_call(method_name, type_def.type, call, errors: [], annotations: type_def.annotations)
|
27
27
|
|
28
28
|
if es.empty?
|
29
29
|
return errors
|
@@ -58,11 +58,11 @@ module RBS
|
|
58
58
|
errors
|
59
59
|
end
|
60
60
|
|
61
|
-
def method_call(method_name, method_type, call, errors:)
|
61
|
+
def method_call(method_name, method_type, call, errors:, annotations: [])
|
62
62
|
return errors if method_type.type.is_a?(Types::UntypedFunction)
|
63
63
|
|
64
64
|
args(method_name, method_type, method_type.type, call.method_call, errors, type_error: Errors::ArgumentTypeError, argument_error: Errors::ArgumentError)
|
65
|
-
self.return(method_name, method_type, method_type.type, call.method_call, errors, return_error: Errors::ReturnTypeError)
|
65
|
+
self.return(method_name, method_type, method_type.type, call.method_call, errors, return_error: Errors::ReturnTypeError, annotations:)
|
66
66
|
|
67
67
|
if method_type.block
|
68
68
|
case
|
@@ -106,8 +106,10 @@ module RBS
|
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
109
|
-
def return(method_name, method_type, fun, call, errors, return_error:)
|
109
|
+
def return(method_name, method_type, fun, call, errors, return_error:, annotations: [])
|
110
110
|
if call.return?
|
111
|
+
return if Test.call(call.return_value, IS_AP, NilClass) && annotations.find { |a| a.string == "implicitly-returns-nil" }
|
112
|
+
|
111
113
|
unless value(call.return_value, fun.return_type)
|
112
114
|
errors << return_error.new(klass: self_class,
|
113
115
|
method_name: method_name,
|
data/lib/rbs/types.rb
CHANGED
@@ -15,7 +15,7 @@ module RBS
|
|
15
15
|
end
|
16
16
|
|
17
17
|
module NoTypeName
|
18
|
-
def map_type_name
|
18
|
+
def map_type_name(&)
|
19
19
|
self
|
20
20
|
end
|
21
21
|
end
|
@@ -107,13 +107,15 @@ module RBS
|
|
107
107
|
class Bool < Base; end
|
108
108
|
class Void < Base; end
|
109
109
|
class Any < Base
|
110
|
-
def
|
111
|
-
|
110
|
+
def initialize(location:, todo: false)
|
111
|
+
super(location: location)
|
112
|
+
if todo
|
113
|
+
@string = "__todo__"
|
114
|
+
end
|
112
115
|
end
|
113
116
|
|
114
|
-
def
|
115
|
-
@string
|
116
|
-
self
|
117
|
+
def to_s(level=0)
|
118
|
+
@string || "untyped"
|
117
119
|
end
|
118
120
|
end
|
119
121
|
class Nil < Base; end
|
@@ -229,7 +231,7 @@ module RBS
|
|
229
231
|
|
230
232
|
include EmptyEachType
|
231
233
|
|
232
|
-
def map_type_name
|
234
|
+
def map_type_name(&)
|
233
235
|
ClassSingleton.new(
|
234
236
|
name: yield(name, location, self),
|
235
237
|
location: location
|
@@ -323,6 +325,8 @@ module RBS
|
|
323
325
|
end
|
324
326
|
|
325
327
|
def sub(s)
|
328
|
+
return self if s.empty?
|
329
|
+
|
326
330
|
self.class.new(name: name,
|
327
331
|
args: args.map {|ty| ty.sub(s) },
|
328
332
|
location: location)
|
@@ -365,6 +369,8 @@ module RBS
|
|
365
369
|
end
|
366
370
|
|
367
371
|
def sub(s)
|
372
|
+
return self if s.empty?
|
373
|
+
|
368
374
|
self.class.new(name: name,
|
369
375
|
args: args.map {|ty| ty.sub(s) },
|
370
376
|
location: location)
|
@@ -407,6 +413,8 @@ module RBS
|
|
407
413
|
end
|
408
414
|
|
409
415
|
def sub(s)
|
416
|
+
return self if s.empty?
|
417
|
+
|
410
418
|
Alias.new(name: name, args: args.map {|ty| ty.sub(s) }, location: location)
|
411
419
|
end
|
412
420
|
|
@@ -463,6 +471,8 @@ module RBS
|
|
463
471
|
end
|
464
472
|
|
465
473
|
def sub(s)
|
474
|
+
return self if s.empty?
|
475
|
+
|
466
476
|
self.class.new(types: types.map {|ty| ty.sub(s) },
|
467
477
|
location: location)
|
468
478
|
end
|
@@ -536,7 +546,7 @@ module RBS
|
|
536
546
|
end
|
537
547
|
end
|
538
548
|
else
|
539
|
-
raise ArgumentError, "only one of `:fields` or `:all_fields` is
|
549
|
+
raise ArgumentError, "only one of `:fields` or `:all_fields` is required"
|
540
550
|
end
|
541
551
|
|
542
552
|
@location = location
|
@@ -568,6 +578,8 @@ module RBS
|
|
568
578
|
end
|
569
579
|
|
570
580
|
def sub(s)
|
581
|
+
return self if s.empty?
|
582
|
+
|
571
583
|
self.class.new(
|
572
584
|
all_fields: all_fields.transform_values {|ty, required| [ty.sub(s), required] },
|
573
585
|
location: location
|
@@ -658,6 +670,8 @@ module RBS
|
|
658
670
|
end
|
659
671
|
|
660
672
|
def sub(s)
|
673
|
+
return self if s.empty?
|
674
|
+
|
661
675
|
self.class.new(type: type.sub(s), location: location)
|
662
676
|
end
|
663
677
|
|
@@ -746,15 +760,26 @@ module RBS
|
|
746
760
|
end
|
747
761
|
|
748
762
|
def sub(s)
|
763
|
+
return self if s.empty?
|
764
|
+
|
749
765
|
self.class.new(types: types.map {|ty| ty.sub(s) },
|
750
766
|
location: location)
|
751
767
|
end
|
752
768
|
|
753
769
|
def to_s(level = 0)
|
770
|
+
strs = types.map do |ty|
|
771
|
+
case ty
|
772
|
+
when Intersection
|
773
|
+
ty.to_s([1, level].max)
|
774
|
+
else
|
775
|
+
ty.to_s
|
776
|
+
end
|
777
|
+
end
|
778
|
+
|
754
779
|
if level > 0
|
755
|
-
"(#{
|
780
|
+
"(#{strs.join(" | ")})"
|
756
781
|
else
|
757
|
-
|
782
|
+
strs.join(" | ")
|
758
783
|
end
|
759
784
|
end
|
760
785
|
|
@@ -826,6 +851,8 @@ module RBS
|
|
826
851
|
end
|
827
852
|
|
828
853
|
def sub(s)
|
854
|
+
return self if s.empty?
|
855
|
+
|
829
856
|
self.class.new(types: types.map {|ty| ty.sub(s) },
|
830
857
|
location: location)
|
831
858
|
end
|
@@ -1078,6 +1105,8 @@ module RBS
|
|
1078
1105
|
end
|
1079
1106
|
|
1080
1107
|
def sub(s)
|
1108
|
+
return self if s.empty?
|
1109
|
+
|
1081
1110
|
map_type {|ty| ty.sub(s) }
|
1082
1111
|
end
|
1083
1112
|
|
@@ -1257,6 +1286,8 @@ module RBS
|
|
1257
1286
|
end
|
1258
1287
|
|
1259
1288
|
def sub(subst)
|
1289
|
+
return self if subst.empty?
|
1290
|
+
|
1260
1291
|
map_type { _1.sub(subst) }
|
1261
1292
|
end
|
1262
1293
|
|
@@ -1331,6 +1362,8 @@ module RBS
|
|
1331
1362
|
end
|
1332
1363
|
|
1333
1364
|
def sub(s)
|
1365
|
+
return self if s.empty?
|
1366
|
+
|
1334
1367
|
self.class.new(
|
1335
1368
|
type: type.sub(s),
|
1336
1369
|
required: required,
|
@@ -1400,6 +1433,8 @@ module RBS
|
|
1400
1433
|
end
|
1401
1434
|
|
1402
1435
|
def sub(s)
|
1436
|
+
return self if s.empty?
|
1437
|
+
|
1403
1438
|
self.class.new(
|
1404
1439
|
type: type.sub(s),
|
1405
1440
|
block: block&.sub(s),
|
data/lib/rbs/unit_test/spy.rb
CHANGED
@@ -20,6 +20,8 @@ module RBS
|
|
20
20
|
attr_reader :object
|
21
21
|
attr_reader :method_name
|
22
22
|
|
23
|
+
NO_RETURN = Object.new
|
24
|
+
|
23
25
|
def initialize(object:, method_name:)
|
24
26
|
@callback = -> (_) { }
|
25
27
|
@object = object
|
@@ -39,7 +41,7 @@ module RBS
|
|
39
41
|
define_method(
|
40
42
|
spy.method_name,
|
41
43
|
_ = -> (*args, &block) do
|
42
|
-
return_value =
|
44
|
+
return_value = NO_RETURN
|
43
45
|
exception = nil
|
44
46
|
block_calls = [] #: Array[Test::ArgumentsReturn]
|
45
47
|
|
@@ -105,7 +107,7 @@ module RBS
|
|
105
107
|
arguments: args,
|
106
108
|
exception: exception
|
107
109
|
)
|
108
|
-
when return_value
|
110
|
+
when ::RBS::UnitTest::Spy::WrapSpy::NO_RETURN != return_value
|
109
111
|
Test::ArgumentsReturn.return(
|
110
112
|
arguments: args,
|
111
113
|
value: return_value
|
@@ -163,7 +163,7 @@ module RBS
|
|
163
163
|
end
|
164
164
|
end
|
165
165
|
|
166
|
-
last_trace = trace.last or raise
|
166
|
+
last_trace = trace.last or raise "empty trace"
|
167
167
|
|
168
168
|
yield(mt, last_trace, result, exception)
|
169
169
|
end
|
@@ -182,9 +182,9 @@ module RBS
|
|
182
182
|
|
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
|
-
|
186
|
-
all_errors =
|
187
|
-
assert all_errors.any? {|es| es.empty? }, "Call trace does not match one of method definitions:\n #{trace.inspect}\n #{
|
185
|
+
method_defs = method_defs(method)
|
186
|
+
all_errors = method_defs.map {|t| typecheck.method_call(method, t.type, trace, errors: [], annotations: t.each_annotation.to_a) }
|
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
|
190
190
|
|
@@ -219,30 +219,36 @@ module RBS
|
|
219
219
|
assert_operator exception, :is_a?, ::Exception
|
220
220
|
assert_empty errors.map {|x| RBS::Test::Errors.to_string(x) }
|
221
221
|
|
222
|
-
|
223
|
-
all_errors =
|
224
|
-
assert all_errors.all? {|es| es.size > 0 }, "Call trace unexpectedly matches one of method definitions:\n #{trace.inspect}\n #{
|
222
|
+
method_defs = method_defs(method)
|
223
|
+
all_errors = method_defs.map {|t| typecheck.method_call(method, t.type, trace, errors: [], annotations: t.each_annotation.to_a) }
|
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
|
227
227
|
end
|
228
228
|
end
|
229
229
|
|
230
|
-
def
|
230
|
+
def method_defs(method)
|
231
231
|
type, definition = target
|
232
232
|
|
233
233
|
case type
|
234
234
|
when Types::ClassInstance
|
235
235
|
subst = RBS::Substitution.build(definition.type_params, type.args)
|
236
|
-
definition.methods[method].
|
237
|
-
|
236
|
+
definition.methods[method].defs.map do |type_def|
|
237
|
+
type_def.update(
|
238
|
+
type: type_def.type.sub(subst)
|
239
|
+
)
|
238
240
|
end
|
239
241
|
when Types::ClassSingleton
|
240
|
-
definition.methods[method].
|
242
|
+
definition.methods[method].defs
|
241
243
|
else
|
242
244
|
raise
|
243
245
|
end
|
244
246
|
end
|
245
247
|
|
248
|
+
def method_types(method)
|
249
|
+
method_defs(method).map(&:type)
|
250
|
+
end
|
251
|
+
|
246
252
|
def allows_error(*errors)
|
247
253
|
yield
|
248
254
|
rescue *errors => exn
|
@@ -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/validator.rb
CHANGED
data/lib/rbs/version.rb
CHANGED
data/lib/rbs/writer.rb
CHANGED
@@ -77,14 +77,19 @@ module RBS
|
|
77
77
|
end
|
78
78
|
|
79
79
|
def write(contents)
|
80
|
-
|
80
|
+
resolves = contents.select { _1.is_a?(AST::Directives::ResolveTypeNames) } #: Array[AST::Directives::ResolveTypeNames]
|
81
|
+
uses = contents.select {|c| c.is_a?(AST::Directives::Use) } #: Array[AST::Directives::Use]
|
81
82
|
decls = contents.select {|c| c.is_a?(AST::Declarations::Base) } #: Array[AST::Declarations::t]
|
82
83
|
|
83
|
-
|
84
|
-
|
84
|
+
if first_resolves = resolves.first
|
85
|
+
puts "# resolve-type-names: #{first_resolves.value}"
|
86
|
+
puts
|
85
87
|
end
|
86
88
|
|
87
|
-
|
89
|
+
uses.each do |dir|
|
90
|
+
write_use_directive(dir)
|
91
|
+
end
|
92
|
+
puts unless uses.empty?
|
88
93
|
|
89
94
|
[nil, *decls].each_cons(2) do |prev, decl|
|
90
95
|
raise unless decl
|
@@ -94,7 +99,7 @@ module RBS
|
|
94
99
|
end
|
95
100
|
end
|
96
101
|
|
97
|
-
def
|
102
|
+
def write_use_directive(dir)
|
98
103
|
clauses = dir.clauses.map do |clause|
|
99
104
|
case clause
|
100
105
|
when AST::Directives::Use::SingleClause
|
data/lib/rbs.rb
CHANGED
data/rbs.gemspec
CHANGED
@@ -30,7 +30,7 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
31
31
|
`git ls-files -z`.split("\x0").reject do |f|
|
32
32
|
[
|
33
|
-
%r{^(test|spec|features|bin|steep|benchmark)/},
|
33
|
+
%r{^(test|spec|features|bin|steep|benchmark|templates)/},
|
34
34
|
/Gemfile/
|
35
35
|
].any? {|r| f.match(r) }
|
36
36
|
end
|
@@ -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
|
|
data/sig/definition_builder.rbs
CHANGED
@@ -105,7 +105,15 @@ module RBS
|
|
105
105
|
|
106
106
|
def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t) -> Location[untyped, untyped]?
|
107
107
|
|
108
|
-
def
|
108
|
+
def validate_variable: (Definition::Variable) -> void
|
109
|
+
|
110
|
+
def insert_variable: (
|
111
|
+
TypeName,
|
112
|
+
Hash[Symbol, Definition::Variable],
|
113
|
+
name: Symbol,
|
114
|
+
type: Types::t,
|
115
|
+
source: Definition::Variable::source
|
116
|
+
) -> void
|
109
117
|
|
110
118
|
# Add method definition to `methods`, which will be merged to `class_definition` after defining all methods at this *level* -- class, module, or interface
|
111
119
|
#
|
@@ -142,11 +150,17 @@ module RBS
|
|
142
150
|
Hash[Symbol, Definition::Method]? self_type_methods,
|
143
151
|
) -> void
|
144
152
|
|
145
|
-
# Updates `definition` with methods and variables of `type_name` that can be a module or a class
|
153
|
+
# Updates `definition` with methods and instance variables of `type_name` that can be a module or a class
|
146
154
|
#
|
147
155
|
# It processes includes and prepends recursively.
|
156
|
+
# If `define_class_vars:` is falsy, it skips inserting class variables.
|
148
157
|
#
|
149
|
-
def define_instance: (
|
158
|
+
def define_instance: (
|
159
|
+
Definition definition,
|
160
|
+
TypeName type_name,
|
161
|
+
Substitution subst,
|
162
|
+
define_class_vars: bool
|
163
|
+
) -> void
|
150
164
|
|
151
165
|
# Updates `definition` with methods defined in an interface `type_name`
|
152
166
|
#
|