rbs 3.6.1 → 3.9.5
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/comments.yml +2 -2
- data/.github/workflows/dependabot.yml +1 -1
- data/.github/workflows/ruby.yml +34 -10
- data/.github/workflows/windows.yml +20 -3
- data/.gitignore +1 -0
- data/.rubocop.yml +26 -1
- data/CHANGELOG.md +241 -0
- data/Rakefile +54 -4
- data/config.yml +317 -0
- data/core/array.rbs +1756 -1591
- data/core/basic_object.rbs +38 -35
- data/core/comparable.rbs +1 -1
- data/core/complex.rbs +166 -94
- data/core/data.rbs +2 -2
- data/core/dir.rbs +2 -18
- data/core/encoding.rbs +12 -32
- data/core/enumerable.rbs +270 -266
- data/core/enumerator.rbs +14 -4
- data/core/env.rbs +1 -1
- data/core/errno.rbs +33 -16
- data/core/errors.rbs +6 -2
- data/core/exception.rbs +342 -167
- data/core/fiber.rbs +3 -2
- data/core/file.rbs +26 -75
- data/core/float.rbs +125 -72
- data/core/gc.rbs +158 -42
- data/core/hash.rbs +122 -143
- data/core/integer.rbs +79 -50
- data/core/io/buffer.rbs +49 -43
- data/core/io.rbs +108 -151
- data/core/kernel.rbs +341 -209
- data/core/match_data.rbs +76 -2
- data/core/math.rbs +0 -36
- data/core/method.rbs +2 -2
- data/core/module.rbs +32 -27
- data/core/nil_class.rbs +2 -2
- data/core/numeric.rbs +101 -104
- data/core/object.rbs +1 -5
- data/core/object_space/weak_key_map.rbs +3 -4
- data/core/object_space.rbs +3 -3
- data/core/proc.rbs +82 -14
- data/core/process.rbs +110 -58
- data/core/ractor.rbs +57 -4
- data/core/range.rbs +114 -87
- data/core/rational.rbs +0 -2
- data/core/rbs/unnamed/argf.rbs +237 -36
- data/core/rbs/unnamed/env_class.rbs +35 -53
- data/core/rbs/unnamed/random.rbs +1 -2
- data/core/regexp.rbs +10 -56
- data/core/ruby_vm.rbs +88 -9
- data/core/rubygems/config_file.rbs +3 -0
- data/core/rubygems/errors.rbs +3 -6
- data/core/rubygems/platform.rbs +0 -9
- data/core/rubygems/rubygems.rbs +3 -6
- data/core/rubygems/version.rbs +8 -8
- data/core/set.rbs +4 -16
- data/core/string.rbs +271 -264
- data/core/struct.rbs +6 -18
- data/core/symbol.rbs +14 -21
- data/core/thread.rbs +32 -35
- data/core/time.rbs +131 -50
- data/core/trace_point.rbs +124 -113
- data/core/true_class.rbs +0 -1
- data/core/unbound_method.rbs +1 -1
- data/core/warning.rbs +9 -2
- data/docs/architecture.md +1 -1
- data/docs/syntax.md +17 -10
- data/ext/rbs_extension/extconf.rb +11 -0
- data/ext/rbs_extension/location.c +61 -29
- data/ext/rbs_extension/location.h +4 -3
- data/ext/rbs_extension/main.c +23 -1
- data/ext/rbs_extension/parser.c +506 -517
- data/ext/rbs_extension/parserstate.c +109 -30
- data/ext/rbs_extension/parserstate.h +6 -4
- data/ext/rbs_extension/rbs_extension.h +1 -10
- data/{ext/rbs_extension → include/rbs}/constants.h +21 -19
- data/include/rbs/ruby_objs.h +72 -0
- data/include/rbs/util/rbs_constant_pool.h +219 -0
- data/include/rbs.h +7 -0
- data/lib/rbs/annotate/annotations.rb +3 -3
- data/lib/rbs/annotate/rdoc_source.rb +2 -2
- 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/diff.rb +3 -3
- data/lib/rbs/cli/validate.rb +2 -1
- data/lib/rbs/cli.rb +16 -16
- data/lib/rbs/collection/config/lockfile_generator.rb +58 -8
- data/lib/rbs/collection/config.rb +5 -3
- data/lib/rbs/collection/sources/rubygems.rb +1 -1
- data/lib/rbs/collection.rb +1 -0
- data/lib/rbs/definition.rb +51 -34
- data/lib/rbs/definition_builder/ancestor_builder.rb +5 -3
- data/lib/rbs/definition_builder.rb +83 -24
- data/lib/rbs/environment.rb +33 -18
- data/lib/rbs/environment_loader.rb +6 -1
- 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/namespace.rb +1 -0
- data/lib/rbs/parser_aux.rb +40 -3
- data/lib/rbs/prototype/rb.rb +20 -12
- data/lib/rbs/prototype/rbi.rb +11 -6
- data/lib/rbs/prototype/runtime/value_object_generator.rb +7 -5
- data/lib/rbs/prototype/runtime.rb +7 -5
- data/lib/rbs/subtractor.rb +3 -3
- data/lib/rbs/test/hook.rb +47 -42
- data/lib/rbs/test/type_check.rb +7 -5
- data/lib/rbs/type_name.rb +14 -9
- data/lib/rbs/types.rb +63 -14
- data/lib/rbs/unit_test/spy.rb +4 -2
- data/lib/rbs/unit_test/type_assertions.rb +19 -13
- data/lib/rbs/unit_test/with_aliases.rb +3 -1
- data/lib/rbs/validator.rb +7 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +10 -5
- data/lib/rbs.rb +1 -0
- data/lib/rdoc_plugin/parser.rb +2 -2
- data/rbs.gemspec +6 -2
- data/sig/ancestor_graph.rbs +5 -5
- data/sig/annotate/rdoc_source.rbs +2 -0
- data/sig/cli.rbs +2 -0
- data/sig/collection/config/lockfile_generator.rbs +9 -1
- data/sig/declarations.rbs +10 -3
- data/sig/definition.rbs +80 -12
- data/sig/definition_builder.rbs +18 -4
- data/sig/directives.rbs +17 -1
- data/sig/environment.rbs +3 -1
- data/sig/errors.rbs +19 -0
- data/sig/namespace.rbs +2 -3
- data/sig/parser.rbs +5 -1
- data/sig/prototype/rb.rbs +1 -1
- data/sig/resolver/constant_resolver.rbs +2 -2
- data/sig/resolver/context.rbs +1 -1
- data/sig/subtractor.rbs +1 -1
- data/sig/test/type_check.rbs +2 -2
- data/sig/type_alias_dependency.rbs +2 -2
- data/sig/type_alias_regularity.rbs +6 -6
- data/sig/type_param.rbs +4 -4
- data/sig/typename.rbs +8 -5
- 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/use_map.rbs +1 -1
- data/sig/validator.rbs +6 -2
- data/sig/vendorer.rbs +1 -1
- data/sig/writer.rbs +1 -1
- data/{ext/rbs_extension → src}/constants.c +35 -36
- data/src/ruby_objs.c +799 -0
- data/src/util/rbs_constant_pool.c +342 -0
- data/stdlib/base64/0/base64.rbs +0 -9
- data/stdlib/benchmark/0/benchmark.rbs +11 -2
- data/stdlib/bigdecimal/0/big_decimal.rbs +26 -182
- data/stdlib/cgi/0/core.rbs +60 -3
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/coverage/0/coverage.rbs +0 -3
- data/stdlib/csv/0/csv.rbs +18 -58
- data/stdlib/csv/0/manifest.yaml +1 -0
- data/stdlib/date/0/date.rbs +27 -42
- data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -6
- data/stdlib/digest/0/digest.rbs +25 -2
- data/stdlib/erb/0/erb.rbs +0 -1
- data/stdlib/etc/0/etc.rbs +51 -34
- data/stdlib/fileutils/0/fileutils.rbs +3 -44
- data/stdlib/io-console/0/io-console.rbs +69 -15
- data/stdlib/ipaddr/0/ipaddr.rbs +16 -4
- data/stdlib/json/0/json.rbs +107 -120
- data/stdlib/logger/0/log_device.rbs +1 -1
- data/stdlib/logger/0/logger.rbs +3 -18
- data/stdlib/minitest/0/kernel.rbs +2 -2
- data/stdlib/minitest/0/minitest/abstract_reporter.rbs +4 -1
- data/stdlib/minitest/0/minitest/assertion.rbs +1 -0
- data/stdlib/minitest/0/minitest/assertions.rbs +58 -13
- data/stdlib/minitest/0/minitest/backtrace_filter.rbs +7 -0
- data/stdlib/minitest/0/minitest/bench_spec.rbs +8 -8
- data/stdlib/minitest/0/minitest/benchmark.rbs +17 -16
- data/stdlib/minitest/0/minitest/compress.rbs +13 -0
- data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
- data/stdlib/minitest/0/minitest/mock.rbs +9 -5
- data/stdlib/minitest/0/minitest/parallel/executor.rbs +4 -0
- data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +0 -1
- data/stdlib/minitest/0/minitest/pride_io.rbs +8 -0
- data/stdlib/minitest/0/minitest/pride_lol.rbs +2 -0
- data/stdlib/minitest/0/minitest/progress_reporter.rbs +1 -1
- data/stdlib/minitest/0/minitest/reportable.rbs +2 -0
- data/stdlib/minitest/0/minitest/runnable.rbs +33 -1
- data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +1 -1
- data/stdlib/minitest/0/minitest/spec/dsl.rbs +10 -6
- data/stdlib/minitest/0/minitest/spec.rbs +1 -1
- data/stdlib/minitest/0/minitest/statistics_reporter.rbs +5 -0
- data/stdlib/minitest/0/minitest/summary_reporter.rbs +0 -7
- data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +1 -1
- data/stdlib/minitest/0/minitest/test.rbs +7 -14
- data/stdlib/minitest/0/minitest/unexpected_error.rbs +2 -0
- data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
- data/stdlib/minitest/0/minitest/unit.rbs +1 -2
- data/stdlib/minitest/0/minitest.rbs +41 -892
- data/stdlib/monitor/0/monitor.rbs +13 -4
- data/stdlib/net-http/0/net-http.rbs +42 -109
- data/stdlib/nkf/0/nkf.rbs +30 -0
- data/stdlib/objspace/0/objspace.rbs +1 -2
- data/stdlib/observable/0/observable.rbs +1 -1
- data/stdlib/open-uri/0/manifest.yaml +1 -0
- data/stdlib/open-uri/0/open-uri.rbs +52 -0
- data/stdlib/open3/0/open3.rbs +0 -8
- data/stdlib/openssl/0/manifest.yaml +1 -0
- data/stdlib/openssl/0/openssl.rbs +235 -143
- data/stdlib/optparse/0/optparse.rbs +58 -18
- data/stdlib/pathname/0/pathname.rbs +2 -8
- data/stdlib/pp/0/pp.rbs +3 -1
- data/stdlib/prettyprint/0/prettyprint.rbs +0 -4
- data/stdlib/pstore/0/pstore.rbs +0 -6
- data/stdlib/psych/0/core_ext.rbs +12 -0
- data/stdlib/psych/0/psych.rbs +15 -4
- data/stdlib/pty/0/pty.rbs +46 -4
- data/stdlib/rdoc/0/code_object.rbs +0 -4
- data/stdlib/rdoc/0/markup.rbs +10 -12
- data/stdlib/rdoc/0/rdoc.rbs +13 -8
- data/stdlib/resolv/0/resolv.rbs +21 -12
- data/stdlib/ripper/0/ripper.rbs +0 -2
- data/stdlib/securerandom/0/securerandom.rbs +7 -2
- data/stdlib/shellwords/0/shellwords.rbs +11 -12
- data/stdlib/singleton/0/singleton.rbs +0 -1
- data/stdlib/socket/0/addrinfo.rbs +1 -2
- data/stdlib/socket/0/basic_socket.rbs +0 -5
- data/stdlib/socket/0/socket.rbs +32 -27
- data/stdlib/socket/0/tcp_server.rbs +0 -3
- data/stdlib/socket/0/tcp_socket.rbs +36 -3
- data/stdlib/socket/0/udp_socket.rbs +0 -1
- data/stdlib/socket/0/unix_server.rbs +0 -3
- data/stdlib/socket/0/unix_socket.rbs +4 -2
- data/{core/string_io.rbs → stdlib/stringio/0/stringio.rbs} +1 -1
- data/stdlib/strscan/0/string_scanner.rbs +1265 -422
- data/stdlib/tempfile/0/tempfile.rbs +135 -28
- data/stdlib/time/0/time.rbs +48 -35
- data/stdlib/timeout/0/timeout.rbs +11 -8
- data/stdlib/tmpdir/0/tmpdir.rbs +10 -3
- data/stdlib/tsort/0/tsort.rbs +0 -4
- data/stdlib/uri/0/common.rbs +28 -30
- data/stdlib/uri/0/ftp.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +22 -18
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
- data/stdlib/zlib/0/buf_error.rbs +1 -70
- data/stdlib/zlib/0/data_error.rbs +1 -70
- data/stdlib/zlib/0/deflate.rbs +8 -72
- data/stdlib/zlib/0/error.rbs +1 -70
- data/stdlib/zlib/0/gzip_file/crc_error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/length_error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/no_footer.rbs +2 -105
- data/stdlib/zlib/0/gzip_file.rbs +1 -71
- data/stdlib/zlib/0/gzip_reader.rbs +3 -74
- data/stdlib/zlib/0/gzip_writer.rbs +1 -70
- data/stdlib/zlib/0/inflate.rbs +4 -71
- data/stdlib/zlib/0/mem_error.rbs +1 -70
- data/stdlib/zlib/0/need_dict.rbs +1 -70
- data/stdlib/zlib/0/stream_end.rbs +1 -70
- data/stdlib/zlib/0/stream_error.rbs +1 -70
- data/stdlib/zlib/0/version_error.rbs +1 -70
- data/stdlib/zlib/0/zlib.rbs +0 -2
- data/stdlib/zlib/0/zstream.rbs +4 -72
- metadata +17 -13
- data/ext/rbs_extension/ruby_objs.c +0 -602
- data/ext/rbs_extension/ruby_objs.h +0 -51
- data/stdlib/minitest/0/manifest.yaml +0 -2
@@ -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,7 +145,8 @@ 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
|
@@ -155,11 +156,14 @@ module RBS
|
|
155
156
|
type_name,
|
156
157
|
definition.instance_variables,
|
157
158
|
name: member.name,
|
158
|
-
type: member.type.sub(subst_)
|
159
|
+
type: member.type.sub(subst_),
|
160
|
+
source: member
|
159
161
|
)
|
160
162
|
|
161
163
|
when AST::Members::ClassVariable
|
162
|
-
|
164
|
+
if define_class_vars
|
165
|
+
insert_variable(type_name, definition.class_variables, name: member.name, type: member.type, source: member)
|
166
|
+
end
|
163
167
|
end
|
164
168
|
end
|
165
169
|
end
|
@@ -214,13 +218,13 @@ module RBS
|
|
214
218
|
if ans.name.interface?
|
215
219
|
define_interface(definition, ans.name, subst)
|
216
220
|
else
|
217
|
-
define_instance(definition, ans.name, subst)
|
221
|
+
define_instance(definition, ans.name, subst, define_class_vars: true)
|
218
222
|
end
|
219
223
|
end
|
220
224
|
end
|
221
225
|
end
|
222
226
|
|
223
|
-
define_instance(definition, type_name, Substitution.new)
|
227
|
+
define_instance(definition, type_name, Substitution.new, define_class_vars: true)
|
224
228
|
end
|
225
229
|
end
|
226
230
|
end
|
@@ -249,7 +253,6 @@ module RBS
|
|
249
253
|
|
250
254
|
definition.methods.merge!(defn.methods)
|
251
255
|
definition.instance_variables.merge!(defn.instance_variables)
|
252
|
-
definition.class_variables.merge!(defn.class_variables)
|
253
256
|
end
|
254
257
|
|
255
258
|
one_ancestors.each_extended_module do |mod|
|
@@ -258,7 +261,7 @@ module RBS
|
|
258
261
|
end
|
259
262
|
|
260
263
|
subst = tapp_subst(mod.name, mod.args)
|
261
|
-
define_instance(definition, mod.name, subst)
|
264
|
+
define_instance(definition, mod.name, subst, define_class_vars: false)
|
262
265
|
end
|
263
266
|
|
264
267
|
all_interfaces = one_ancestors.each_extended_interface.flat_map do |interface|
|
@@ -282,18 +285,18 @@ module RBS
|
|
282
285
|
end
|
283
286
|
|
284
287
|
if ivar_name
|
285
|
-
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)
|
286
289
|
end
|
287
290
|
end
|
288
291
|
|
289
292
|
when AST::Members::ClassInstanceVariable
|
290
|
-
insert_variable(type_name, definition.instance_variables, name: member.name, type: member.type)
|
291
|
-
|
292
|
-
when AST::Members::ClassVariable
|
293
|
-
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)
|
294
294
|
end
|
295
295
|
end
|
296
296
|
end
|
297
|
+
|
298
|
+
instance_definition = build_instance(type_name)
|
299
|
+
definition.class_variables.replace(instance_definition.class_variables)
|
297
300
|
end
|
298
301
|
end
|
299
302
|
end
|
@@ -387,10 +390,13 @@ module RBS
|
|
387
390
|
member: initialize_def.member,
|
388
391
|
defined_in: initialize_def.defined_in,
|
389
392
|
implemented_in: initialize_def.implemented_in
|
390
|
-
)
|
393
|
+
).tap do |type_def|
|
394
|
+
type_def.overload_annotations.replace(initialize_def.overload_annotations)
|
395
|
+
end
|
391
396
|
end,
|
392
397
|
accessibility: :public,
|
393
|
-
alias_of: nil
|
398
|
+
alias_of: nil,
|
399
|
+
alias_member: nil
|
394
400
|
)
|
395
401
|
|
396
402
|
definition.methods[:new] = typed_new
|
@@ -534,12 +540,42 @@ module RBS
|
|
534
540
|
end
|
535
541
|
end
|
536
542
|
|
537
|
-
def insert_variable(type_name, variables, name:, type:)
|
543
|
+
def insert_variable(type_name, variables, name:, type:, source:)
|
538
544
|
variables[name] = Definition::Variable.new(
|
539
545
|
parent_variable: variables[name],
|
540
546
|
type: type,
|
541
|
-
declared_in: type_name
|
547
|
+
declared_in: type_name,
|
548
|
+
source: source
|
542
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
|
543
579
|
end
|
544
580
|
|
545
581
|
def import_methods(definition, module_name, module_methods, interfaces_methods, subst, self_type_methods)
|
@@ -625,8 +661,11 @@ module RBS
|
|
625
661
|
defn.update(defined_in: defined_in, implemented_in: implemented_in)
|
626
662
|
end,
|
627
663
|
accessibility: original_method.accessibility,
|
628
|
-
alias_of: original_method
|
664
|
+
alias_of: original_method,
|
665
|
+
alias_member: original
|
629
666
|
)
|
667
|
+
|
668
|
+
method_definition.annotations.replace(original.annotations)
|
630
669
|
when AST::Members::MethodDefinition
|
631
670
|
if duplicated_method = methods[method.name]
|
632
671
|
raise DuplicatedMethodDefinitionError.new(
|
@@ -642,7 +681,10 @@ module RBS
|
|
642
681
|
member: original,
|
643
682
|
defined_in: defined_in,
|
644
683
|
implemented_in: implemented_in
|
645
|
-
)
|
684
|
+
).tap do |type_def|
|
685
|
+
# Keep the original annotations given to overloads.
|
686
|
+
type_def.overload_annotations.replace(overload.annotations)
|
687
|
+
end
|
646
688
|
end
|
647
689
|
|
648
690
|
# @type var accessibility: RBS::Definition::accessibility
|
@@ -662,8 +704,11 @@ module RBS
|
|
662
704
|
super_method: super_method,
|
663
705
|
defs: defs,
|
664
706
|
accessibility: accessibility,
|
665
|
-
alias_of: nil
|
707
|
+
alias_of: nil,
|
708
|
+
alias_member: nil
|
666
709
|
)
|
710
|
+
|
711
|
+
method_definition.annotations.replace(original.annotations)
|
667
712
|
when AST::Members::AttrReader, AST::Members::AttrWriter, AST::Members::AttrAccessor
|
668
713
|
if duplicated_method = methods[method.name]
|
669
714
|
raise DuplicatedMethodDefinitionError.new(
|
@@ -712,8 +757,11 @@ module RBS
|
|
712
757
|
)
|
713
758
|
],
|
714
759
|
accessibility: method.accessibility,
|
715
|
-
alias_of: nil
|
760
|
+
alias_of: nil,
|
761
|
+
alias_member: nil
|
716
762
|
)
|
763
|
+
|
764
|
+
method_definition.annotations.replace(original.annotations)
|
717
765
|
when nil
|
718
766
|
# Overloading method definition only
|
719
767
|
|
@@ -740,8 +788,11 @@ module RBS
|
|
740
788
|
defn.update(implemented_in: implemented_in)
|
741
789
|
end,
|
742
790
|
accessibility: existing_method.accessibility,
|
743
|
-
alias_of: existing_method.alias_of
|
791
|
+
alias_of: existing_method.alias_of,
|
792
|
+
alias_member: nil
|
744
793
|
)
|
794
|
+
|
795
|
+
method_definition.annotations.replace(existing_method.annotations)
|
745
796
|
end
|
746
797
|
|
747
798
|
method.overloads.each do |overloading_def|
|
@@ -753,8 +804,16 @@ module RBS
|
|
753
804
|
implemented_in: implemented_in
|
754
805
|
)
|
755
806
|
|
807
|
+
type_def.overload_annotations.replace(overload.annotations)
|
808
|
+
|
756
809
|
method_definition.defs.unshift(type_def)
|
757
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)
|
758
817
|
end
|
759
818
|
|
760
819
|
methods[method.name] = method_definition
|
data/lib/rbs/environment.rb
CHANGED
@@ -486,6 +486,28 @@ module RBS
|
|
486
486
|
end
|
487
487
|
end
|
488
488
|
|
489
|
+
def resolve_signature(resolver, table, dirs, decls, only: nil)
|
490
|
+
map = UseMap.new(table: table)
|
491
|
+
dirs.each do |dir|
|
492
|
+
case dir
|
493
|
+
when AST::Directives::Use
|
494
|
+
dir.clauses.each do |clause|
|
495
|
+
map.build_map(clause)
|
496
|
+
end
|
497
|
+
end
|
498
|
+
end
|
499
|
+
|
500
|
+
decls = decls.map do |decl|
|
501
|
+
if only && !only.member?(decl)
|
502
|
+
decl
|
503
|
+
else
|
504
|
+
resolve_declaration(resolver, map, decl, outer: [], prefix: Namespace.root)
|
505
|
+
end
|
506
|
+
end
|
507
|
+
|
508
|
+
[dirs, decls]
|
509
|
+
end
|
510
|
+
|
489
511
|
def resolve_type_names(only: nil)
|
490
512
|
resolver = Resolver::TypeNameResolver.new(self)
|
491
513
|
env = Environment.new
|
@@ -498,21 +520,10 @@ module RBS
|
|
498
520
|
table.compute_children
|
499
521
|
|
500
522
|
signatures.each do |buffer, (dirs, decls)|
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
map.build_map(clause)
|
505
|
-
end
|
506
|
-
end
|
507
|
-
|
508
|
-
decls = decls.map do |decl|
|
509
|
-
if only && !only.member?(decl)
|
510
|
-
decl
|
511
|
-
else
|
512
|
-
resolve_declaration(resolver, map, decl, outer: [], prefix: Namespace.root)
|
513
|
-
end
|
523
|
+
resolve = dirs.find { _1.is_a?(AST::Directives::ResolveTypeNames) } #: AST::Directives::ResolveTypeNames?
|
524
|
+
if !resolve || resolve.value
|
525
|
+
_, decls = resolve_signature(resolver, table, dirs, decls)
|
514
526
|
end
|
515
|
-
|
516
527
|
env.add_signature(buffer: buffer, directives: dirs, decls: decls)
|
517
528
|
end
|
518
529
|
|
@@ -541,7 +552,8 @@ module RBS
|
|
541
552
|
name: decl.name,
|
542
553
|
type: absolute_type(resolver, map, decl.type, context: nil),
|
543
554
|
location: decl.location,
|
544
|
-
comment: decl.comment
|
555
|
+
comment: decl.comment,
|
556
|
+
annotations: decl.annotations
|
545
557
|
)
|
546
558
|
end
|
547
559
|
|
@@ -649,7 +661,8 @@ module RBS
|
|
649
661
|
name: decl.name.with_prefix(prefix),
|
650
662
|
type: absolute_type(resolver, map, decl.type, context: context),
|
651
663
|
location: decl.location,
|
652
|
-
comment: decl.comment
|
664
|
+
comment: decl.comment,
|
665
|
+
annotations: decl.annotations
|
653
666
|
)
|
654
667
|
|
655
668
|
when AST::Declarations::ClassAlias
|
@@ -657,7 +670,8 @@ module RBS
|
|
657
670
|
new_name: decl.new_name.with_prefix(prefix),
|
658
671
|
old_name: absolute_type_name(resolver, map, decl.old_name, context: context),
|
659
672
|
location: decl.location,
|
660
|
-
comment: decl.comment
|
673
|
+
comment: decl.comment,
|
674
|
+
annotations: decl.annotations
|
661
675
|
)
|
662
676
|
|
663
677
|
when AST::Declarations::ModuleAlias
|
@@ -665,7 +679,8 @@ module RBS
|
|
665
679
|
new_name: decl.new_name.with_prefix(prefix),
|
666
680
|
old_name: absolute_type_name(resolver, map, decl.old_name, context: context),
|
667
681
|
location: decl.location,
|
668
|
-
comment: decl.comment
|
682
|
+
comment: decl.comment,
|
683
|
+
annotations: decl.annotations
|
669
684
|
)
|
670
685
|
end
|
671
686
|
end
|
@@ -26,7 +26,7 @@ module RBS
|
|
26
26
|
DEFAULT_CORE_ROOT = Pathname(_ = __dir__) + "../../core"
|
27
27
|
|
28
28
|
def self.gem_sig_path(name, version)
|
29
|
-
requirements = []
|
29
|
+
requirements = [] #: Array[String]
|
30
30
|
requirements << version if version
|
31
31
|
spec = Gem::Specification.find_by_name(name, *requirements)
|
32
32
|
path = Pathname(spec.gem_dir) + "sig"
|
@@ -113,6 +113,11 @@ module RBS
|
|
113
113
|
# @type var loaded: Array[[AST::Declarations::t, Pathname, source]]
|
114
114
|
loaded = []
|
115
115
|
|
116
|
+
# For migrating stringio to stdlib
|
117
|
+
if @core_root && libs.none? { |lib| lib.name == 'stringio' }
|
118
|
+
add(library: 'stringio', version: nil)
|
119
|
+
end
|
120
|
+
|
116
121
|
each_signature do |source, path, buffer, decls, dirs|
|
117
122
|
decls.each do |decl|
|
118
123
|
loaded << [decl, path, source]
|
data/lib/rbs/errors.rb
CHANGED
@@ -322,6 +322,30 @@ module RBS
|
|
322
322
|
end
|
323
323
|
end
|
324
324
|
|
325
|
+
class VariableDuplicationError < DefinitionError
|
326
|
+
include DetailedMessageable
|
327
|
+
|
328
|
+
attr_reader :type_name
|
329
|
+
attr_reader :variable_name
|
330
|
+
attr_reader :location
|
331
|
+
|
332
|
+
def initialize(type_name:, variable_name:, location:)
|
333
|
+
@type_name = type_name
|
334
|
+
@variable_name = variable_name
|
335
|
+
@location = location
|
336
|
+
|
337
|
+
super "#{Location.to_string location}: Duplicated #{kind} variable name `#{variable_name}` in `#{type_name}`"
|
338
|
+
end
|
339
|
+
end
|
340
|
+
|
341
|
+
class InstanceVariableDuplicationError < VariableDuplicationError
|
342
|
+
def kind = 'instance'
|
343
|
+
end
|
344
|
+
|
345
|
+
class ClassInstanceVariableDuplicationError < VariableDuplicationError
|
346
|
+
def kind = 'class instance'
|
347
|
+
end
|
348
|
+
|
325
349
|
class UnknownMethodAliasError < DefinitionError
|
326
350
|
include DetailedMessageable
|
327
351
|
|
data/lib/rbs/locator.rb
CHANGED
data/lib/rbs/method_type.rb
CHANGED
data/lib/rbs/namespace.rb
CHANGED
data/lib/rbs/parser_aux.rb
CHANGED
@@ -17,11 +17,48 @@ module RBS
|
|
17
17
|
|
18
18
|
def self.parse_signature(source)
|
19
19
|
buf = buffer(source)
|
20
|
-
|
20
|
+
|
21
|
+
resolved = magic_comment(buf)
|
22
|
+
start_pos =
|
23
|
+
if resolved
|
24
|
+
(resolved.location || raise).end_pos
|
25
|
+
else
|
26
|
+
0
|
27
|
+
end
|
28
|
+
dirs, decls = _parse_signature(buf, start_pos, buf.last_position)
|
29
|
+
|
30
|
+
if resolved
|
31
|
+
dirs = dirs.dup if dirs.frozen?
|
32
|
+
dirs.unshift(resolved)
|
33
|
+
end
|
21
34
|
|
22
35
|
[buf, dirs, decls]
|
23
36
|
end
|
24
37
|
|
38
|
+
def self.magic_comment(buf)
|
39
|
+
start_pos = 0
|
40
|
+
|
41
|
+
while true
|
42
|
+
case
|
43
|
+
when match = /\A#\s*(?<keyword>resolve-type-names)\s*(?<colon>:)\s+(?<value>true|false)$/.match(buf.content, start_pos)
|
44
|
+
value = match[:value] or raise
|
45
|
+
|
46
|
+
kw_offset = match.offset(:keyword) #: [Integer, Integer]
|
47
|
+
colon_offset = match.offset(:colon) #: [Integer, Integer]
|
48
|
+
value_offset = match.offset(:value) #: [Integer, Integer]
|
49
|
+
|
50
|
+
location = Location.new(buf, kw_offset[0], value_offset[1])
|
51
|
+
location.add_required_child(:keyword, kw_offset[0]...kw_offset[1])
|
52
|
+
location.add_required_child(:colon, colon_offset[0]...colon_offset[1])
|
53
|
+
location.add_required_child(:value, value_offset[0]...value_offset[1])
|
54
|
+
|
55
|
+
return AST::Directives::ResolveTypeNames.new(value: value == "true", location: location)
|
56
|
+
else
|
57
|
+
return
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
25
62
|
def self.lex(source)
|
26
63
|
buf = buffer(source)
|
27
64
|
list = _lex(buf, buf.last_position)
|
@@ -70,8 +107,8 @@ module RBS
|
|
70
107
|
untyped
|
71
108
|
true
|
72
109
|
false
|
73
|
-
).each_with_object({}) do |keyword, hash|
|
74
|
-
hash[keyword] = nil
|
110
|
+
).each_with_object({}) do |keyword, hash| #$ Hash[String, bot]
|
111
|
+
hash[keyword] = _ = nil
|
75
112
|
end
|
76
113
|
end
|
77
114
|
end
|
data/lib/rbs/prototype/rb.rb
CHANGED
@@ -75,8 +75,8 @@ module RBS
|
|
75
75
|
def parse(string)
|
76
76
|
# @type var comments: Hash[Integer, AST::Comment]
|
77
77
|
comments = Ripper.lex(string).yield_self do |tokens|
|
78
|
-
code_lines = {}
|
79
|
-
tokens.each.with_object({}) do |token, hash|
|
78
|
+
code_lines = {} #: Hash[Integer, bool]
|
79
|
+
tokens.each.with_object({}) do |token, hash| #$ Hash[Integer, AST::Comment]
|
80
80
|
case token[1]
|
81
81
|
when :on_sp, :on_ignored_nl
|
82
82
|
# skip
|
@@ -368,7 +368,7 @@ module RBS
|
|
368
368
|
when node.children[0].is_a?(Symbol)
|
369
369
|
TypeName.new(name: node.children[0], namespace: Namespace.empty)
|
370
370
|
else
|
371
|
-
const_to_name!(node.children[0])
|
371
|
+
const_to_name!(node.children[0], context: context)
|
372
372
|
end
|
373
373
|
|
374
374
|
value_node = node.children.last
|
@@ -382,7 +382,8 @@ module RBS
|
|
382
382
|
name: const_name,
|
383
383
|
type: type,
|
384
384
|
location: nil,
|
385
|
-
comment: comments[node.first_lineno - 1]
|
385
|
+
comment: comments[node.first_lineno - 1],
|
386
|
+
annotations: []
|
386
387
|
)
|
387
388
|
|
388
389
|
when :IASGN
|
@@ -429,13 +430,13 @@ module RBS
|
|
429
430
|
end
|
430
431
|
end
|
431
432
|
|
432
|
-
def const_to_name!(node)
|
433
|
+
def const_to_name!(node, context: nil)
|
433
434
|
case node.type
|
434
435
|
when :CONST
|
435
436
|
TypeName.new(name: node.children[0], namespace: Namespace.empty)
|
436
437
|
when :COLON2
|
437
438
|
if node.children[0]
|
438
|
-
namespace = const_to_name!(node.children[0]).to_namespace
|
439
|
+
namespace = const_to_name!(node.children[0], context: context).to_namespace
|
439
440
|
else
|
440
441
|
namespace = Namespace.empty
|
441
442
|
end
|
@@ -443,6 +444,10 @@ module RBS
|
|
443
444
|
TypeName.new(name: node.children[1], namespace: namespace)
|
444
445
|
when :COLON3
|
445
446
|
TypeName.new(name: node.children[0], namespace: Namespace.root)
|
447
|
+
when :SELF
|
448
|
+
raise if context.nil?
|
449
|
+
|
450
|
+
context.namespace.to_type_name
|
446
451
|
else
|
447
452
|
raise
|
448
453
|
end
|
@@ -639,11 +644,11 @@ module RBS
|
|
639
644
|
children = list.children
|
640
645
|
children.pop
|
641
646
|
else
|
642
|
-
children = []
|
647
|
+
children = [] #: Array[untyped]
|
643
648
|
end
|
644
649
|
|
645
|
-
key_types = []
|
646
|
-
value_types = []
|
650
|
+
key_types = [] #: Array[Types::t]
|
651
|
+
value_types = [] #: Array[Types::t]
|
647
652
|
children.each_slice(2) do |k, v|
|
648
653
|
if k
|
649
654
|
key_types << literal_to_type(k)
|
@@ -655,7 +660,10 @@ module RBS
|
|
655
660
|
end
|
656
661
|
|
657
662
|
if !key_types.empty? && key_types.all? { |t| t.is_a?(Types::Literal) }
|
658
|
-
fields = key_types.map {
|
663
|
+
fields = key_types.map {|t|
|
664
|
+
t.is_a?(Types::Literal) or raise
|
665
|
+
t.literal
|
666
|
+
}.zip(value_types).to_h #: Hash[Types::Literal::literal, Types::t]
|
659
667
|
Types::Record.new(fields: fields, location: nil)
|
660
668
|
else
|
661
669
|
key_type = types_to_union_type(key_types)
|
@@ -715,9 +723,9 @@ module RBS
|
|
715
723
|
when :FLOAT
|
716
724
|
BuiltinNames::Float.instance_type
|
717
725
|
when :RATIONAL
|
718
|
-
Types::ClassInstance.new(name: TypeName("::Rational"), args: [], location: nil)
|
726
|
+
Types::ClassInstance.new(name: TypeName.parse("::Rational"), args: [], location: nil)
|
719
727
|
when :IMAGINARY
|
720
|
-
Types::ClassInstance.new(name: TypeName("::Complex"), args: [], location: nil)
|
728
|
+
Types::ClassInstance.new(name: TypeName.parse("::Complex"), args: [], location: nil)
|
721
729
|
when :LIT
|
722
730
|
case node.children[0]
|
723
731
|
when Symbol
|
data/lib/rbs/prototype/rbi.rb
CHANGED
@@ -17,9 +17,7 @@ module RBS
|
|
17
17
|
|
18
18
|
def parse(string)
|
19
19
|
comments = Ripper.lex(string).yield_self do |tokens|
|
20
|
-
tokens.each.with_object({}) do |token, hash|
|
21
|
-
# @type var hash: Hash[Integer, AST::Comment]
|
22
|
-
|
20
|
+
tokens.each.with_object({}) do |token, hash| #$ Hash[Integer, AST::Comment]
|
23
21
|
if token[1] == :on_comment
|
24
22
|
line = token[0][0]
|
25
23
|
body = token[2][2..-1] or raise
|
@@ -259,7 +257,8 @@ module RBS
|
|
259
257
|
name: name,
|
260
258
|
type: type,
|
261
259
|
location: nil,
|
262
|
-
comment: nil
|
260
|
+
comment: nil,
|
261
|
+
annotations: []
|
263
262
|
)
|
264
263
|
end
|
265
264
|
when :ALIAS
|
@@ -325,11 +324,17 @@ module RBS
|
|
325
324
|
end
|
326
325
|
end
|
327
326
|
when :type_parameters
|
328
|
-
type_params = []
|
327
|
+
type_params = [] #: Array[AST::TypeParam]
|
329
328
|
|
330
329
|
each_arg args do |node|
|
331
330
|
if name = symbol_literal_node?(node)
|
332
|
-
type_params <<
|
331
|
+
type_params << AST::TypeParam.new(
|
332
|
+
name: name,
|
333
|
+
variance: :invariant,
|
334
|
+
upper_bound: nil,
|
335
|
+
location: nil,
|
336
|
+
default_type: nil
|
337
|
+
)
|
333
338
|
end
|
334
339
|
end
|
335
340
|
|
@@ -80,7 +80,9 @@ module RBS
|
|
80
80
|
kind: :instance,
|
81
81
|
location: nil,
|
82
82
|
comment: nil,
|
83
|
-
annotations:
|
83
|
+
annotations: (
|
84
|
+
[] #: Array[AST::Annotation]
|
85
|
+
)
|
84
86
|
)
|
85
87
|
end
|
86
88
|
end
|
@@ -100,7 +102,7 @@ module RBS
|
|
100
102
|
CAN_CALL_KEYWORD_INIT_P = Struct.new(:tmp).respond_to?(:keyword_init?)
|
101
103
|
|
102
104
|
def build_super_class
|
103
|
-
AST::Declarations::Class::Super.new(name: TypeName("::Struct"), args: [untyped], location: nil)
|
105
|
+
AST::Declarations::Class::Super.new(name: TypeName.parse("::Struct"), args: [untyped], location: nil)
|
104
106
|
end
|
105
107
|
|
106
108
|
def add_decl_members(decl)
|
@@ -114,7 +116,7 @@ module RBS
|
|
114
116
|
# | (?foo: untyped, ?bar: untyped) -> instance
|
115
117
|
def build_s_new
|
116
118
|
[:new, :[]].map do |name|
|
117
|
-
new_overloads = []
|
119
|
+
new_overloads = [] #: Array[AST::Members::MethodDefinition::Overload]
|
118
120
|
|
119
121
|
if CAN_CALL_KEYWORD_INIT_P
|
120
122
|
case @target_class.keyword_init?
|
@@ -221,7 +223,7 @@ module RBS
|
|
221
223
|
private
|
222
224
|
|
223
225
|
def build_super_class
|
224
|
-
AST::Declarations::Class::Super.new(name: TypeName("::Data"), args: [], location: nil)
|
226
|
+
AST::Declarations::Class::Super.new(name: TypeName.parse("::Data"), args: [], location: nil)
|
225
227
|
end
|
226
228
|
|
227
229
|
def add_decl_members(decl)
|
@@ -234,7 +236,7 @@ module RBS
|
|
234
236
|
# | (foo: untyped, bar: untyped) -> instance
|
235
237
|
def build_s_new
|
236
238
|
[:new, :[]].map do |name|
|
237
|
-
new_overloads = []
|
239
|
+
new_overloads = [] #: Array[AST::Members::MethodDefinition::Overload]
|
238
240
|
|
239
241
|
new_overloads << AST::Members::MethodDefinition::Overload.new(
|
240
242
|
annotations: [],
|