rbs 0.4.0 → 0.9.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 +7 -1
- data/.gitignore +1 -1
- data/CHANGELOG.md +35 -0
- data/Gemfile +14 -0
- data/README.md +86 -47
- data/Rakefile +53 -21
- data/bin/rbs-prof +9 -0
- data/bin/run_in_md.rb +49 -0
- data/docs/stdlib.md +0 -2
- data/docs/syntax.md +6 -3
- data/goodcheck.yml +65 -0
- data/lib/rbs.rb +3 -0
- data/lib/rbs/ast/comment.rb +6 -0
- data/lib/rbs/ast/declarations.rb +106 -13
- data/lib/rbs/ast/members.rb +41 -17
- data/lib/rbs/cli.rb +317 -121
- data/lib/rbs/constant.rb +4 -4
- data/lib/rbs/constant_table.rb +51 -45
- data/lib/rbs/definition.rb +175 -59
- data/lib/rbs/definition_builder.rb +814 -604
- data/lib/rbs/environment.rb +352 -210
- data/lib/rbs/environment_walker.rb +14 -23
- data/lib/rbs/errors.rb +184 -3
- data/lib/rbs/factory.rb +14 -0
- data/lib/rbs/location.rb +15 -0
- data/lib/rbs/parser.y +100 -34
- data/lib/rbs/prototype/rb.rb +101 -113
- data/lib/rbs/prototype/rbi.rb +5 -3
- data/lib/rbs/prototype/runtime.rb +11 -7
- data/lib/rbs/substitution.rb +12 -1
- data/lib/rbs/test.rb +82 -3
- data/lib/rbs/test/errors.rb +5 -1
- data/lib/rbs/test/hook.rb +133 -259
- data/lib/rbs/test/observer.rb +17 -0
- data/lib/rbs/test/setup.rb +35 -19
- data/lib/rbs/test/setup_helper.rb +29 -0
- data/lib/rbs/test/spy.rb +0 -321
- data/lib/rbs/test/tester.rb +116 -0
- data/lib/rbs/test/type_check.rb +43 -7
- data/lib/rbs/type_name_resolver.rb +58 -0
- data/lib/rbs/types.rb +94 -2
- data/lib/rbs/validator.rb +55 -0
- data/lib/rbs/variance_calculator.rb +12 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +127 -91
- data/rbs.gemspec +0 -10
- data/schema/decls.json +36 -10
- data/schema/members.json +3 -0
- data/stdlib/benchmark/benchmark.rbs +151 -151
- data/stdlib/builtin/enumerable.rbs +3 -3
- data/stdlib/builtin/file.rbs +0 -3
- data/stdlib/builtin/io.rbs +4 -4
- data/stdlib/builtin/proc.rbs +1 -2
- data/stdlib/builtin/thread.rbs +2 -2
- data/stdlib/csv/csv.rbs +4 -6
- data/stdlib/fiber/fiber.rbs +1 -1
- data/stdlib/json/json.rbs +7 -1
- data/stdlib/logger/formatter.rbs +23 -0
- data/stdlib/logger/log_device.rbs +39 -0
- data/stdlib/logger/logger.rbs +507 -0
- data/stdlib/logger/period.rbs +7 -0
- data/stdlib/logger/severity.rbs +8 -0
- data/stdlib/mutex_m/mutex_m.rbs +77 -0
- data/stdlib/pathname/pathname.rbs +6 -6
- data/stdlib/prime/integer-extension.rbs +1 -1
- data/stdlib/prime/prime.rbs +44 -44
- data/stdlib/pty/pty.rbs +159 -0
- data/stdlib/tmpdir/tmpdir.rbs +1 -1
- metadata +19 -130
- data/lib/rbs/test/test_helper.rb +0 -183
data/lib/rbs/environment.rb
CHANGED
@@ -3,279 +3,421 @@ module RBS
|
|
3
3
|
attr_reader :buffers
|
4
4
|
attr_reader :declarations
|
5
5
|
|
6
|
-
attr_reader :
|
7
|
-
attr_reader :
|
8
|
-
attr_reader :
|
9
|
-
attr_reader :
|
10
|
-
attr_reader :
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
@name_to_alias = {}
|
6
|
+
attr_reader :class_decls
|
7
|
+
attr_reader :interface_decls
|
8
|
+
attr_reader :alias_decls
|
9
|
+
attr_reader :constant_decls
|
10
|
+
attr_reader :global_decls
|
11
|
+
|
12
|
+
module ContextUtil
|
13
|
+
def context
|
14
|
+
@context ||= begin
|
15
|
+
(outer + [decl]).each.with_object([Namespace.root]) do |decl, array|
|
16
|
+
array.unshift(array.first + decl.name.to_namespace)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
21
20
|
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
22
|
+
class MultiEntry
|
23
|
+
D = Struct.new(:decl, :outer, keyword_init: true) do
|
24
|
+
include ContextUtil
|
25
|
+
end
|
26
26
|
|
27
|
-
|
28
|
-
|
29
|
-
@name_to_constant = other.name_to_constant.dup
|
30
|
-
@name_to_global = other.name_to_global.dup
|
31
|
-
@name_to_alias = other.name_to_alias.dup
|
32
|
-
end
|
27
|
+
attr_reader :name
|
28
|
+
attr_reader :decls
|
33
29
|
|
34
|
-
|
35
|
-
|
36
|
-
|
30
|
+
def initialize(name:)
|
31
|
+
@name = name
|
32
|
+
@decls = []
|
37
33
|
end
|
38
|
-
cache[name] = decl
|
39
|
-
end
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
when AST::Declarations::Class, AST::Declarations::Module, AST::Declarations::Interface
|
45
|
-
cache_name name_to_decl, name: decl.name.absolute!, decl: decl
|
46
|
-
when AST::Declarations::Extension
|
47
|
-
yield_self do
|
48
|
-
name = decl.name.absolute!
|
49
|
-
exts = name_to_extensions.fetch(name) do
|
50
|
-
name_to_extensions[name] = []
|
51
|
-
end
|
52
|
-
exts << decl
|
53
|
-
end
|
54
|
-
when AST::Declarations::Alias
|
55
|
-
cache_name name_to_alias, name: decl.name.absolute!, decl: decl
|
56
|
-
when AST::Declarations::Constant
|
57
|
-
cache_name name_to_constant, name: decl.name.absolute!, decl: decl
|
58
|
-
when AST::Declarations::Global
|
59
|
-
cache_name name_to_global, name: decl.name, decl: decl
|
35
|
+
def insert(decl:, outer:)
|
36
|
+
decls << D.new(decl: decl, outer: outer)
|
37
|
+
@primary = nil
|
60
38
|
end
|
61
|
-
end
|
62
39
|
|
63
|
-
|
64
|
-
|
65
|
-
|
40
|
+
def validate_type_params
|
41
|
+
unless decls.empty?
|
42
|
+
hd_decl, *tl_decls = decls
|
43
|
+
hd_params = hd_decl.decl.type_params
|
44
|
+
hd_names = hd_params.params.map(&:name)
|
66
45
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
46
|
+
tl_decls.each do |tl_decl|
|
47
|
+
tl_params = tl_decl.decl.type_params
|
48
|
+
|
49
|
+
unless hd_params.size == tl_params.size && hd_params == tl_params.rename_to(hd_names)
|
50
|
+
raise GenericParameterMismatchError.new(name: name, decl: tl_decl.decl)
|
51
|
+
end
|
52
|
+
end
|
71
53
|
end
|
72
|
-
else
|
73
|
-
enum_for :each_decl
|
74
54
|
end
|
75
|
-
end
|
76
55
|
|
77
|
-
|
78
|
-
|
79
|
-
name_to_constant.each do |name, decl|
|
80
|
-
yield name, decl
|
81
|
-
end
|
82
|
-
else
|
83
|
-
enum_for :each_constant
|
56
|
+
def type_params
|
57
|
+
primary.decl.type_params
|
84
58
|
end
|
85
59
|
end
|
86
60
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
end
|
92
|
-
else
|
93
|
-
enum_for :each_global
|
61
|
+
class ModuleEntry < MultiEntry
|
62
|
+
def self_types
|
63
|
+
decls.flat_map do |d|
|
64
|
+
d.decl.self_types
|
65
|
+
end.uniq
|
94
66
|
end
|
95
|
-
end
|
96
67
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
68
|
+
def primary
|
69
|
+
@primary ||= begin
|
70
|
+
validate_type_params
|
71
|
+
decls.first
|
72
|
+
end
|
102
73
|
end
|
103
74
|
end
|
104
75
|
|
105
|
-
|
106
|
-
|
76
|
+
class ClassEntry < MultiEntry
|
77
|
+
def primary
|
78
|
+
@primary ||= begin
|
79
|
+
validate_type_params
|
80
|
+
decls.find {|d| d.decl.super_class } || decls.first
|
81
|
+
end
|
82
|
+
end
|
107
83
|
end
|
108
84
|
|
109
|
-
|
110
|
-
|
111
|
-
|
85
|
+
class SingleEntry
|
86
|
+
include ContextUtil
|
87
|
+
|
88
|
+
attr_reader :name
|
89
|
+
attr_reader :outer
|
90
|
+
attr_reader :decl
|
91
|
+
|
92
|
+
def initialize(name:, decl:, outer:)
|
93
|
+
@name = name
|
94
|
+
@decl = decl
|
95
|
+
@outer = outer
|
112
96
|
end
|
113
97
|
end
|
114
98
|
|
115
|
-
def
|
116
|
-
|
99
|
+
def initialize
|
100
|
+
@buffers = []
|
101
|
+
@declarations = []
|
102
|
+
|
103
|
+
@class_decls = {}
|
104
|
+
@interface_decls = {}
|
105
|
+
@alias_decls = {}
|
106
|
+
@constant_decls = {}
|
107
|
+
@global_decls = {}
|
117
108
|
end
|
118
109
|
|
119
|
-
def
|
120
|
-
|
110
|
+
def initialize_copy(other)
|
111
|
+
@buffers = other.buffers.dup
|
112
|
+
@declarations = other.declarations.dup
|
113
|
+
|
114
|
+
@class_decls = other.class_decls.dup
|
115
|
+
@interface_decls = other.interface_decls.dup
|
116
|
+
@alias_decls = other.alias_decls.dup
|
117
|
+
@constant_decls = other.constant_decls.dup
|
118
|
+
@global_decls = other.global_decls.dup
|
121
119
|
end
|
122
120
|
|
123
|
-
def
|
124
|
-
|
121
|
+
def self.from_loader(loader)
|
122
|
+
self.new.tap do |env|
|
123
|
+
loader.load(env: env)
|
124
|
+
end
|
125
125
|
end
|
126
126
|
|
127
|
-
def
|
128
|
-
if
|
129
|
-
(
|
130
|
-
else
|
131
|
-
enum_for :each_extension, type_name
|
127
|
+
def cache_name(cache, name:, decl:, outer:)
|
128
|
+
if cache.key?(name)
|
129
|
+
raise DuplicatedDeclarationError.new(name, decl, cache[name].decl)
|
132
130
|
end
|
131
|
+
|
132
|
+
cache[name] = SingleEntry.new(name: name, decl: decl, outer: outer)
|
133
133
|
end
|
134
134
|
|
135
|
-
def
|
136
|
-
|
135
|
+
def insert_decl(decl, outer:, namespace:)
|
136
|
+
case decl
|
137
|
+
when AST::Declarations::Class, AST::Declarations::Module
|
138
|
+
name = decl.name.with_prefix(namespace)
|
137
139
|
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
absolute_name = name.with_prefix(namespace)
|
140
|
+
if constant_decls.key?(name)
|
141
|
+
raise DuplicatedDeclarationError.new(name, decl, constant_decls[name].decl)
|
142
|
+
end
|
142
143
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
parent = namespace.parent
|
150
|
-
absolute_type_name_in environment, name: name, namespace: parent
|
144
|
+
unless class_decls.key?(name)
|
145
|
+
case decl
|
146
|
+
when AST::Declarations::Class
|
147
|
+
class_decls[name] ||= ClassEntry.new(name: name)
|
148
|
+
when AST::Declarations::Module
|
149
|
+
class_decls[name] ||= ModuleEntry.new(name: name)
|
151
150
|
end
|
152
151
|
end
|
152
|
+
|
153
|
+
existing_entry = class_decls[name]
|
154
|
+
|
155
|
+
case
|
156
|
+
when decl.is_a?(AST::Declarations::Module) && existing_entry.is_a?(ModuleEntry)
|
157
|
+
# OK
|
158
|
+
when decl.is_a?(AST::Declarations::Class) && existing_entry.is_a?(ClassEntry)
|
159
|
+
# OK
|
160
|
+
else
|
161
|
+
raise DuplicatedDeclarationError.new(name, decl, existing_entry.primary.decl)
|
162
|
+
end
|
163
|
+
|
164
|
+
existing_entry.insert(decl: decl, outer: outer)
|
165
|
+
|
166
|
+
prefix = outer + [decl]
|
167
|
+
ns = name.to_namespace
|
168
|
+
decl.each_decl do |d|
|
169
|
+
insert_decl(d, outer: prefix, namespace: ns)
|
170
|
+
end
|
171
|
+
|
172
|
+
when AST::Declarations::Interface
|
173
|
+
cache_name interface_decls, name: decl.name.with_prefix(namespace), decl: decl, outer: outer
|
174
|
+
|
175
|
+
when AST::Declarations::Alias
|
176
|
+
cache_name alias_decls, name: decl.name.with_prefix(namespace), decl: decl, outer: outer
|
177
|
+
|
178
|
+
when AST::Declarations::Constant
|
179
|
+
name = decl.name.with_prefix(namespace)
|
180
|
+
|
181
|
+
if class_decls.key?(name)
|
182
|
+
raise DuplicatedDeclarationError.new(name, decl, class_decls[name].decls[0].decl)
|
183
|
+
end
|
184
|
+
|
185
|
+
cache_name constant_decls, name: name, decl: decl, outer: outer
|
186
|
+
|
187
|
+
when AST::Declarations::Global
|
188
|
+
cache_name global_decls, name: decl.name, decl: decl, outer: outer
|
189
|
+
|
190
|
+
when AST::Declarations::Extension
|
191
|
+
RBS.logger.warn "#{Location.to_string decl.location} Extension construct is deprecated: use class/module syntax instead"
|
153
192
|
end
|
154
193
|
end
|
155
194
|
|
156
|
-
def
|
157
|
-
|
158
|
-
|
195
|
+
def <<(decl)
|
196
|
+
declarations << decl
|
197
|
+
insert_decl(decl, outer: [], namespace: Namespace.root)
|
198
|
+
self
|
159
199
|
end
|
160
200
|
|
161
|
-
def
|
162
|
-
|
163
|
-
|
164
|
-
end
|
201
|
+
def resolve_type_names
|
202
|
+
resolver = TypeNameResolver.from_env(self)
|
203
|
+
env = Environment.new()
|
165
204
|
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
end
|
205
|
+
declarations.each do |decl|
|
206
|
+
env << resolve_declaration(resolver, decl, outer: [], prefix: Namespace.root)
|
207
|
+
end
|
170
208
|
|
171
|
-
|
172
|
-
absolute_name = case
|
173
|
-
when type_name.class?
|
174
|
-
absolute_class_name(type_name, namespace: namespace)
|
175
|
-
when type_name.alias?
|
176
|
-
absolute_alias_name(type_name, namespace: namespace)
|
177
|
-
when type_name.interface?
|
178
|
-
absolute_interface_name(type_name, namespace: namespace)
|
179
|
-
end
|
180
|
-
|
181
|
-
absolute_name || yield(type_name)
|
209
|
+
env
|
182
210
|
end
|
183
211
|
|
184
|
-
def
|
185
|
-
if
|
186
|
-
|
187
|
-
|
188
|
-
|
212
|
+
def resolve_declaration(resolver, decl, outer:, prefix:)
|
213
|
+
if decl.is_a?(AST::Declarations::Global)
|
214
|
+
return AST::Declarations::Global.new(
|
215
|
+
name: decl.name,
|
216
|
+
type: absolute_type(resolver, decl.type, context: [Namespace.root]),
|
217
|
+
location: decl.location,
|
218
|
+
comment: decl.comment
|
219
|
+
)
|
220
|
+
end
|
221
|
+
|
222
|
+
context = (outer + [decl]).each.with_object([Namespace.root]) do |decl, array|
|
223
|
+
array.unshift(array.first + decl.name.to_namespace)
|
224
|
+
end
|
225
|
+
|
226
|
+
case decl
|
227
|
+
when AST::Declarations::Class
|
228
|
+
outer_ = outer + [decl]
|
229
|
+
prefix_ = prefix + decl.name.to_namespace
|
230
|
+
AST::Declarations::Class.new(
|
231
|
+
name: decl.name.with_prefix(prefix),
|
232
|
+
type_params: decl.type_params,
|
233
|
+
super_class: decl.super_class&.yield_self do |super_class|
|
234
|
+
AST::Declarations::Class::Super.new(
|
235
|
+
name: absolute_type_name(resolver, super_class.name, context: context),
|
236
|
+
args: super_class.args.map {|type| absolute_type(resolver, type, context: context) }
|
237
|
+
)
|
238
|
+
end,
|
239
|
+
members: decl.members.map do |member|
|
240
|
+
case member
|
241
|
+
when AST::Members::Base
|
242
|
+
resolve_member(resolver, member, context: context)
|
243
|
+
when AST::Declarations::Base
|
244
|
+
resolve_declaration(
|
245
|
+
resolver,
|
246
|
+
member,
|
247
|
+
outer: outer_,
|
248
|
+
prefix: prefix_
|
249
|
+
)
|
250
|
+
end
|
251
|
+
end,
|
252
|
+
location: decl.location,
|
253
|
+
annotations: decl.annotations,
|
254
|
+
comment: decl.comment
|
255
|
+
)
|
256
|
+
when AST::Declarations::Module
|
257
|
+
outer_ = outer + [decl]
|
258
|
+
prefix_ = prefix + decl.name.to_namespace
|
259
|
+
AST::Declarations::Module.new(
|
260
|
+
name: decl.name.with_prefix(prefix),
|
261
|
+
type_params: decl.type_params,
|
262
|
+
self_types: decl.self_types.map do |module_self|
|
263
|
+
AST::Declarations::Module::Self.new(
|
264
|
+
name: absolute_type_name(resolver, module_self.name, context: context),
|
265
|
+
args: module_self.args.map {|type| absolute_type(resolver, type, context: context) },
|
266
|
+
location: module_self.location
|
267
|
+
)
|
268
|
+
end,
|
269
|
+
members: decl.members.map do |member|
|
270
|
+
case member
|
271
|
+
when AST::Members::Base
|
272
|
+
resolve_member(resolver, member, context: context)
|
273
|
+
when AST::Declarations::Base
|
274
|
+
resolve_declaration(
|
275
|
+
resolver,
|
276
|
+
member,
|
277
|
+
outer: outer_,
|
278
|
+
prefix: prefix_
|
279
|
+
)
|
280
|
+
end
|
281
|
+
end,
|
282
|
+
location: decl.location,
|
283
|
+
annotations: decl.annotations,
|
284
|
+
comment: decl.comment
|
285
|
+
)
|
286
|
+
when AST::Declarations::Interface
|
287
|
+
AST::Declarations::Interface.new(
|
288
|
+
name: decl.name.with_prefix(prefix),
|
289
|
+
type_params: decl.type_params,
|
290
|
+
members: decl.members.map do |member|
|
291
|
+
resolve_member(resolver, member, context: context)
|
292
|
+
end,
|
293
|
+
comment: decl.comment,
|
294
|
+
location: decl.location,
|
295
|
+
annotations: decl.annotations
|
296
|
+
)
|
297
|
+
when AST::Declarations::Alias
|
298
|
+
AST::Declarations::Alias.new(
|
299
|
+
name: decl.name.with_prefix(prefix),
|
300
|
+
type: absolute_type(resolver, decl.type, context: context),
|
301
|
+
location: decl.location,
|
302
|
+
annotations: decl.annotations,
|
303
|
+
comment: decl.comment
|
304
|
+
)
|
305
|
+
|
306
|
+
when AST::Declarations::Constant
|
307
|
+
AST::Declarations::Constant.new(
|
308
|
+
name: decl.name.with_prefix(prefix),
|
309
|
+
type: absolute_type(resolver, decl.type, context: context),
|
310
|
+
location: decl.location,
|
311
|
+
comment: decl.comment
|
312
|
+
)
|
189
313
|
end
|
190
314
|
end
|
191
315
|
|
192
|
-
def
|
193
|
-
case
|
194
|
-
when
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
316
|
+
def resolve_member(resolver, member, context:)
|
317
|
+
case member
|
318
|
+
when AST::Members::MethodDefinition
|
319
|
+
AST::Members::MethodDefinition.new(
|
320
|
+
name: member.name,
|
321
|
+
kind: member.kind,
|
322
|
+
types: member.types.map do |type|
|
323
|
+
type.map_type {|ty| absolute_type(resolver, ty, context: context) }
|
324
|
+
end,
|
325
|
+
comment: member.comment,
|
326
|
+
overload: member.overload?,
|
327
|
+
annotations: member.annotations,
|
328
|
+
attributes: member.attributes,
|
329
|
+
location: member.location
|
330
|
+
)
|
331
|
+
when AST::Members::AttrAccessor
|
332
|
+
AST::Members::AttrAccessor.new(
|
333
|
+
name: member.name,
|
334
|
+
type: absolute_type(resolver, member.type, context: context),
|
335
|
+
annotations: member.annotations,
|
336
|
+
comment: member.comment,
|
337
|
+
location: member.location,
|
338
|
+
ivar_name: member.ivar_name
|
339
|
+
)
|
340
|
+
when AST::Members::AttrReader
|
341
|
+
AST::Members::AttrReader.new(
|
342
|
+
name: member.name,
|
343
|
+
type: absolute_type(resolver, member.type, context: context),
|
344
|
+
annotations: member.annotations,
|
345
|
+
comment: member.comment,
|
346
|
+
location: member.location,
|
347
|
+
ivar_name: member.ivar_name
|
348
|
+
)
|
349
|
+
when AST::Members::AttrWriter
|
350
|
+
AST::Members::AttrWriter.new(
|
351
|
+
name: member.name,
|
352
|
+
type: absolute_type(resolver, member.type, context: context),
|
353
|
+
annotations: member.annotations,
|
354
|
+
comment: member.comment,
|
355
|
+
location: member.location,
|
356
|
+
ivar_name: member.ivar_name
|
222
357
|
)
|
223
|
-
when
|
224
|
-
|
225
|
-
|
226
|
-
|
358
|
+
when AST::Members::InstanceVariable
|
359
|
+
AST::Members::InstanceVariable.new(
|
360
|
+
name: member.name,
|
361
|
+
type: absolute_type(resolver, member.type, context: context),
|
362
|
+
comment: member.comment,
|
363
|
+
location: member.location
|
227
364
|
)
|
228
|
-
when
|
229
|
-
|
230
|
-
|
231
|
-
|
365
|
+
when AST::Members::ClassInstanceVariable
|
366
|
+
AST::Members::ClassInstanceVariable.new(
|
367
|
+
name: member.name,
|
368
|
+
type: absolute_type(resolver, member.type, context: context),
|
369
|
+
comment: member.comment,
|
370
|
+
location: member.location
|
232
371
|
)
|
233
|
-
when
|
234
|
-
|
235
|
-
|
236
|
-
|
372
|
+
when AST::Members::ClassVariable
|
373
|
+
AST::Members::ClassVariable.new(
|
374
|
+
name: member.name,
|
375
|
+
type: absolute_type(resolver, member.type, context: context),
|
376
|
+
comment: member.comment,
|
377
|
+
location: member.location
|
237
378
|
)
|
238
|
-
when
|
239
|
-
|
240
|
-
|
241
|
-
|
379
|
+
when AST::Members::Include
|
380
|
+
AST::Members::Include.new(
|
381
|
+
name: absolute_type_name(resolver, member.name, context: context),
|
382
|
+
args: member.args.map {|type| absolute_type(resolver, type, context: context) },
|
383
|
+
comment: member.comment,
|
384
|
+
location: member.location,
|
385
|
+
annotations: member.annotations
|
242
386
|
)
|
243
|
-
when
|
244
|
-
|
245
|
-
|
246
|
-
|
387
|
+
when AST::Members::Extend
|
388
|
+
AST::Members::Extend.new(
|
389
|
+
name: absolute_type_name(resolver, member.name, context: context),
|
390
|
+
args: member.args.map {|type| absolute_type(resolver, type, context: context) },
|
391
|
+
comment: member.comment,
|
392
|
+
location: member.location,
|
393
|
+
annotations: member.annotations
|
394
|
+
)
|
395
|
+
when AST::Members::Prepend
|
396
|
+
AST::Members::Prepend.new(
|
397
|
+
name: absolute_type_name(resolver, member.name, context: context),
|
398
|
+
args: member.args.map {|type| absolute_type(resolver, type, context: context) },
|
399
|
+
comment: member.comment,
|
400
|
+
location: member.location,
|
401
|
+
annotations: member.annotations
|
247
402
|
)
|
248
403
|
else
|
249
|
-
|
404
|
+
member
|
250
405
|
end
|
251
406
|
end
|
252
407
|
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
when Types::ClassInstance, Types::Interface
|
257
|
-
if type.name.namespace.relative?
|
258
|
-
type = absolute_type(type, namespace: namespace) do |type|
|
259
|
-
NoTypeFoundError.check!(type.name.absolute!, env: self, location: type.location)
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
decl = find_class(type.name)
|
264
|
-
unless decl
|
265
|
-
raise NoTypeFoundError.new(type_name: type.name, location: type.location)
|
266
|
-
end
|
408
|
+
def absolute_type_name(resolver, type_name, context:)
|
409
|
+
resolver.resolve(type_name, context: context) || type_name
|
410
|
+
end
|
267
411
|
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
params: decl.type_params,
|
272
|
-
location: type.location
|
273
|
-
)
|
412
|
+
def absolute_type(resolver, type, context:)
|
413
|
+
type.map_type_name do |name|
|
414
|
+
absolute_type_name(resolver, name, context: context)
|
274
415
|
end
|
416
|
+
end
|
275
417
|
|
276
|
-
|
277
|
-
|
278
|
-
|
418
|
+
def inspect
|
419
|
+
ivars = %i[@buffers @declarations @class_decls @interface_decls @alias_decls @constant_decls @global_decls]
|
420
|
+
"\#<RBS::Environment #{ivars.map { |iv| "#{iv}=(#{instance_variable_get(iv).size} items)"}.join(' ')}>"
|
279
421
|
end
|
280
422
|
end
|
281
423
|
end
|