rbs 3.1.3 → 3.2.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 +0 -6
- data/CHANGELOG.md +82 -0
- data/Gemfile +0 -6
- data/Gemfile.lock +12 -21
- data/README.md +1 -1
- data/Rakefile +45 -1
- data/Steepfile +3 -3
- data/core/array.rbs +0 -8
- data/core/binding.rbs +7 -69
- data/core/builtin.rbs +33 -8
- data/core/constants.rbs +13 -5
- data/core/dir.rbs +25 -25
- data/core/errno.rbs +474 -590
- data/core/exception.rbs +1 -1
- data/core/global_variables.rbs +27 -27
- data/core/io.rbs +163 -172
- data/core/kernel.rbs +58 -38
- data/core/module.rbs +34 -32
- data/core/object.rbs +3 -7
- data/core/string_io.rbs +9 -0
- data/core/thread.rbs +25 -1
- data/core/time.rbs +3 -3
- data/core/warning.rbs +3 -1
- data/docs/CONTRIBUTING.md +1 -1
- data/docs/rbs_by_example.md +16 -35
- data/docs/repo.md +1 -1
- data/docs/sigs.md +7 -7
- data/docs/stdlib.md +2 -3
- data/docs/syntax.md +40 -40
- data/lib/rbs/cli.rb +15 -4
- data/lib/rbs/collection/config/lockfile_generator.rb +6 -2
- data/lib/rbs/collection/installer.rb +5 -2
- data/lib/rbs/collection/sources/stdlib.rb +5 -1
- data/lib/rbs/errors.rb +8 -1
- data/lib/rbs/file_finder.rb +1 -1
- data/lib/rbs/prototype/rb.rb +64 -6
- data/lib/rbs/prototype/rbi.rb +2 -6
- data/lib/rbs/prototype/runtime.rb +29 -8
- data/lib/rbs/subtractor.rb +17 -0
- data/lib/rbs/type_name.rb +4 -4
- data/lib/rbs/version.rb +1 -1
- data/rbs.gemspec +1 -1
- data/schema/decls.json +1 -1
- data/sig/errors.rbs +54 -0
- data/sig/parser.rbs +2 -2
- data/sig/prototype/rb.rbs +9 -1
- data/sig/subtractor.rbs +4 -0
- data/stdlib/logger/0/logger.rbs +1 -1
- data/stdlib/observable/0/observable.rbs +219 -0
- data/stdlib/uri/0/common.rbs +24 -0
- data/stdlib/zlib/0/buf_error.rbs +79 -0
- data/stdlib/zlib/0/data_error.rbs +79 -0
- data/stdlib/zlib/0/deflate.rbs +276 -0
- data/stdlib/zlib/0/error.rbs +89 -0
- data/stdlib/zlib/0/gzip_file/crc_error.rbs +115 -0
- data/stdlib/zlib/0/gzip_file/error.rbs +128 -0
- data/stdlib/zlib/0/gzip_file/length_error.rbs +115 -0
- data/stdlib/zlib/0/gzip_file/no_footer.rbs +114 -0
- data/stdlib/zlib/0/gzip_file.rbs +228 -0
- data/stdlib/zlib/0/gzip_reader.rbs +362 -0
- data/stdlib/zlib/0/gzip_writer.rbs +237 -0
- data/stdlib/zlib/0/inflate.rbs +249 -0
- data/stdlib/zlib/0/mem_error.rbs +79 -0
- data/stdlib/zlib/0/need_dict.rbs +82 -0
- data/stdlib/zlib/0/stream_end.rbs +80 -0
- data/stdlib/zlib/0/stream_error.rbs +80 -0
- data/stdlib/zlib/0/version_error.rbs +80 -0
- data/stdlib/zlib/0/zstream.rbs +270 -0
- metadata +22 -6
- data/stdlib/prime/0/integer-extension.rbs +0 -41
- data/stdlib/prime/0/manifest.yaml +0 -2
- data/stdlib/prime/0/prime.rbs +0 -372
data/lib/rbs/cli.rb
CHANGED
@@ -645,6 +645,7 @@ EOU
|
|
645
645
|
relative_libs = []
|
646
646
|
merge = false
|
647
647
|
owners_included = []
|
648
|
+
outline = false
|
648
649
|
|
649
650
|
OptionParser.new do |opts|
|
650
651
|
opts.banner = <<EOU
|
@@ -657,7 +658,7 @@ Examples:
|
|
657
658
|
|
658
659
|
$ rbs prototype runtime String
|
659
660
|
$ rbs prototype runtime --require set Set
|
660
|
-
$ rbs prototype runtime -R lib/rbs RBS::*
|
661
|
+
$ rbs prototype runtime -R lib/rbs RBS RBS::*
|
661
662
|
|
662
663
|
Options:
|
663
664
|
EOU
|
@@ -673,6 +674,9 @@ EOU
|
|
673
674
|
opts.on("--method-owner CLASS", "Generate method prototypes if the owner of the method is [CLASS]") do |klass|
|
674
675
|
owners_included << klass
|
675
676
|
end
|
677
|
+
opts.on("--outline", "Generates only module/class/constant declaration (no method definition)") do
|
678
|
+
outline = true
|
679
|
+
end
|
676
680
|
end.parse!(args)
|
677
681
|
|
678
682
|
loader = options.loader()
|
@@ -686,7 +690,10 @@ EOU
|
|
686
690
|
eval("require_relative(lib)", binding, "rbs")
|
687
691
|
end
|
688
692
|
|
689
|
-
|
693
|
+
runtime = Prototype::Runtime.new(patterns: args, env: env, merge: merge, owners_included: owners_included)
|
694
|
+
runtime.outline = outline
|
695
|
+
|
696
|
+
decls = runtime.decls
|
690
697
|
|
691
698
|
writer = Writer.new(out: stdout)
|
692
699
|
writer.write decls
|
@@ -961,7 +968,7 @@ Options:
|
|
961
968
|
Parser.public_send(parse_method, buf, require_eof: true)
|
962
969
|
end
|
963
970
|
rescue RBS::ParsingError => ex
|
964
|
-
stdout.
|
971
|
+
stdout.print ex.detailed_message(highlight: true)
|
965
972
|
syntax_error = true
|
966
973
|
end
|
967
974
|
|
@@ -1241,7 +1248,11 @@ EOB
|
|
1241
1248
|
w.write(subtracted)
|
1242
1249
|
|
1243
1250
|
if write_to_file
|
1244
|
-
|
1251
|
+
if io.string.empty?
|
1252
|
+
rbs_path.delete
|
1253
|
+
else
|
1254
|
+
rbs_path.write(io.string)
|
1255
|
+
end
|
1245
1256
|
else
|
1246
1257
|
stdout.puts(io.string)
|
1247
1258
|
end
|
@@ -134,8 +134,12 @@ module RBS
|
|
134
134
|
if locked
|
135
135
|
lockfile.gems[name] = locked
|
136
136
|
|
137
|
-
|
138
|
-
|
137
|
+
begin
|
138
|
+
locked[:source].dependencies_of(locked[:name], locked[:version])&.each do |dep|
|
139
|
+
assign_stdlib(name: dep["name"], from_gem: name)
|
140
|
+
end
|
141
|
+
rescue
|
142
|
+
RBS.logger.warn "Cannot find `#{locked[:name]}-#{locked[:version]}` gem. Using incorrect Bundler context? (#{definition.lockfile})"
|
139
143
|
end
|
140
144
|
end
|
141
145
|
end
|
@@ -14,7 +14,10 @@ module RBS
|
|
14
14
|
def install_from_lockfile
|
15
15
|
install_to = lockfile.fullpath
|
16
16
|
install_to.mkpath
|
17
|
-
lockfile.gems.
|
17
|
+
selected = lockfile.gems.select do |name, gem|
|
18
|
+
gem[:source].has?(name, gem[:version])
|
19
|
+
end
|
20
|
+
selected.each_value do |gem|
|
18
21
|
gem[:source].install(
|
19
22
|
dest: install_to,
|
20
23
|
name: gem[:name],
|
@@ -22,7 +25,7 @@ module RBS
|
|
22
25
|
stdout: stdout
|
23
26
|
)
|
24
27
|
end
|
25
|
-
stdout.puts "It's done! #{
|
28
|
+
stdout.puts "It's done! #{selected.size} gems' RBSs now installed."
|
26
29
|
end
|
27
30
|
end
|
28
31
|
end
|
@@ -27,7 +27,11 @@ module RBS
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def manifest_of(name, version)
|
30
|
-
|
30
|
+
unless path = lookup(name, version)
|
31
|
+
RBS.logger.warn "`#{name}` is specified in rbs_collection.lock.yaml. But it is not found in #{REPO.dirs.join(",")}"
|
32
|
+
return
|
33
|
+
end
|
34
|
+
manifest_path = path.join('manifest.yaml')
|
31
35
|
YAML.safe_load(manifest_path.read) if manifest_path.exist?
|
32
36
|
end
|
33
37
|
|
data/lib/rbs/errors.rb
CHANGED
@@ -22,7 +22,14 @@ module RBS
|
|
22
22
|
|
23
23
|
module DetailedMessageable
|
24
24
|
def detailed_message(highlight: false, **)
|
25
|
-
msg =
|
25
|
+
msg = if Exception.method_defined?(:detailed_message)
|
26
|
+
super
|
27
|
+
else
|
28
|
+
# Failback to `#message` in Ruby 3.1 or earlier
|
29
|
+
"#{message} (#{self.class.name})"
|
30
|
+
end
|
31
|
+
|
32
|
+
return msg unless location
|
26
33
|
|
27
34
|
# Support only one line
|
28
35
|
return msg unless location.start_line == location.end_line
|
data/lib/rbs/file_finder.rb
CHANGED
@@ -5,7 +5,7 @@ module RBS
|
|
5
5
|
module_function
|
6
6
|
|
7
7
|
def self.each_file(path, immediate:, skip_hidden:, &block)
|
8
|
-
return enum_for(__method__, path, immediate: immediate, skip_hidden: skip_hidden) unless block
|
8
|
+
return enum_for((__method__ or raise), path, immediate: immediate, skip_hidden: skip_hidden) unless block
|
9
9
|
|
10
10
|
case
|
11
11
|
when path.file?
|
data/lib/rbs/prototype/rb.rb
CHANGED
@@ -5,11 +5,11 @@ module RBS
|
|
5
5
|
class RB
|
6
6
|
include Helpers
|
7
7
|
|
8
|
-
Context = _ = Struct.new(:module_function, :singleton, :namespace, keyword_init: true) do
|
8
|
+
Context = _ = Struct.new(:module_function, :singleton, :namespace, :in_def, keyword_init: true) do
|
9
9
|
# @implements Context
|
10
10
|
|
11
11
|
def self.initial(namespace: Namespace.root)
|
12
|
-
self.new(module_function: false, singleton: false, namespace: namespace)
|
12
|
+
self.new(module_function: false, singleton: false, namespace: namespace, in_def: false)
|
13
13
|
end
|
14
14
|
|
15
15
|
def method_kind
|
@@ -29,6 +29,14 @@ module RBS
|
|
29
29
|
:instance
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
def enter_namespace(namespace)
|
34
|
+
Context.initial(namespace: self.namespace + namespace)
|
35
|
+
end
|
36
|
+
|
37
|
+
def update(module_function: self.module_function, singleton: self.singleton, in_def: self.in_def)
|
38
|
+
Context.new(module_function: module_function, singleton: singleton, namespace: namespace, in_def: in_def)
|
39
|
+
end
|
32
40
|
end
|
33
41
|
|
34
42
|
attr_reader :source_decls
|
@@ -121,11 +129,12 @@ module RBS
|
|
121
129
|
|
122
130
|
decls.push kls
|
123
131
|
|
124
|
-
new_ctx =
|
132
|
+
new_ctx = context.enter_namespace(kls.name.to_namespace)
|
125
133
|
each_node class_body do |child|
|
126
134
|
process child, decls: kls.members, comments: comments, context: new_ctx
|
127
135
|
end
|
128
136
|
remove_unnecessary_accessibility_methods! kls.members
|
137
|
+
sort_members! kls.members
|
129
138
|
|
130
139
|
when :MODULE
|
131
140
|
module_name, *module_body = node.children
|
@@ -142,11 +151,12 @@ module RBS
|
|
142
151
|
|
143
152
|
decls.push mod
|
144
153
|
|
145
|
-
new_ctx =
|
154
|
+
new_ctx = context.enter_namespace(mod.name.to_namespace)
|
146
155
|
each_node module_body do |child|
|
147
156
|
process child, decls: mod.members, comments: comments, context: new_ctx
|
148
157
|
end
|
149
158
|
remove_unnecessary_accessibility_methods! mod.members
|
159
|
+
sort_members! mod.members
|
150
160
|
|
151
161
|
when :SCLASS
|
152
162
|
this, body = node.children
|
@@ -195,6 +205,11 @@ module RBS
|
|
195
205
|
|
196
206
|
decls.push member unless decls.include?(member)
|
197
207
|
|
208
|
+
new_ctx = context.update(singleton: kind == :singleton, in_def: true)
|
209
|
+
each_node def_body.children do |child|
|
210
|
+
process child, decls: decls, comments: comments, context: new_ctx
|
211
|
+
end
|
212
|
+
|
198
213
|
when :ALIAS
|
199
214
|
new_name, old_name = node.children.map { |c| literal_to_symbol(c) }
|
200
215
|
member = AST::Members::Alias.new(
|
@@ -306,7 +321,7 @@ module RBS
|
|
306
321
|
if args.empty?
|
307
322
|
context.module_function = true
|
308
323
|
else
|
309
|
-
module_func_context = context.
|
324
|
+
module_func_context = context.update(module_function: true)
|
310
325
|
args.each do |arg|
|
311
326
|
if arg && (name = literal_to_symbol(arg))
|
312
327
|
if (i, defn = find_def_index_by_name(decls, name))
|
@@ -377,6 +392,39 @@ module RBS
|
|
377
392
|
comment: comments[node.first_lineno - 1]
|
378
393
|
)
|
379
394
|
|
395
|
+
when :IASGN
|
396
|
+
case [context.singleton, context.in_def]
|
397
|
+
when [true, true], [false, false]
|
398
|
+
member = AST::Members::ClassInstanceVariable.new(
|
399
|
+
name: node.children.first,
|
400
|
+
type: Types::Bases::Any.new(location: nil),
|
401
|
+
location: nil,
|
402
|
+
comment: comments[node.first_lineno - 1]
|
403
|
+
)
|
404
|
+
when [false, true]
|
405
|
+
member = AST::Members::InstanceVariable.new(
|
406
|
+
name: node.children.first,
|
407
|
+
type: Types::Bases::Any.new(location: nil),
|
408
|
+
location: nil,
|
409
|
+
comment: comments[node.first_lineno - 1]
|
410
|
+
)
|
411
|
+
when [true, false]
|
412
|
+
# The variable is for the singleton class of the class object.
|
413
|
+
# RBS does not have a way to represent it. So we ignore it.
|
414
|
+
else
|
415
|
+
raise 'unreachable'
|
416
|
+
end
|
417
|
+
|
418
|
+
decls.push member if member && !decls.include?(member)
|
419
|
+
|
420
|
+
when :CVASGN
|
421
|
+
member = AST::Members::ClassVariable.new(
|
422
|
+
name: node.children.first,
|
423
|
+
type: Types::Bases::Any.new(location: nil),
|
424
|
+
location: nil,
|
425
|
+
comment: comments[node.first_lineno - 1]
|
426
|
+
)
|
427
|
+
decls.push member unless decls.include?(member)
|
380
428
|
else
|
381
429
|
process_children(node, decls: decls, comments: comments, context: context)
|
382
430
|
end
|
@@ -413,7 +461,7 @@ module RBS
|
|
413
461
|
when :SELF
|
414
462
|
context.namespace.to_type_name
|
415
463
|
when :CONST, :COLON2, :COLON3
|
416
|
-
const_to_name!(node)
|
464
|
+
const_to_name!(node) rescue nil
|
417
465
|
end
|
418
466
|
end
|
419
467
|
end
|
@@ -743,6 +791,16 @@ module RBS
|
|
743
791
|
]
|
744
792
|
end
|
745
793
|
end
|
794
|
+
|
795
|
+
def sort_members!(decls)
|
796
|
+
i = 0
|
797
|
+
orders = {
|
798
|
+
AST::Members::ClassVariable => -3,
|
799
|
+
AST::Members::ClassInstanceVariable => -2,
|
800
|
+
AST::Members::InstanceVariable => -1,
|
801
|
+
}
|
802
|
+
decls.sort_by! { |decl| [orders.fetch(decl.class, 0), i += 1] }
|
803
|
+
end
|
746
804
|
end
|
747
805
|
end
|
748
806
|
end
|
data/lib/rbs/prototype/rbi.rb
CHANGED
@@ -479,7 +479,7 @@ module RBS
|
|
479
479
|
else
|
480
480
|
Types::ClassInstance.new(name: const_to_name(type_node), args: [], location: nil)
|
481
481
|
end
|
482
|
-
when type_node.type == :COLON2
|
482
|
+
when type_node.type == :COLON2 || type_node.type == :COLON3
|
483
483
|
Types::ClassInstance.new(name: const_to_name(type_node), args: [], location: nil)
|
484
484
|
when call_node?(type_node, name: :[], receiver: -> (_) { true })
|
485
485
|
# The type_node represents a type application
|
@@ -553,11 +553,7 @@ module RBS
|
|
553
553
|
TypeName.new(name: node.children[0], namespace: Namespace.empty)
|
554
554
|
when :COLON2
|
555
555
|
if node.children[0]
|
556
|
-
|
557
|
-
namespace = Namespace.root
|
558
|
-
else
|
559
|
-
namespace = const_to_name(node.children[0]).to_namespace
|
560
|
-
end
|
556
|
+
namespace = const_to_name(node.children[0]).to_namespace
|
561
557
|
else
|
562
558
|
namespace = Namespace.empty
|
563
559
|
end
|
@@ -9,6 +9,7 @@ module RBS
|
|
9
9
|
attr_reader :env
|
10
10
|
attr_reader :merge
|
11
11
|
attr_reader :owners_included
|
12
|
+
attr_accessor :outline
|
12
13
|
|
13
14
|
def initialize(patterns:, env:, merge:, owners_included: [])
|
14
15
|
@patterns = patterns
|
@@ -19,6 +20,7 @@ module RBS
|
|
19
20
|
@owners_included = owners_included.map do |name|
|
20
21
|
Object.const_get(name)
|
21
22
|
end
|
23
|
+
@outline = false
|
22
24
|
end
|
23
25
|
|
24
26
|
def target?(const)
|
@@ -378,7 +380,7 @@ module RBS
|
|
378
380
|
RBS.logger.warn("Skipping anonymous superclass #{mod.superclass} of #{mod}")
|
379
381
|
nil
|
380
382
|
else
|
381
|
-
super_name = to_type_name(const_name(mod.superclass), full_name: true)
|
383
|
+
super_name = to_type_name(const_name(mod.superclass), full_name: true).absolute!
|
382
384
|
super_args = type_args(super_name)
|
383
385
|
AST::Declarations::Class::Super.new(name: super_name, args: super_args, location: nil)
|
384
386
|
end
|
@@ -393,7 +395,7 @@ module RBS
|
|
393
395
|
unless decl
|
394
396
|
decl = AST::Declarations::Class.new(
|
395
397
|
name: to_type_name(only_name(mod)),
|
396
|
-
type_params:
|
398
|
+
type_params: type_params(mod),
|
397
399
|
super_class: generate_super_class(mod),
|
398
400
|
members: [],
|
399
401
|
annotations: [],
|
@@ -426,7 +428,7 @@ module RBS
|
|
426
428
|
)
|
427
429
|
end
|
428
430
|
|
429
|
-
generate_methods(mod, type_name, decl.members)
|
431
|
+
generate_methods(mod, type_name, decl.members) unless outline
|
430
432
|
|
431
433
|
generate_constants mod, decl.members
|
432
434
|
end
|
@@ -447,7 +449,7 @@ module RBS
|
|
447
449
|
unless decl
|
448
450
|
decl = AST::Declarations::Module.new(
|
449
451
|
name: to_type_name(only_name(mod)),
|
450
|
-
type_params:
|
452
|
+
type_params: type_params(mod),
|
451
453
|
self_types: [],
|
452
454
|
members: [],
|
453
455
|
annotations: [],
|
@@ -480,7 +482,7 @@ module RBS
|
|
480
482
|
)
|
481
483
|
end
|
482
484
|
|
483
|
-
generate_methods(mod, type_name, decl.members)
|
485
|
+
generate_methods(mod, type_name, decl.members) unless outline
|
484
486
|
|
485
487
|
generate_constants mod, decl.members
|
486
488
|
end
|
@@ -502,7 +504,7 @@ module RBS
|
|
502
504
|
if outer_module.is_a?(Class)
|
503
505
|
outer_decl = AST::Declarations::Class.new(
|
504
506
|
name: to_type_name(outer_module_name),
|
505
|
-
type_params:
|
507
|
+
type_params: type_params(outer_module),
|
506
508
|
super_class: generate_super_class(outer_module),
|
507
509
|
members: [],
|
508
510
|
annotations: [],
|
@@ -512,7 +514,7 @@ module RBS
|
|
512
514
|
else
|
513
515
|
outer_decl = AST::Declarations::Module.new(
|
514
516
|
name: to_type_name(outer_module_name),
|
515
|
-
type_params:
|
517
|
+
type_params: type_params(outer_module),
|
516
518
|
self_types: [],
|
517
519
|
members: [],
|
518
520
|
annotations: [],
|
@@ -539,7 +541,17 @@ module RBS
|
|
539
541
|
|
540
542
|
def const_name(const)
|
541
543
|
@module_name_method ||= Module.instance_method(:name)
|
542
|
-
@module_name_method.bind(const).call
|
544
|
+
name = @module_name_method.bind(const).call
|
545
|
+
return nil unless name
|
546
|
+
|
547
|
+
begin
|
548
|
+
Object.const_get(name)
|
549
|
+
rescue NameError
|
550
|
+
# Should generate const name if anonymous or internal module (e.g. NameError::message)
|
551
|
+
nil
|
552
|
+
else
|
553
|
+
name
|
554
|
+
end
|
543
555
|
end
|
544
556
|
|
545
557
|
def type_args(type_name)
|
@@ -550,6 +562,15 @@ module RBS
|
|
550
562
|
end
|
551
563
|
end
|
552
564
|
|
565
|
+
def type_params(mod)
|
566
|
+
type_name = to_type_name(const_name(mod), full_name: true)
|
567
|
+
if class_decl = env.class_decls[type_name.absolute!]
|
568
|
+
class_decl.type_params
|
569
|
+
else
|
570
|
+
[]
|
571
|
+
end
|
572
|
+
end
|
573
|
+
|
553
574
|
def block_from_ast_of(method)
|
554
575
|
return nil if RUBY_VERSION < '3.1'
|
555
576
|
|
data/lib/rbs/subtractor.rb
CHANGED
@@ -51,6 +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 = filter_redundunt_access_modifiers(children)
|
54
55
|
return nil if children.empty?
|
55
56
|
|
56
57
|
update_decl(decl, members: children)
|
@@ -144,6 +145,22 @@ module RBS
|
|
144
145
|
end
|
145
146
|
end
|
146
147
|
|
148
|
+
private def filter_redundunt_access_modifiers(decls)
|
149
|
+
decls = decls.dup
|
150
|
+
decls.pop while access_modifier?(decls.last)
|
151
|
+
decls = decls.map.with_index do |decl, i|
|
152
|
+
if access_modifier?(decl) && access_modifier?(decls[i + 1])
|
153
|
+
nil
|
154
|
+
else
|
155
|
+
decl
|
156
|
+
end
|
157
|
+
end.compact
|
158
|
+
end
|
159
|
+
|
160
|
+
private def access_modifier?(decl)
|
161
|
+
decl.is_a?(AST::Members::Public) || decl.is_a?(AST::Members::Private)
|
162
|
+
end
|
163
|
+
|
147
164
|
private def update_decl(decl, members:)
|
148
165
|
case decl
|
149
166
|
when AST::Declarations::Class
|
data/lib/rbs/type_name.rb
CHANGED
@@ -9,12 +9,12 @@ module RBS
|
|
9
9
|
def initialize(namespace:, name:)
|
10
10
|
@namespace = namespace
|
11
11
|
@name = name
|
12
|
-
@kind = case
|
13
|
-
when
|
12
|
+
@kind = case
|
13
|
+
when name.match?(/\A[A-Z]/)
|
14
14
|
:class
|
15
|
-
when
|
15
|
+
when name.match?(/\A[a-z]/)
|
16
16
|
:alias
|
17
|
-
when "_"
|
17
|
+
when name.start_with?("_")
|
18
18
|
:interface
|
19
19
|
else
|
20
20
|
# Defaults to :class
|
data/lib/rbs/version.rb
CHANGED
data/rbs.gemspec
CHANGED
data/schema/decls.json
CHANGED
@@ -60,7 +60,7 @@
|
|
60
60
|
"required": ["declaration", "name", "type", "comment", "location"]
|
61
61
|
},
|
62
62
|
"global": {
|
63
|
-
"title": "Global declaration: `$DEBUG:
|
63
|
+
"title": "Global declaration: `$DEBUG: boolish`, ...",
|
64
64
|
"type": "object",
|
65
65
|
"properties": {
|
66
66
|
"declaration": {
|
data/sig/errors.rbs
CHANGED
@@ -16,9 +16,23 @@ module RBS
|
|
16
16
|
class BaseError < StandardError
|
17
17
|
end
|
18
18
|
|
19
|
+
interface _Location
|
20
|
+
%a{pure} def location: () -> Location[untyped, untyped]?
|
21
|
+
end
|
22
|
+
|
23
|
+
interface _DetailedMessage
|
24
|
+
def detailed_message: (**untyped) -> String
|
25
|
+
end
|
26
|
+
|
27
|
+
module DetailedMessageable : _Location, _DetailedMessage
|
28
|
+
def detailed_message: (?highlight: boolish, **untyped) -> String
|
29
|
+
end
|
30
|
+
|
19
31
|
# Error class for errors raised during parsing.
|
20
32
|
#
|
21
33
|
class ParsingError < BaseError
|
34
|
+
include DetailedMessageable
|
35
|
+
|
22
36
|
attr_reader location: Location[untyped, untyped]
|
23
37
|
attr_reader error_message: String
|
24
38
|
attr_reader token_type: String
|
@@ -67,6 +81,8 @@ module RBS
|
|
67
81
|
end
|
68
82
|
|
69
83
|
class NoTypeFoundError < DefinitionError
|
84
|
+
include DetailedMessageable
|
85
|
+
|
70
86
|
attr_reader type_name: TypeName
|
71
87
|
attr_reader location: Location[untyped, untyped]?
|
72
88
|
|
@@ -85,6 +101,8 @@ module RBS
|
|
85
101
|
end
|
86
102
|
|
87
103
|
class NoSelfTypeFoundError < DefinitionError
|
104
|
+
include DetailedMessageable
|
105
|
+
|
88
106
|
attr_reader type_name: TypeName
|
89
107
|
attr_reader location: Location[untyped, untyped]?
|
90
108
|
|
@@ -96,6 +114,8 @@ module RBS
|
|
96
114
|
end
|
97
115
|
|
98
116
|
class NoMixinFoundError < DefinitionError
|
117
|
+
include DetailedMessageable
|
118
|
+
|
99
119
|
attr_reader type_name: TypeName
|
100
120
|
attr_reader member: AST::Members::t
|
101
121
|
|
@@ -107,6 +127,8 @@ module RBS
|
|
107
127
|
end
|
108
128
|
|
109
129
|
class DuplicatedMethodDefinitionError < DefinitionError
|
130
|
+
include DetailedMessageable
|
131
|
+
|
110
132
|
type ty = Types::ClassSingleton | Types::ClassInstance | Types::Interface
|
111
133
|
type original = DefinitionBuilder::MethodBuilder::Methods::Definition::original
|
112
134
|
|
@@ -143,6 +165,8 @@ module RBS
|
|
143
165
|
# ```
|
144
166
|
#
|
145
167
|
class DuplicatedInterfaceMethodDefinitionError < DefinitionError
|
168
|
+
include DetailedMessageable
|
169
|
+
|
146
170
|
type ty = Types::ClassSingleton | Types::ClassInstance | Types::Interface
|
147
171
|
type mixin_member = AST::Members::Include | AST::Members::Extend
|
148
172
|
|
@@ -155,11 +179,15 @@ module RBS
|
|
155
179
|
def type_name: () -> TypeName
|
156
180
|
|
157
181
|
def qualified_method_name: () -> String
|
182
|
+
|
183
|
+
def location: () -> AST::Members::Mixin::loc?
|
158
184
|
end
|
159
185
|
|
160
186
|
# The `alias` member declares an alias from unknown method
|
161
187
|
#
|
162
188
|
class UnknownMethodAliasError < DefinitionError
|
189
|
+
include DetailedMessageable
|
190
|
+
|
163
191
|
attr_reader type_name: TypeName
|
164
192
|
attr_reader original_name: Symbol
|
165
193
|
attr_reader aliased_name: Symbol
|
@@ -178,12 +206,16 @@ module RBS
|
|
178
206
|
# The *overloading* method definition cannot find *non-overloading* method definition
|
179
207
|
#
|
180
208
|
class InvalidOverloadMethodError < DefinitionError
|
209
|
+
include DetailedMessageable
|
210
|
+
|
181
211
|
attr_reader type_name: TypeName
|
182
212
|
attr_reader method_name: Symbol
|
183
213
|
attr_reader kind: :instance | :singleton
|
184
214
|
attr_reader members: Array[AST::Members::MethodDefinition]
|
185
215
|
|
186
216
|
def initialize: (type_name: TypeName, method_name: Symbol, kind: :instance | :singleton, members: Array[AST::Members::MethodDefinition]) -> void
|
217
|
+
|
218
|
+
def location: () -> AST::Members::MethodDefinition::loc?
|
187
219
|
end
|
188
220
|
|
189
221
|
class GenericParameterMismatchError < LoadingError
|
@@ -201,6 +233,8 @@ module RBS
|
|
201
233
|
end
|
202
234
|
|
203
235
|
class InvalidVarianceAnnotationError < DefinitionError
|
236
|
+
include DetailedMessageable
|
237
|
+
|
204
238
|
attr_reader type_name: TypeName
|
205
239
|
attr_reader param: AST::TypeParam
|
206
240
|
attr_reader location: Location[untyped, untyped]?
|
@@ -209,6 +243,8 @@ module RBS
|
|
209
243
|
end
|
210
244
|
|
211
245
|
class RecursiveAliasDefinitionError < DefinitionError
|
246
|
+
include DetailedMessageable
|
247
|
+
|
212
248
|
type ty = Types::ClassInstance | Types::ClassSingleton | Types::Interface
|
213
249
|
type defn = DefinitionBuilder::MethodBuilder::Methods::Definition
|
214
250
|
|
@@ -223,6 +259,8 @@ module RBS
|
|
223
259
|
# MixinClassError is raised if a include/prepend/extend has a class (not a module) to mix-in
|
224
260
|
#
|
225
261
|
class MixinClassError < DefinitionError
|
262
|
+
include DetailedMessageable
|
263
|
+
|
226
264
|
type member = AST::Members::Include | AST::Members::Prepend | AST::Members::Extend
|
227
265
|
|
228
266
|
attr_reader type_name: TypeName
|
@@ -240,6 +278,8 @@ module RBS
|
|
240
278
|
# InheritModuleError is raised if a class definition inherits a module (not a class)
|
241
279
|
#
|
242
280
|
class InheritModuleError < DefinitionError
|
281
|
+
include DetailedMessageable
|
282
|
+
|
243
283
|
attr_reader super_decl: AST::Declarations::Class::Super
|
244
284
|
|
245
285
|
def initialize: (AST::Declarations::Class::Super) -> void
|
@@ -254,6 +294,8 @@ module RBS
|
|
254
294
|
end
|
255
295
|
|
256
296
|
class RecursiveTypeAliasError < BaseError
|
297
|
+
include DetailedMessageable
|
298
|
+
|
257
299
|
attr_reader alias_names: Array[TypeName]
|
258
300
|
attr_reader location: Location[untyped, untyped]?
|
259
301
|
|
@@ -263,6 +305,8 @@ module RBS
|
|
263
305
|
end
|
264
306
|
|
265
307
|
class NonregularTypeAliasError < BaseError
|
308
|
+
include DetailedMessageable
|
309
|
+
|
266
310
|
# Diagnostic reported from `TypeAliasRegularity`.
|
267
311
|
attr_reader diagnostic: TypeAliasRegularity::Diagnostic
|
268
312
|
|
@@ -273,6 +317,8 @@ module RBS
|
|
273
317
|
end
|
274
318
|
|
275
319
|
class CyclicTypeParameterBound < BaseError
|
320
|
+
include DetailedMessageable
|
321
|
+
|
276
322
|
attr_reader location: Location[untyped, untyped]?
|
277
323
|
|
278
324
|
# Array of parameters which contains cyclic dependencies.
|
@@ -295,16 +341,24 @@ module RBS
|
|
295
341
|
# ```
|
296
342
|
#
|
297
343
|
class InconsistentClassModuleAliasError < BaseError
|
344
|
+
include DetailedMessageable
|
345
|
+
|
298
346
|
attr_reader alias_entry: Environment::ModuleAliasEntry | Environment::ClassAliasEntry
|
299
347
|
|
300
348
|
def initialize: (Environment::ModuleAliasEntry | Environment::ClassAliasEntry) -> void
|
349
|
+
|
350
|
+
def location: () -> AST::Declarations::AliasDecl::loc?
|
301
351
|
end
|
302
352
|
|
303
353
|
# A module/class alias declaration is cyclic
|
304
354
|
#
|
305
355
|
class CyclicClassAliasDefinitionError < BaseError
|
356
|
+
include DetailedMessageable
|
357
|
+
|
306
358
|
attr_reader alias_entry: Environment::ModuleAliasEntry | Environment::ClassAliasEntry
|
307
359
|
|
308
360
|
def initialize: (Environment::ModuleAliasEntry | Environment::ClassAliasEntry) -> void
|
361
|
+
|
362
|
+
def location: () -> AST::Declarations::AliasDecl::loc?
|
309
363
|
end
|
310
364
|
end
|
data/sig/parser.rbs
CHANGED
@@ -2,7 +2,7 @@ module RBS
|
|
2
2
|
class Parser
|
3
3
|
# Parse a method type and return it
|
4
4
|
#
|
5
|
-
# When `range` keyword is specified, it starts parsing from the `begin` to the `
|
5
|
+
# When `range` keyword is specified, it starts parsing from the `begin` to the `end` of the range.
|
6
6
|
#
|
7
7
|
# ```ruby
|
8
8
|
# RBS::Parser.parse_method_type("() -> void") # => `() -> void`
|
@@ -25,7 +25,7 @@ module RBS
|
|
25
25
|
|
26
26
|
# Parse a type and return it
|
27
27
|
#
|
28
|
-
# When `range` keyword is specified, it starts parsing from the `begin` to the `
|
28
|
+
# When `range` keyword is specified, it starts parsing from the `begin` to the `end` of the range.
|
29
29
|
#
|
30
30
|
# ```ruby
|
31
31
|
# RBS::Parser.parse_type("String") # => `String`
|