rbs 2.2.2 → 2.3.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/dependabot.yml +4 -0
- data/.github/workflows/comments.yml +2 -2
- data/.github/workflows/ruby.yml +1 -1
- data/.gitignore +0 -1
- data/CHANGELOG.md +43 -0
- data/Gemfile +2 -1
- data/Gemfile.lock +117 -0
- data/Rakefile +1 -1
- data/core/dir.rbs +1 -1
- data/core/enumerator.rbs +1 -1
- data/core/false_class.rbs +1 -1
- data/core/integer.rbs +4 -4
- data/core/io/wait.rbs +1 -1
- data/core/module.rbs +21 -2
- data/core/nil_class.rbs +7 -5
- data/core/object.rbs +9 -0
- data/core/trace_point.rbs +42 -3
- data/core/true_class.rbs +1 -1
- data/ext/rbs_extension/constants.c +1 -1
- data/ext/rbs_extension/extconf.rb +1 -1
- data/ext/rbs_extension/location.c +1 -1
- data/ext/rbs_extension/parser.c +4 -3
- data/ext/rbs_extension/parserstate.c +2 -2
- data/ext/rbs_extension/unescape.c +1 -1
- data/lib/rbs/ast/members.rb +2 -1
- data/lib/rbs/collection/installer.rb +4 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +4 -2
- data/lib/rbs/definition_builder/method_builder.rb +1 -1
- data/lib/rbs/definition_builder.rb +2 -2
- data/lib/rbs/environment.rb +24 -12
- data/lib/rbs/locator.rb +24 -15
- data/lib/rbs/prototype/rb.rb +17 -6
- data/lib/rbs/resolver/constant_resolver.rb +192 -0
- data/lib/rbs/resolver/type_name_resolver.rb +55 -0
- data/lib/rbs/type_name.rb +15 -0
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +2 -0
- data/schema/members.json +4 -1
- data/sig/environment.rbs +28 -21
- data/sig/environment_loader.rbs +23 -23
- data/sig/locator.rbs +2 -0
- data/sig/manifest.yaml +8 -0
- data/sig/resolver/constant_resolver.rbs +93 -0
- data/sig/resolver/context.rbs +34 -0
- data/sig/resolver/type_name_resolver.rbs +31 -0
- data/sig/typename.rbs +9 -3
- data/stdlib/bigdecimal/0/big_decimal.rbs +135 -0
- data/stdlib/erb/0/erb.rbs +237 -0
- data/stdlib/optparse/0/optparse.rbs +20 -18
- data/stdlib/prime/0/prime.rbs +115 -4
- data/stdlib/rubygems/0/version.rbs +159 -1
- data/steep/Gemfile.lock +13 -15
- metadata +10 -3
@@ -140,7 +140,7 @@ module RBS
|
|
140
140
|
case entry
|
141
141
|
when Environment::ClassEntry, Environment::ModuleEntry
|
142
142
|
ancestors = ancestor_builder.instance_ancestors(type_name)
|
143
|
-
args = Types::Variable.
|
143
|
+
args = entry.type_params.map {|param| Types::Variable.new(name: param.name, location: param.location) }
|
144
144
|
self_type = Types::ClassInstance.new(name: type_name, args: args, location: nil)
|
145
145
|
|
146
146
|
Definition.new(type_name: type_name, entry: entry, self_type: self_type, ancestors: ancestors).tap do |definition|
|
@@ -425,7 +425,7 @@ module RBS
|
|
425
425
|
type: method_type.type.with_return_type(
|
426
426
|
Types::ClassInstance.new(
|
427
427
|
name: type_name,
|
428
|
-
args: Types::Variable.
|
428
|
+
args: entry.type_params.map {|param| Types::Variable.new(name: param.name, location: param.location) },
|
429
429
|
location: nil
|
430
430
|
)
|
431
431
|
)
|
data/lib/rbs/environment.rb
CHANGED
@@ -9,19 +9,23 @@ module RBS
|
|
9
9
|
attr_reader :global_decls
|
10
10
|
|
11
11
|
module ContextUtil
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
end
|
18
|
-
end
|
12
|
+
def calculate_context(decls)
|
13
|
+
decls.each.with_object([Namespace.root]) do |decl, array|
|
14
|
+
first = array.first or raise
|
15
|
+
array.unshift(first + decl.name.to_namespace)
|
16
|
+
end
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
22
20
|
class MultiEntry
|
23
21
|
D = _ = Struct.new(:decl, :outer, keyword_init: true) do
|
22
|
+
# @implements D[M]
|
23
|
+
|
24
24
|
include ContextUtil
|
25
|
+
|
26
|
+
def context
|
27
|
+
@context ||= calculate_context(outer + [decl])
|
28
|
+
end
|
25
29
|
end
|
26
30
|
|
27
31
|
attr_reader :name
|
@@ -39,8 +43,6 @@ module RBS
|
|
39
43
|
|
40
44
|
def validate_type_params
|
41
45
|
unless decls.empty?
|
42
|
-
# @type var hd_decl: MultiEntry::D[module_decl]
|
43
|
-
# @type var tl_decls: Array[MultiEntry::D[module_decl]]
|
44
46
|
hd_decl, *tl_decls = decls
|
45
47
|
raise unless hd_decl
|
46
48
|
|
@@ -50,7 +52,7 @@ module RBS
|
|
50
52
|
tl_params = tl_decl.decl.type_params
|
51
53
|
|
52
54
|
unless compatible_params?(hd_params, tl_params)
|
53
|
-
raise GenericParameterMismatchError.new(name: name, decl: tl_decl.decl)
|
55
|
+
raise GenericParameterMismatchError.new(name: name, decl: _ = tl_decl.decl)
|
54
56
|
end
|
55
57
|
end
|
56
58
|
end
|
@@ -86,6 +88,12 @@ module RBS
|
|
86
88
|
end
|
87
89
|
end
|
88
90
|
|
91
|
+
def foo
|
92
|
+
a = [1].sample()
|
93
|
+
return unless a
|
94
|
+
a + 1
|
95
|
+
end
|
96
|
+
|
89
97
|
class ClassEntry < MultiEntry
|
90
98
|
def primary
|
91
99
|
@primary ||= begin
|
@@ -96,8 +104,6 @@ module RBS
|
|
96
104
|
end
|
97
105
|
|
98
106
|
class SingleEntry
|
99
|
-
include ContextUtil
|
100
|
-
|
101
107
|
attr_reader :name
|
102
108
|
attr_reader :outer
|
103
109
|
attr_reader :decl
|
@@ -107,6 +113,12 @@ module RBS
|
|
107
113
|
@decl = decl
|
108
114
|
@outer = outer
|
109
115
|
end
|
116
|
+
|
117
|
+
include ContextUtil
|
118
|
+
|
119
|
+
def context
|
120
|
+
@context = calculate_context(outer)
|
121
|
+
end
|
110
122
|
end
|
111
123
|
|
112
124
|
def initialize
|
data/lib/rbs/locator.rb
CHANGED
@@ -41,11 +41,7 @@ module RBS
|
|
41
41
|
case decl
|
42
42
|
when AST::Declarations::Class
|
43
43
|
decl.type_params.each do |param|
|
44
|
-
|
45
|
-
array.unshift(param)
|
46
|
-
find_in_loc(pos, array: array, location: param.location)
|
47
|
-
return true
|
48
|
-
end
|
44
|
+
find_in_type_param(pos, type_param: param, array: array) and return true
|
49
45
|
end
|
50
46
|
|
51
47
|
if super_class = decl.super_class
|
@@ -66,11 +62,7 @@ module RBS
|
|
66
62
|
|
67
63
|
when AST::Declarations::Module
|
68
64
|
decl.type_params.each do |param|
|
69
|
-
|
70
|
-
array.unshift(param)
|
71
|
-
find_in_loc(pos, array: array, location: param.location)
|
72
|
-
return true
|
73
|
-
end
|
65
|
+
find_in_type_param(pos, type_param: param, array: array) and return true
|
74
66
|
end
|
75
67
|
|
76
68
|
decl.self_types.each do |self_type|
|
@@ -91,11 +83,7 @@ module RBS
|
|
91
83
|
|
92
84
|
when AST::Declarations::Interface
|
93
85
|
decl.type_params.each do |param|
|
94
|
-
|
95
|
-
array.unshift(param)
|
96
|
-
find_in_loc(pos, array: array, location: param.location)
|
97
|
-
return true
|
98
|
-
end
|
86
|
+
find_in_type_param(pos, type_param: param, array: array) and return true
|
99
87
|
end
|
100
88
|
|
101
89
|
decl.members.each do |member|
|
@@ -144,6 +132,10 @@ module RBS
|
|
144
132
|
if test_loc(pos, location: method_type.location)
|
145
133
|
array.unshift(method_type)
|
146
134
|
|
135
|
+
method_type.type_params.each do |param|
|
136
|
+
find_in_type_param(pos, type_param: param, array: array) and return true
|
137
|
+
end
|
138
|
+
|
147
139
|
method_type.each_type do |type|
|
148
140
|
find_in_type(pos, array: array, type: type) and break
|
149
141
|
end
|
@@ -154,6 +146,23 @@ module RBS
|
|
154
146
|
end
|
155
147
|
end
|
156
148
|
|
149
|
+
def find_in_type_param(pos, type_param:, array:)
|
150
|
+
if test_loc(pos, location: type_param.location)
|
151
|
+
array.unshift(type_param)
|
152
|
+
|
153
|
+
if upper_bound = type_param.upper_bound
|
154
|
+
find_in_type(pos, type: upper_bound, array: array) or
|
155
|
+
find_in_loc(pos, location: type_param.location, array: array)
|
156
|
+
else
|
157
|
+
find_in_loc(pos, location: type_param.location, array: array)
|
158
|
+
end
|
159
|
+
|
160
|
+
true
|
161
|
+
else
|
162
|
+
false
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
157
166
|
def find_in_type(pos, type:, array:)
|
158
167
|
if test_loc(pos, location: type.location)
|
159
168
|
array.unshift(type)
|
data/lib/rbs/prototype/rb.rb
CHANGED
@@ -338,7 +338,7 @@ module RBS
|
|
338
338
|
# Give up type prediction when node is MASGN.
|
339
339
|
Types::Bases::Any.new(location: nil)
|
340
340
|
else
|
341
|
-
|
341
|
+
literal_to_type(value_node)
|
342
342
|
end
|
343
343
|
decls << AST::Declarations::Constant.new(
|
344
344
|
name: const_name,
|
@@ -408,7 +408,7 @@ module RBS
|
|
408
408
|
name = lvasgn.children[0]
|
409
409
|
fun.optional_positionals << Types::Function::Param.new(
|
410
410
|
name: name,
|
411
|
-
type:
|
411
|
+
type: param_type(lvasgn.children[1])
|
412
412
|
)
|
413
413
|
end
|
414
414
|
|
@@ -429,7 +429,7 @@ module RBS
|
|
429
429
|
when nil, :NODE_SPECIAL_REQUIRED_KEYWORD
|
430
430
|
fun.required_keywords[name] = Types::Function::Param.new(name: name, type: untyped)
|
431
431
|
when RubyVM::AbstractSyntaxTree::Node
|
432
|
-
fun.optional_keywords[name] = Types::Function::Param.new(name: name, type:
|
432
|
+
fun.optional_keywords[name] = Types::Function::Param.new(name: name, type: param_type(value))
|
433
433
|
else
|
434
434
|
raise "Unexpected keyword arg value: #{value}"
|
435
435
|
end
|
@@ -477,9 +477,9 @@ module RBS
|
|
477
477
|
when :DREGX
|
478
478
|
BuiltinNames::Regexp.instance_type
|
479
479
|
when :TRUE
|
480
|
-
|
480
|
+
Types::Literal.new(literal: true, location: nil)
|
481
481
|
when :FALSE
|
482
|
-
|
482
|
+
Types::Literal.new(literal: false, location: nil)
|
483
483
|
when :NIL
|
484
484
|
Types::Bases::Nil.new(location: nil)
|
485
485
|
when :LIT
|
@@ -536,6 +536,14 @@ module RBS
|
|
536
536
|
value_type = types_to_union_type(value_types)
|
537
537
|
BuiltinNames::Hash.instance_type([key_type, value_type])
|
538
538
|
end
|
539
|
+
when :CALL
|
540
|
+
receiver, method_name, * = node.children
|
541
|
+
case method_name
|
542
|
+
when :freeze, :tap, :itself, :dup, :clone, :taint, :untaint, :extend
|
543
|
+
literal_to_type(receiver)
|
544
|
+
else
|
545
|
+
default
|
546
|
+
end
|
539
547
|
else
|
540
548
|
untyped
|
541
549
|
end
|
@@ -570,7 +578,7 @@ module RBS
|
|
570
578
|
end
|
571
579
|
end
|
572
580
|
|
573
|
-
def
|
581
|
+
def param_type(node, default: Types::Bases::Any.new(location: nil))
|
574
582
|
case node.type
|
575
583
|
when :LIT
|
576
584
|
case node.children[0]
|
@@ -602,6 +610,9 @@ module RBS
|
|
602
610
|
end
|
603
611
|
end
|
604
612
|
|
613
|
+
# backward compatible
|
614
|
+
alias node_type param_type
|
615
|
+
|
605
616
|
def private
|
606
617
|
@private ||= AST::Members::Private.new(location: nil)
|
607
618
|
end
|
@@ -0,0 +1,192 @@
|
|
1
|
+
module RBS
|
2
|
+
module Resolver
|
3
|
+
class ConstantResolver
|
4
|
+
class Table
|
5
|
+
attr_reader :children_table, :toplevel
|
6
|
+
attr_reader :constants_table
|
7
|
+
|
8
|
+
def initialize(environment)
|
9
|
+
@children_table = {}
|
10
|
+
@toplevel = {}
|
11
|
+
|
12
|
+
@constants_table = {}
|
13
|
+
|
14
|
+
environment.class_decls.each_key do |name|
|
15
|
+
children_table[name] = {}
|
16
|
+
end
|
17
|
+
|
18
|
+
environment.class_decls.each do |name, entry|
|
19
|
+
unless name.namespace.empty?
|
20
|
+
parent = name.namespace.to_type_name
|
21
|
+
|
22
|
+
table = children_table[parent] or raise
|
23
|
+
constant = constant_of_module(name, entry)
|
24
|
+
else
|
25
|
+
table = toplevel
|
26
|
+
constant = constant_of_module(name, entry)
|
27
|
+
end
|
28
|
+
|
29
|
+
table[name.name] = constant
|
30
|
+
constants_table[name] = constant
|
31
|
+
end
|
32
|
+
|
33
|
+
environment.constant_decls.each do |name, entry|
|
34
|
+
unless name.namespace.empty?
|
35
|
+
parent = name.namespace.to_type_name
|
36
|
+
|
37
|
+
table = children_table[parent] or raise
|
38
|
+
constant = constant_of_constant(name, entry)
|
39
|
+
else
|
40
|
+
table = toplevel
|
41
|
+
constant = constant_of_constant(name, entry)
|
42
|
+
end
|
43
|
+
|
44
|
+
table[name.name] = constant
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def children(name)
|
49
|
+
children_table[name]
|
50
|
+
end
|
51
|
+
|
52
|
+
def constant(name)
|
53
|
+
constants_table[name]
|
54
|
+
end
|
55
|
+
|
56
|
+
def constant_of_module(name, entry)
|
57
|
+
type = Types::ClassSingleton.new(
|
58
|
+
name: name,
|
59
|
+
location: nil
|
60
|
+
)
|
61
|
+
|
62
|
+
Constant.new(name: name, type: type, entry: entry)
|
63
|
+
end
|
64
|
+
|
65
|
+
def constant_of_constant(name, entry)
|
66
|
+
Constant.new(name: name, type: entry.decl.type, entry: entry)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
attr_reader :builder, :table
|
71
|
+
attr_reader :context_constants_cache, :child_constants_cache
|
72
|
+
|
73
|
+
def initialize(builder:)
|
74
|
+
@builder = builder
|
75
|
+
@table = Table.new(builder.env)
|
76
|
+
@context_constants_cache = {}
|
77
|
+
@child_constants_cache = {}
|
78
|
+
end
|
79
|
+
|
80
|
+
def resolve(name, context:)
|
81
|
+
cs = constants(context) or raise "Broken context is given"
|
82
|
+
cs[name]
|
83
|
+
end
|
84
|
+
|
85
|
+
def constants(context)
|
86
|
+
unless context_constants_cache.key?(context)
|
87
|
+
load_context_constants(context)
|
88
|
+
end
|
89
|
+
|
90
|
+
context_constants_cache[context]
|
91
|
+
end
|
92
|
+
|
93
|
+
def resolve_child(module_name, name)
|
94
|
+
children(module_name)[name]
|
95
|
+
end
|
96
|
+
|
97
|
+
def children(module_name)
|
98
|
+
unless child_constants_cache.key?(module_name)
|
99
|
+
load_child_constants(module_name)
|
100
|
+
end
|
101
|
+
|
102
|
+
child_constants_cache[module_name] or raise
|
103
|
+
end
|
104
|
+
|
105
|
+
def load_context_constants(context)
|
106
|
+
# @type var consts: Hash[Symbol, Constant]
|
107
|
+
consts = {}
|
108
|
+
|
109
|
+
if context
|
110
|
+
if last = context[1]
|
111
|
+
constants_from_ancestors(last, constants: consts)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
constants_from_context(context, constants: consts) or return
|
115
|
+
constants_itself(context, constants: consts)
|
116
|
+
|
117
|
+
context_constants_cache[context] = consts
|
118
|
+
end
|
119
|
+
|
120
|
+
def load_child_constants(name)
|
121
|
+
# @type var constants: Hash[Symbol, Constant]
|
122
|
+
constants = {}
|
123
|
+
|
124
|
+
if table.children(name)
|
125
|
+
builder.ancestor_builder.instance_ancestors(name).ancestors.each do |ancestor|
|
126
|
+
if ancestor.is_a?(Definition::Ancestor::Instance)
|
127
|
+
if ancestor.name == BuiltinNames::Object.name
|
128
|
+
if name != BuiltinNames::Object.name
|
129
|
+
next
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
case ancestor.source
|
134
|
+
when AST::Members::Include, :super, nil
|
135
|
+
consts = table.children(ancestor.name) or raise
|
136
|
+
constants.merge!(consts)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
child_constants_cache[name] = constants
|
143
|
+
end
|
144
|
+
|
145
|
+
def constants_from_context(context, constants:)
|
146
|
+
if context
|
147
|
+
parent, last = context
|
148
|
+
|
149
|
+
constants_from_context(parent, constants: constants) or return false
|
150
|
+
|
151
|
+
if last
|
152
|
+
consts = table.children(last) or return false
|
153
|
+
constants.merge!(consts)
|
154
|
+
end
|
155
|
+
else
|
156
|
+
constants.merge!(table.toplevel)
|
157
|
+
end
|
158
|
+
|
159
|
+
true
|
160
|
+
end
|
161
|
+
|
162
|
+
def constants_from_ancestors(module_name, constants:)
|
163
|
+
builder.ancestor_builder.instance_ancestors(module_name).ancestors.each do |ancestor|
|
164
|
+
if ancestor.is_a?(Definition::Ancestor::Instance)
|
165
|
+
case ancestor.source
|
166
|
+
when AST::Members::Include, :super, nil
|
167
|
+
consts = table.children(ancestor.name) or raise
|
168
|
+
constants.merge!(consts)
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
174
|
+
def constants_itself(context, constants:)
|
175
|
+
if context
|
176
|
+
_, typename = context
|
177
|
+
|
178
|
+
if typename
|
179
|
+
if (ns = typename.namespace).empty?
|
180
|
+
constant = table.toplevel[typename.name] or raise
|
181
|
+
else
|
182
|
+
hash = table.children(ns.to_type_name) or raise
|
183
|
+
constant = hash[typename.name]
|
184
|
+
end
|
185
|
+
|
186
|
+
constants[typename.name] = constant
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module RBS
|
2
|
+
module Resolver
|
3
|
+
class TypeNameResolver
|
4
|
+
attr_reader :all_names
|
5
|
+
attr_reader :cache
|
6
|
+
|
7
|
+
def initialize(env)
|
8
|
+
@all_names = Set[]
|
9
|
+
@cache = {}
|
10
|
+
|
11
|
+
all_names.merge(env.class_decls.keys)
|
12
|
+
all_names.merge(env.interface_decls.keys)
|
13
|
+
all_names.merge(env.alias_decls.keys)
|
14
|
+
end
|
15
|
+
|
16
|
+
def try_cache(query)
|
17
|
+
cache.fetch(query) do
|
18
|
+
result = yield
|
19
|
+
cache[query] = result
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def resolve(type_name, context:)
|
24
|
+
if type_name.absolute?
|
25
|
+
return type_name
|
26
|
+
end
|
27
|
+
|
28
|
+
try_cache([type_name, context]) do
|
29
|
+
resolve_in(type_name, context)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def resolve_in(type_name, context)
|
34
|
+
if context
|
35
|
+
parent, child = context
|
36
|
+
case child
|
37
|
+
when false
|
38
|
+
resolve_in(type_name, parent)
|
39
|
+
when TypeName
|
40
|
+
name = type_name.with_prefix(child.to_namespace)
|
41
|
+
has_name?(name) || resolve_in(type_name, parent)
|
42
|
+
end
|
43
|
+
else
|
44
|
+
has_name?(type_name.absolute!)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def has_name?(full_name)
|
49
|
+
if all_names.include?(full_name)
|
50
|
+
full_name
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/lib/rbs/type_name.rb
CHANGED
@@ -69,6 +69,21 @@ module RBS
|
|
69
69
|
def with_prefix(namespace)
|
70
70
|
self.class.new(namespace: namespace + self.namespace, name: name)
|
71
71
|
end
|
72
|
+
|
73
|
+
def split
|
74
|
+
namespace.path + [name]
|
75
|
+
end
|
76
|
+
|
77
|
+
def +(other)
|
78
|
+
if other.absolute?
|
79
|
+
other
|
80
|
+
else
|
81
|
+
TypeName.new(
|
82
|
+
namespace: self.to_namespace + other.namespace,
|
83
|
+
name: other.name
|
84
|
+
)
|
85
|
+
end
|
86
|
+
end
|
72
87
|
end
|
73
88
|
end
|
74
89
|
|
data/lib/rbs/version.rb
CHANGED
data/lib/rbs.rb
CHANGED
@@ -28,6 +28,8 @@ require "rbs/definition_builder/method_builder"
|
|
28
28
|
require "rbs/variance_calculator"
|
29
29
|
require "rbs/substitution"
|
30
30
|
require "rbs/constant"
|
31
|
+
require "rbs/resolver/constant_resolver"
|
32
|
+
require "rbs/resolver/type_name_resolver"
|
31
33
|
require "rbs/constant_table"
|
32
34
|
require "rbs/ast/comment"
|
33
35
|
require "rbs/writer"
|
data/schema/members.json
CHANGED
@@ -37,9 +37,12 @@
|
|
37
37
|
},
|
38
38
|
"overload": {
|
39
39
|
"type": "boolean"
|
40
|
+
},
|
41
|
+
"visibility": {
|
42
|
+
"enum": ["public", "private", null]
|
40
43
|
}
|
41
44
|
},
|
42
|
-
"required": ["member", "kind", "types", "comment", "annotations", "location"]
|
45
|
+
"required": ["member", "kind", "types", "comment", "annotations", "location", "visibility"]
|
43
46
|
},
|
44
47
|
"variable": {
|
45
48
|
"title": "Declaration for instance variables and class variables",
|
data/sig/environment.rbs
CHANGED
@@ -2,32 +2,40 @@ module RBS
|
|
2
2
|
class Environment
|
3
3
|
type module_decl = AST::Declarations::Class | AST::Declarations::Module
|
4
4
|
|
5
|
-
interface
|
6
|
-
def
|
5
|
+
interface _ModuleOrClass
|
6
|
+
def name: () -> TypeName
|
7
7
|
|
8
|
-
def
|
8
|
+
def type_params: () -> Array[AST::TypeParam]
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
def
|
11
|
+
interface _NamedDecl
|
12
|
+
def name: () -> TypeName
|
13
|
+
end
|
14
|
+
|
15
|
+
module ContextUtil
|
16
|
+
def calculate_context: (Array[_NamedDecl]) -> Array[Namespace]
|
13
17
|
end
|
14
18
|
|
15
|
-
class MultiEntry
|
16
|
-
class D[M]
|
19
|
+
class MultiEntry[M < _ModuleOrClass]
|
20
|
+
class D[M < _ModuleOrClass]
|
17
21
|
attr_reader decl: M
|
18
22
|
attr_reader outer: Array[module_decl]
|
19
23
|
|
20
|
-
def initialize: (decl:
|
24
|
+
def initialize: (decl: M, outer: Array[module_decl]) -> void
|
21
25
|
|
22
26
|
include ContextUtil
|
27
|
+
|
28
|
+
@context: Array[Namespace]
|
29
|
+
|
30
|
+
def context: () -> Array[Namespace]
|
23
31
|
end
|
24
32
|
|
25
33
|
attr_reader name: TypeName
|
26
|
-
attr_reader decls: Array[
|
34
|
+
attr_reader decls: Array[D[M]]
|
27
35
|
|
28
36
|
def initialize: (name: TypeName) -> void
|
29
37
|
|
30
|
-
def insert: (decl:
|
38
|
+
def insert: (decl: M, outer: Array[module_decl]) -> void
|
31
39
|
|
32
40
|
def validate_type_params: () -> void
|
33
41
|
|
@@ -35,29 +43,28 @@ module RBS
|
|
35
43
|
|
36
44
|
def type_params: () -> Array[AST::TypeParam]
|
37
45
|
|
38
|
-
def primary: () -> D[
|
46
|
+
def primary: () -> D[M]
|
39
47
|
end
|
40
48
|
|
41
|
-
class ModuleEntry < MultiEntry
|
42
|
-
attr_reader decls: Array[MultiEntry::D[AST::Declarations::Module]]
|
43
|
-
attr_reader primary: MultiEntry::D[AST::Declarations::Module]
|
44
|
-
|
49
|
+
class ModuleEntry < MultiEntry[AST::Declarations::Module]
|
45
50
|
def self_types: () -> Array[AST::Declarations::Module::Self]
|
46
51
|
end
|
47
52
|
|
48
|
-
class ClassEntry < MultiEntry
|
49
|
-
attr_reader decls: Array[MultiEntry::D[AST::Declarations::Class]]
|
50
|
-
attr_reader primary: MultiEntry::D[AST::Declarations::Class]
|
53
|
+
class ClassEntry < MultiEntry[AST::Declarations::Class]
|
51
54
|
end
|
52
55
|
|
53
56
|
class SingleEntry[N, D]
|
54
|
-
include ContextUtil
|
55
|
-
|
56
57
|
attr_reader name: N
|
57
58
|
attr_reader decl: D
|
58
59
|
attr_reader outer: Array[module_decl]
|
59
60
|
|
60
61
|
def initialize: (name: N, decl: D, outer: Array[module_decl]) -> void
|
62
|
+
|
63
|
+
include ContextUtil
|
64
|
+
|
65
|
+
@context: Array[Namespace]
|
66
|
+
|
67
|
+
def context: () -> Array[Namespace]
|
61
68
|
end
|
62
69
|
|
63
70
|
# Top level declarations.
|
@@ -75,7 +82,7 @@ module RBS
|
|
75
82
|
|
76
83
|
def self.from_loader: (EnvironmentLoader) -> Environment
|
77
84
|
|
78
|
-
def cache_name: [
|
85
|
+
def cache_name: [N, D] (Hash[N, SingleEntry[N, D]] cache, name: N, decl: D, outer: Array[module_decl]) -> SingleEntry[N, D]
|
79
86
|
|
80
87
|
def insert_decl: (AST::Declarations::t, outer: Array[module_decl], namespace: Namespace) -> void
|
81
88
|
|