rbs 3.10.0 → 4.0.0.dev.1
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 +3 -3
- data/.github/workflows/ruby.yml +24 -35
- data/.github/workflows/typecheck.yml +3 -1
- data/.github/workflows/windows.yml +2 -2
- data/.gitignore +0 -4
- data/CHANGELOG.md +0 -88
- data/README.md +1 -38
- data/Rakefile +20 -142
- data/Steepfile +1 -0
- data/config.yml +43 -1
- data/core/array.rbs +46 -100
- data/core/complex.rbs +21 -32
- data/core/dir.rbs +2 -2
- data/core/encoding.rbs +9 -6
- data/core/enumerable.rbs +3 -90
- data/core/enumerator.rbs +1 -18
- data/core/errno.rbs +0 -8
- data/core/errors.rbs +1 -28
- data/core/exception.rbs +2 -2
- data/core/fiber.rbs +4 -5
- data/core/file.rbs +12 -27
- data/core/file_test.rbs +1 -1
- data/core/float.rbs +22 -209
- data/core/gc.rbs +281 -417
- data/core/hash.rbs +727 -1024
- data/core/integer.rbs +38 -78
- data/core/io/buffer.rbs +7 -18
- data/core/io/wait.rbs +33 -11
- data/core/io.rbs +12 -14
- data/core/kernel.rbs +51 -57
- data/core/marshal.rbs +1 -1
- data/core/match_data.rbs +1 -1
- data/core/math.rbs +3 -42
- data/core/method.rbs +6 -14
- data/core/module.rbs +17 -88
- data/core/nil_class.rbs +3 -3
- data/core/numeric.rbs +16 -16
- data/core/object.rbs +3 -3
- data/core/object_space.rbs +15 -21
- data/core/proc.rbs +8 -15
- data/core/process.rbs +2 -2
- data/core/ractor.rbs +437 -278
- data/core/range.rbs +8 -7
- data/core/rational.rbs +24 -37
- data/core/rbs/unnamed/argf.rbs +2 -2
- data/core/rbs/unnamed/env_class.rbs +1 -1
- data/core/rbs/unnamed/random.rbs +2 -4
- data/core/regexp.rbs +20 -25
- data/core/ruby_vm.rbs +4 -6
- data/core/rubygems/errors.rbs +70 -3
- data/core/rubygems/rubygems.rbs +79 -11
- data/core/rubygems/version.rbs +3 -2
- data/core/set.rbs +359 -488
- data/core/string.rbs +1228 -3153
- data/core/struct.rbs +1 -1
- data/core/symbol.rbs +4 -4
- data/core/thread.rbs +29 -92
- data/core/time.rbs +9 -35
- data/core/trace_point.rbs +4 -7
- data/core/unbound_method.rbs +6 -14
- data/docs/collection.md +2 -2
- data/docs/gem.md +1 -0
- data/docs/sigs.md +3 -3
- data/ext/rbs_extension/ast_translation.c +1077 -944
- data/ext/rbs_extension/ast_translation.h +0 -7
- data/ext/rbs_extension/class_constants.c +83 -71
- data/ext/rbs_extension/class_constants.h +7 -4
- data/ext/rbs_extension/extconf.rb +2 -24
- data/ext/rbs_extension/legacy_location.c +172 -173
- data/ext/rbs_extension/legacy_location.h +3 -8
- data/ext/rbs_extension/main.c +289 -239
- data/ext/rbs_extension/rbs_extension.h +0 -3
- data/ext/rbs_extension/rbs_string_bridging.h +0 -4
- data/include/rbs/ast.h +98 -37
- data/include/rbs/defines.h +12 -38
- data/include/rbs/lexer.h +114 -126
- data/include/rbs/location.h +14 -14
- data/include/rbs/parser.h +37 -21
- data/include/rbs/string.h +5 -3
- data/include/rbs/util/rbs_allocator.h +19 -40
- data/include/rbs/util/rbs_assert.h +1 -12
- data/include/rbs/util/rbs_constant_pool.h +3 -3
- data/include/rbs/util/rbs_encoding.h +1 -3
- data/include/rbs/util/rbs_unescape.h +1 -2
- data/lib/rbs/ast/ruby/annotations.rb +119 -0
- data/lib/rbs/ast/ruby/comment_block.rb +221 -0
- data/lib/rbs/ast/ruby/declarations.rb +86 -0
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
- data/lib/rbs/ast/ruby/members.rb +213 -0
- data/lib/rbs/buffer.rb +104 -24
- data/lib/rbs/cli/validate.rb +40 -35
- data/lib/rbs/cli.rb +5 -6
- data/lib/rbs/collection/config/lockfile_generator.rb +0 -1
- data/lib/rbs/collection.rb +0 -1
- data/lib/rbs/definition.rb +6 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +65 -62
- data/lib/rbs/definition_builder/method_builder.rb +45 -30
- data/lib/rbs/definition_builder.rb +44 -9
- data/lib/rbs/environment/class_entry.rb +69 -0
- data/lib/rbs/environment/module_entry.rb +66 -0
- data/lib/rbs/environment.rb +244 -218
- data/lib/rbs/environment_loader.rb +3 -3
- data/lib/rbs/errors.rb +5 -4
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +206 -0
- data/lib/rbs/location_aux.rb +35 -3
- data/lib/rbs/parser_aux.rb +11 -6
- data/lib/rbs/prototype/runtime.rb +2 -2
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +38 -124
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/subtractor.rb +4 -3
- data/lib/rbs/test/type_check.rb +0 -14
- data/lib/rbs/types.rb +1 -3
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +13 -1
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +1 -0
- data/sig/ancestor_builder.rbs +1 -1
- data/sig/ast/ruby/annotations.rbs +110 -0
- data/sig/ast/ruby/comment_block.rbs +119 -0
- data/sig/ast/ruby/declarations.rbs +60 -0
- data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
- data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
- data/sig/ast/ruby/members.rbs +72 -0
- data/sig/buffer.rbs +63 -5
- data/sig/definition.rbs +1 -0
- data/sig/definition_builder.rbs +1 -1
- data/sig/environment/class_entry.rbs +50 -0
- data/sig/environment/module_entry.rbs +50 -0
- data/sig/environment.rbs +28 -133
- data/sig/errors.rbs +13 -6
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +87 -0
- data/sig/location.rbs +32 -7
- data/sig/manifest.yaml +1 -0
- data/sig/method_builder.rbs +7 -4
- data/sig/parser.rbs +16 -20
- data/sig/resolver/type_name_resolver.rbs +7 -38
- data/sig/source.rbs +48 -0
- data/sig/types.rbs +1 -4
- data/src/ast.c +290 -201
- data/src/lexer.c +2813 -2902
- data/src/lexer.re +4 -0
- data/src/lexstate.c +155 -169
- data/src/location.c +40 -40
- data/src/parser.c +2665 -2433
- data/src/string.c +48 -0
- data/src/util/rbs_allocator.c +77 -80
- data/src/util/rbs_assert.c +10 -10
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +15 -13
- data/src/util/rbs_encoding.c +4062 -20097
- data/src/util/rbs_unescape.c +48 -85
- data/stdlib/bigdecimal/0/big_decimal.rbs +82 -100
- data/stdlib/bigdecimal-math/0/big_math.rbs +8 -169
- data/stdlib/cgi/0/core.rbs +396 -2
- data/stdlib/cgi/0/manifest.yaml +0 -1
- data/stdlib/coverage/0/coverage.rbs +1 -3
- data/stdlib/date/0/date.rbs +59 -67
- data/stdlib/date/0/date_time.rbs +1 -1
- data/stdlib/delegate/0/delegator.rbs +7 -10
- data/stdlib/erb/0/erb.rbs +347 -737
- data/stdlib/fileutils/0/fileutils.rbs +13 -18
- data/stdlib/forwardable/0/forwardable.rbs +0 -3
- data/stdlib/json/0/json.rbs +48 -68
- data/stdlib/net-http/0/net-http.rbs +0 -3
- data/stdlib/objspace/0/objspace.rbs +4 -9
- data/stdlib/open-uri/0/open-uri.rbs +0 -40
- data/stdlib/openssl/0/openssl.rbs +228 -331
- data/stdlib/optparse/0/optparse.rbs +3 -3
- data/{core → stdlib/pathname/0}/pathname.rbs +355 -255
- data/stdlib/psych/0/psych.rbs +3 -3
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +68 -25
- data/stdlib/ripper/0/ripper.rbs +2 -5
- data/stdlib/singleton/0/singleton.rbs +0 -3
- data/stdlib/socket/0/socket.rbs +1 -13
- data/stdlib/socket/0/tcp_socket.rbs +2 -10
- data/stdlib/stringio/0/stringio.rbs +85 -1176
- data/stdlib/strscan/0/string_scanner.rbs +31 -31
- data/stdlib/tempfile/0/tempfile.rbs +3 -3
- data/stdlib/time/0/time.rbs +1 -1
- data/stdlib/timeout/0/timeout.rbs +7 -63
- data/stdlib/tsort/0/cyclic.rbs +0 -3
- data/stdlib/uri/0/common.rbs +2 -11
- data/stdlib/uri/0/file.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +16 -17
- data/stdlib/uri/0/rfc2396_parser.rbs +7 -6
- data/stdlib/zlib/0/zstream.rbs +0 -1
- metadata +40 -12
- data/.clang-format +0 -74
- data/.clangd +0 -2
- data/.github/workflows/c-check.yml +0 -54
- data/core/ruby.rbs +0 -53
- data/docs/aliases.md +0 -79
- data/docs/encoding.md +0 -56
- data/ext/rbs_extension/compat.h +0 -10
- data/stdlib/cgi-escape/0/escape.rbs +0 -153
|
@@ -5,36 +5,17 @@ module RBS
|
|
|
5
5
|
class TypeNameResolver
|
|
6
6
|
attr_reader :all_names
|
|
7
7
|
attr_reader :cache
|
|
8
|
-
attr_reader :
|
|
8
|
+
attr_reader :env
|
|
9
9
|
|
|
10
|
-
def initialize(
|
|
11
|
-
@all_names =
|
|
12
|
-
@aliases = aliases
|
|
10
|
+
def initialize(env)
|
|
11
|
+
@all_names = Set[]
|
|
13
12
|
@cache = {}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def self.new(*args)
|
|
17
|
-
if args.size == 1 && args[0].is_a?(Environment)
|
|
18
|
-
build(args[0])
|
|
19
|
-
else
|
|
20
|
-
super
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def self.build(env)
|
|
25
|
-
all_names = Set.new #: Set[TypeName]
|
|
13
|
+
@env = env
|
|
26
14
|
|
|
27
15
|
all_names.merge(env.class_decls.keys)
|
|
28
16
|
all_names.merge(env.interface_decls.keys)
|
|
29
17
|
all_names.merge(env.type_alias_decls.keys)
|
|
30
|
-
|
|
31
|
-
aliases = {} #: Hash[TypeName, [TypeName, context]]
|
|
32
|
-
|
|
33
|
-
env.class_alias_decls.each do |name, entry|
|
|
34
|
-
aliases[name] = [entry.decl.old_name, entry.context]
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
new(all_names, aliases)
|
|
18
|
+
all_names.merge(env.class_alias_decls.keys)
|
|
38
19
|
end
|
|
39
20
|
|
|
40
21
|
def try_cache(query)
|
|
@@ -45,131 +26,64 @@ module RBS
|
|
|
45
26
|
end
|
|
46
27
|
|
|
47
28
|
def resolve(type_name, context:)
|
|
48
|
-
if type_name.absolute?
|
|
29
|
+
if type_name.absolute?
|
|
49
30
|
return type_name
|
|
50
31
|
end
|
|
51
32
|
|
|
52
33
|
try_cache([type_name, context]) do
|
|
53
|
-
|
|
54
|
-
resolve_namespace0(type_name, context, Set.new) || nil
|
|
55
|
-
else
|
|
56
|
-
namespace = type_name.namespace
|
|
34
|
+
head, tail = partition(type_name)
|
|
57
35
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
36
|
+
head = resolve_in(head, context)
|
|
37
|
+
|
|
38
|
+
if head
|
|
39
|
+
if tail
|
|
40
|
+
absolute_name = tail.with_prefix(head.to_namespace)
|
|
41
|
+
if env.normalize_type_name?(absolute_name)
|
|
42
|
+
absolute_name
|
|
64
43
|
end
|
|
44
|
+
else
|
|
45
|
+
head
|
|
65
46
|
end
|
|
66
47
|
end
|
|
67
48
|
end
|
|
68
49
|
end
|
|
69
50
|
|
|
70
|
-
def
|
|
71
|
-
if type_name.
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
raise "Type name must be a class name: #{type_name}"
|
|
77
|
-
end
|
|
51
|
+
def partition(type_name)
|
|
52
|
+
if type_name.namespace.empty?
|
|
53
|
+
head = type_name.name
|
|
54
|
+
tail = nil
|
|
55
|
+
else
|
|
56
|
+
head, *tail = type_name.namespace.path
|
|
78
57
|
|
|
79
|
-
|
|
80
|
-
ns = resolve_namespace0(type_name, context, Set.new) or return ns
|
|
81
|
-
end
|
|
82
|
-
end
|
|
58
|
+
head or raise
|
|
83
59
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
60
|
+
tail = TypeName.new(
|
|
61
|
+
name: type_name.name,
|
|
62
|
+
namespace: Namespace.new(absolute: false, path: tail)
|
|
63
|
+
)
|
|
87
64
|
end
|
|
88
|
-
end
|
|
89
65
|
|
|
90
|
-
|
|
91
|
-
if aliases.key?(type_name)
|
|
92
|
-
type_name
|
|
93
|
-
end
|
|
66
|
+
[head, tail]
|
|
94
67
|
end
|
|
95
68
|
|
|
96
|
-
def
|
|
69
|
+
def resolve_in(head, context)
|
|
97
70
|
if context
|
|
98
|
-
|
|
99
|
-
case
|
|
71
|
+
parent, child = context
|
|
72
|
+
case child
|
|
100
73
|
when false
|
|
101
|
-
|
|
102
|
-
else
|
|
103
|
-
has_type_name?(inner) or raise "Context must be normalized: #{inner.inspect}"
|
|
104
|
-
has_type_name?(TypeName.new(name: type_name, namespace: inner.to_namespace)) || resolve_type_name(type_name, outer)
|
|
105
|
-
end
|
|
106
|
-
else
|
|
107
|
-
type_name = TypeName.new(name: type_name, namespace: Namespace.root)
|
|
108
|
-
has_type_name?(type_name)
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
def resolve_head_namespace(head, context)
|
|
113
|
-
if context
|
|
114
|
-
outer, inner = context
|
|
115
|
-
case inner
|
|
116
|
-
when false
|
|
117
|
-
resolve_head_namespace(head, outer)
|
|
74
|
+
resolve_in(head, parent)
|
|
118
75
|
when TypeName
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
has_type_name?(type_name) || aliased_name?(type_name) || resolve_head_namespace(head, outer)
|
|
76
|
+
name = TypeName.new(name: head, namespace: child.to_namespace)
|
|
77
|
+
has_name?(name) || resolve_in(head, parent)
|
|
122
78
|
end
|
|
123
79
|
else
|
|
124
|
-
|
|
125
|
-
has_type_name?(type_name) || aliased_name?(type_name)
|
|
126
|
-
end
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
def normalize_namespace(type_name, rhs, context, visited)
|
|
130
|
-
if visited.include?(type_name)
|
|
131
|
-
# Cycle detected
|
|
132
|
-
return false
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
visited << type_name
|
|
136
|
-
|
|
137
|
-
begin
|
|
138
|
-
resolve_namespace0(rhs, context, visited)
|
|
139
|
-
ensure
|
|
140
|
-
visited.delete(type_name)
|
|
80
|
+
has_name?(TypeName.new(name: head, namespace: Namespace.root))
|
|
141
81
|
end
|
|
142
82
|
end
|
|
143
83
|
|
|
144
|
-
def
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
head = head #: Symbol
|
|
148
|
-
|
|
149
|
-
head =
|
|
150
|
-
if type_name.absolute?
|
|
151
|
-
root_name = TypeName.new(name: head, namespace: Namespace.root)
|
|
152
|
-
has_type_name?(root_name) || aliased_name?(root_name)
|
|
153
|
-
else
|
|
154
|
-
resolve_head_namespace(head, context)
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
if head
|
|
158
|
-
if (rhs, context = aliases.fetch(head, nil))
|
|
159
|
-
head = normalize_namespace(head, rhs, context, visited) or return head
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
tail.inject(head) do |namespace, name|
|
|
163
|
-
type_name = TypeName.new(name: name, namespace: namespace.to_namespace)
|
|
164
|
-
case
|
|
165
|
-
when has_type_name?(type_name)
|
|
166
|
-
type_name
|
|
167
|
-
when (rhs, context = aliases.fetch(type_name, nil))
|
|
168
|
-
m = normalize_namespace(type_name, rhs, context, visited) or return m
|
|
169
|
-
else
|
|
170
|
-
return nil
|
|
171
|
-
end
|
|
172
|
-
end
|
|
84
|
+
def has_name?(full_name)
|
|
85
|
+
if all_names.include?(full_name)
|
|
86
|
+
full_name
|
|
173
87
|
end
|
|
174
88
|
end
|
|
175
89
|
end
|
data/lib/rbs/source.rb
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module RBS
|
|
4
|
+
module Source
|
|
5
|
+
class RBS
|
|
6
|
+
attr_reader :buffer, :directives, :declarations
|
|
7
|
+
|
|
8
|
+
def initialize(buffer, directives, decls)
|
|
9
|
+
@buffer = buffer
|
|
10
|
+
@directives = directives
|
|
11
|
+
@declarations = decls
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def each_type_name(&block)
|
|
15
|
+
if block
|
|
16
|
+
set = Set[] #: Set[TypeName]
|
|
17
|
+
declarations.each do |decl|
|
|
18
|
+
each_declaration_type_name(set, decl, &block)
|
|
19
|
+
end
|
|
20
|
+
else
|
|
21
|
+
enum_for :each_type_name
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def each_declaration_type_name(names, decl, &block)
|
|
26
|
+
case decl
|
|
27
|
+
when AST::Declarations::Class
|
|
28
|
+
decl.each_decl { each_declaration_type_name(names, _1, &block) }
|
|
29
|
+
type_name = decl.name
|
|
30
|
+
when AST::Declarations::Module
|
|
31
|
+
decl.each_decl { each_declaration_type_name(names, _1, &block) }
|
|
32
|
+
type_name = decl.name
|
|
33
|
+
when AST::Declarations::Interface
|
|
34
|
+
type_name = decl.name
|
|
35
|
+
when AST::Declarations::TypeAlias
|
|
36
|
+
type_name = decl.name
|
|
37
|
+
when AST::Declarations::ModuleAlias
|
|
38
|
+
type_name = decl.new_name
|
|
39
|
+
when AST::Declarations::ClassAlias
|
|
40
|
+
type_name = decl.new_name
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
if type_name
|
|
44
|
+
unless names.include?(type_name)
|
|
45
|
+
yield type_name
|
|
46
|
+
names << type_name
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class Ruby
|
|
53
|
+
attr_reader :buffer
|
|
54
|
+
attr_reader :prism_result
|
|
55
|
+
attr_reader :declarations
|
|
56
|
+
attr_reader :diagnostics
|
|
57
|
+
|
|
58
|
+
def initialize(buffer, prism, declarations, diagnostics)
|
|
59
|
+
@buffer = buffer
|
|
60
|
+
@prism_result = prism
|
|
61
|
+
@declarations = declarations
|
|
62
|
+
@diagnostics = diagnostics
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
def each_type_name(&block)
|
|
66
|
+
if block
|
|
67
|
+
names = Set[] #: Set[TypeName]
|
|
68
|
+
declarations.each do |decl|
|
|
69
|
+
each_declaration_type_name(names, decl, &block)
|
|
70
|
+
end
|
|
71
|
+
else
|
|
72
|
+
enum_for :each_type_name
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def each_declaration_type_name(names, decl, &block)
|
|
77
|
+
case decl
|
|
78
|
+
when AST::Ruby::Declarations::ClassDecl
|
|
79
|
+
decl.each_decl do |d|
|
|
80
|
+
each_declaration_type_name(names, d, &block)
|
|
81
|
+
end
|
|
82
|
+
type_name = decl.class_name
|
|
83
|
+
when AST::Ruby::Declarations::ModuleDecl
|
|
84
|
+
decl.each_decl do |d|
|
|
85
|
+
each_declaration_type_name(names, d, &block)
|
|
86
|
+
end
|
|
87
|
+
type_name = decl.module_name
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
if type_name
|
|
91
|
+
unless names.include?(type_name)
|
|
92
|
+
yield type_name
|
|
93
|
+
names << type_name
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
data/lib/rbs/subtractor.rb
CHANGED
|
@@ -129,9 +129,10 @@ module RBS
|
|
|
129
129
|
|
|
130
130
|
entry = @subtrahend.class_decls[owner]
|
|
131
131
|
return unless entry
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
132
|
+
entry.each_decl do |d|
|
|
133
|
+
next unless d.is_a?(AST::Declarations::Base)
|
|
134
|
+
d.members.each { |m| block.call(m) }
|
|
135
|
+
end
|
|
135
136
|
end
|
|
136
137
|
|
|
137
138
|
private def mixin_exist?(owner, mixin, context:)
|
data/lib/rbs/test/type_check.rb
CHANGED
|
@@ -288,19 +288,6 @@ module RBS
|
|
|
288
288
|
values << args
|
|
289
289
|
nil
|
|
290
290
|
end
|
|
291
|
-
when nil
|
|
292
|
-
values = []
|
|
293
|
-
count = 10_000
|
|
294
|
-
|
|
295
|
-
ret = val.each do |*args|
|
|
296
|
-
count -= 1
|
|
297
|
-
values << args
|
|
298
|
-
break if count <= 0
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
if count == 0
|
|
302
|
-
ret = self
|
|
303
|
-
end
|
|
304
291
|
else
|
|
305
292
|
values = []
|
|
306
293
|
ret = val.each do |*args|
|
|
@@ -364,7 +351,6 @@ module RBS
|
|
|
364
351
|
value(val, builder.expand_alias2(type.name.absolute!, type.args))
|
|
365
352
|
when Types::Tuple
|
|
366
353
|
Test.call(val, IS_AP, ::Array) &&
|
|
367
|
-
type.types.length == val.length &&
|
|
368
354
|
type.types.map.with_index {|ty, index| value(val[index], ty) }.all?
|
|
369
355
|
when Types::Record
|
|
370
356
|
Test::call(val, IS_AP, ::Hash) &&
|
data/lib/rbs/types.rb
CHANGED
|
@@ -1339,10 +1339,8 @@ module RBS
|
|
|
1339
1339
|
attr_reader :type
|
|
1340
1340
|
attr_reader :required
|
|
1341
1341
|
attr_reader :self_type
|
|
1342
|
-
attr_reader :location
|
|
1343
1342
|
|
|
1344
|
-
def initialize(
|
|
1345
|
-
@location = location
|
|
1343
|
+
def initialize(type:, required:, self_type: nil)
|
|
1346
1344
|
@type = type
|
|
1347
1345
|
@required = required ? true : false
|
|
1348
1346
|
@self_type = self_type
|
data/lib/rbs/version.rb
CHANGED
data/lib/rbs.rb
CHANGED
|
@@ -4,12 +4,13 @@ require "rbs/version"
|
|
|
4
4
|
|
|
5
5
|
require "set"
|
|
6
6
|
require "json"
|
|
7
|
-
require "pathname"
|
|
7
|
+
require "pathname"
|
|
8
8
|
require "pp"
|
|
9
9
|
require "ripper"
|
|
10
10
|
require "logger"
|
|
11
11
|
require "tsort"
|
|
12
12
|
require "strscan"
|
|
13
|
+
require "prism"
|
|
13
14
|
|
|
14
15
|
require "rbs/errors"
|
|
15
16
|
require "rbs/buffer"
|
|
@@ -24,8 +25,19 @@ require "rbs/ast/declarations"
|
|
|
24
25
|
require "rbs/ast/members"
|
|
25
26
|
require "rbs/ast/annotation"
|
|
26
27
|
require "rbs/ast/visitor"
|
|
28
|
+
require "rbs/ast/ruby/comment_block"
|
|
29
|
+
require "rbs/ast/ruby/helpers/constant_helper"
|
|
30
|
+
require "rbs/ast/ruby/helpers/location_helper"
|
|
31
|
+
require "rbs/ast/ruby/annotations"
|
|
32
|
+
require "rbs/ast/ruby/declarations"
|
|
33
|
+
require "rbs/ast/ruby/members"
|
|
34
|
+
require "rbs/source"
|
|
35
|
+
require "rbs/inline_parser"
|
|
36
|
+
require "rbs/inline_parser/comment_association"
|
|
27
37
|
require "rbs/environment"
|
|
28
38
|
require "rbs/environment/use_map"
|
|
39
|
+
require "rbs/environment/class_entry"
|
|
40
|
+
require "rbs/environment/module_entry"
|
|
29
41
|
require "rbs/environment_loader"
|
|
30
42
|
require "rbs/builtin_names"
|
|
31
43
|
require "rbs/definition"
|
data/lib/rdoc/discover.rb
CHANGED
data/lib/rdoc_plugin/parser.rb
CHANGED
|
@@ -76,7 +76,7 @@ module RBS
|
|
|
76
76
|
method.visibility = decl.visibility
|
|
77
77
|
method.call_seq = decl.overloads.map {|overload| "#{decl.name.to_s}#{overload.method_type.to_s}" }.join("\n")
|
|
78
78
|
if loc = decl.location
|
|
79
|
-
method.start_collecting_tokens
|
|
79
|
+
method.start_collecting_tokens
|
|
80
80
|
method.add_token({ line_no: 1, char_no: 1, kind: :on_comment, text: "# File #{@top_level.relative_name}, line(s) #{loc.start_line}:#{loc.end_line}\n" })
|
|
81
81
|
method.add_token({ line_no: 1, char_no: 1, text: loc.source })
|
|
82
82
|
method.line = loc.start_line
|
data/rbs.gemspec
CHANGED
data/sig/ancestor_builder.rbs
CHANGED
|
@@ -146,7 +146,7 @@ module RBS
|
|
|
146
146
|
extended_modules: Array[Definition::Ancestor::Instance]?,
|
|
147
147
|
extended_interfaces: Array[Definition::Ancestor::Instance]?) -> void
|
|
148
148
|
|
|
149
|
-
def mixin_ancestors0: (AST::Declarations::Class | AST::Declarations::Module | AST::Declarations::Interface,
|
|
149
|
+
def mixin_ancestors0: (AST::Declarations::Class | AST::Declarations::Module | AST::Declarations::Interface | AST::Ruby::Declarations::ClassDecl | AST::Ruby::Declarations::ModuleDecl,
|
|
150
150
|
TypeName,
|
|
151
151
|
align_params: Substitution?,
|
|
152
152
|
included_modules: Array[Definition::Ancestor::Instance]?,
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
module RBS
|
|
2
|
+
module AST
|
|
3
|
+
module Ruby
|
|
4
|
+
module Annotations
|
|
5
|
+
type leading_annotation = ColonMethodTypeAnnotation
|
|
6
|
+
| MethodTypesAnnotation
|
|
7
|
+
| SkipAnnotation
|
|
8
|
+
| ReturnTypeAnnotation
|
|
9
|
+
|
|
10
|
+
type trailing_annotation = NodeTypeAssertion
|
|
11
|
+
|
|
12
|
+
type t = leading_annotation | trailing_annotation
|
|
13
|
+
|
|
14
|
+
class Base
|
|
15
|
+
# Location that covers all of the annotation
|
|
16
|
+
#
|
|
17
|
+
attr_reader location: Location
|
|
18
|
+
|
|
19
|
+
# Location of `@rbs`, `@rbs!`, or `:` prefix
|
|
20
|
+
#
|
|
21
|
+
attr_reader prefix_location: Location
|
|
22
|
+
|
|
23
|
+
def initialize: (Location location, Location prefix_location) -> void
|
|
24
|
+
|
|
25
|
+
def buffer: () -> Buffer
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# `: TYPE` annotation attached to nodes
|
|
29
|
+
#
|
|
30
|
+
class NodeTypeAssertion < Base
|
|
31
|
+
attr_reader type: Types::t
|
|
32
|
+
|
|
33
|
+
def initialize: (location: Location, prefix_location: Location, type: Types::t) -> void
|
|
34
|
+
|
|
35
|
+
def map_type_name: () { (TypeName) -> TypeName } -> self
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# `: METHOD-TYPE` annotation in leading comments
|
|
39
|
+
#
|
|
40
|
+
class ColonMethodTypeAnnotation < Base
|
|
41
|
+
attr_reader annotations: Array[AST::Annotation]
|
|
42
|
+
|
|
43
|
+
attr_reader method_type: MethodType
|
|
44
|
+
|
|
45
|
+
def initialize: (location: Location, prefix_location: Location, annotations: Array[AST::Annotation], method_type: MethodType) -> void
|
|
46
|
+
|
|
47
|
+
def map_type_name: () { (TypeName) -> TypeName } -> self
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# `@rbs METHOD-TYPEs` annotation in leading comments
|
|
51
|
+
#
|
|
52
|
+
# ```
|
|
53
|
+
# @rbs () -> void | %a{foo} () -> String
|
|
54
|
+
# ^^^^ -- prefix_location
|
|
55
|
+
# ^ -- vertical_bar_locations[0]
|
|
56
|
+
# ```
|
|
57
|
+
class MethodTypesAnnotation < Base
|
|
58
|
+
class Overload = AST::Members::MethodDefinition::Overload
|
|
59
|
+
|
|
60
|
+
attr_reader overloads: Array[Overload]
|
|
61
|
+
|
|
62
|
+
attr_reader vertical_bar_locations: Array[Location]
|
|
63
|
+
|
|
64
|
+
def initialize: (location: Location, prefix_location: Location, overloads: Array[Overload], vertical_bar_locations: Array[Location]) -> void
|
|
65
|
+
|
|
66
|
+
def map_type_name: () { (TypeName) -> TypeName } -> self
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
# `@rbs skip -- comment` annotation in leading comments
|
|
70
|
+
#
|
|
71
|
+
class SkipAnnotation < Base
|
|
72
|
+
attr_reader skip_location: Location
|
|
73
|
+
attr_reader comment_location: Location?
|
|
74
|
+
|
|
75
|
+
def initialize: (location: Location, prefix_location: Location, skip_location: Location, comment_location: Location?) -> void
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# `@rbs return: T -- comment` annotation in leading comments
|
|
79
|
+
#
|
|
80
|
+
# ```
|
|
81
|
+
# @rbs return: String -- Returns a string
|
|
82
|
+
# ^^^ -- prefix_location
|
|
83
|
+
# ^^^^^^ -- return_location
|
|
84
|
+
# ^ -- colon_location
|
|
85
|
+
# ^^^^^^^^^^^^^^^^^^^ -- comment
|
|
86
|
+
# ```
|
|
87
|
+
class ReturnTypeAnnotation < Base
|
|
88
|
+
attr_reader return_location: Location
|
|
89
|
+
|
|
90
|
+
attr_reader colon_location: Location
|
|
91
|
+
|
|
92
|
+
attr_reader return_type: Types::t
|
|
93
|
+
|
|
94
|
+
attr_reader comment_location: Location?
|
|
95
|
+
|
|
96
|
+
def initialize: (
|
|
97
|
+
location: Location,
|
|
98
|
+
prefix_location: Location,
|
|
99
|
+
return_location: Location,
|
|
100
|
+
colon_location: Location,
|
|
101
|
+
return_type: Types::t,
|
|
102
|
+
comment_location: Location?,
|
|
103
|
+
) -> void
|
|
104
|
+
|
|
105
|
+
def map_type_name: () { (TypeName) -> TypeName } -> self
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
use Prism::Comment
|
|
2
|
+
|
|
3
|
+
module RBS
|
|
4
|
+
module AST
|
|
5
|
+
module Ruby
|
|
6
|
+
# CommentBlock is a collection of comments
|
|
7
|
+
#
|
|
8
|
+
# ```ruby
|
|
9
|
+
# # Comment1 < block1
|
|
10
|
+
# # Comment2 <
|
|
11
|
+
#
|
|
12
|
+
# # Comment3 < block2
|
|
13
|
+
# ```
|
|
14
|
+
#
|
|
15
|
+
# A comment block is a *leading* block or *trailing* block.
|
|
16
|
+
#
|
|
17
|
+
# ```ruby
|
|
18
|
+
# # This is leading block.
|
|
19
|
+
# # This is the second line of the leading block.
|
|
20
|
+
#
|
|
21
|
+
# foo # This is trailing block.
|
|
22
|
+
# # This is second line of the trailing block.
|
|
23
|
+
# ```
|
|
24
|
+
#
|
|
25
|
+
# A leading block is a comment block where all of the comments are at the start of the line content.
|
|
26
|
+
# A trailing block is a comment block where the first comment of the block has something at the line before the comment.
|
|
27
|
+
#
|
|
28
|
+
class CommentBlock
|
|
29
|
+
attr_reader name: Pathname
|
|
30
|
+
|
|
31
|
+
# Sub buffer of the contents of the comments
|
|
32
|
+
#
|
|
33
|
+
attr_reader comment_buffer: Buffer
|
|
34
|
+
|
|
35
|
+
attr_reader offsets: Array[
|
|
36
|
+
[
|
|
37
|
+
Comment,
|
|
38
|
+
Integer, # -- prefix size
|
|
39
|
+
]
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
def initialize: (Buffer source_buffer, Array[Comment]) -> void
|
|
43
|
+
|
|
44
|
+
# Build comment block instances
|
|
45
|
+
def self.build: (Buffer, Array[Comment]) -> Array[instance]
|
|
46
|
+
|
|
47
|
+
# Returns true if the comment block is a *leading* comment, which is attached to the successor node
|
|
48
|
+
def leading?: () -> bool
|
|
49
|
+
|
|
50
|
+
# Returns true if the comment block is a *trailing* comment, which is attached to the predecessor node
|
|
51
|
+
def trailing?: () -> bool
|
|
52
|
+
|
|
53
|
+
# The line number of the first comment in the block
|
|
54
|
+
def start_line: () -> Integer
|
|
55
|
+
|
|
56
|
+
# The line number of the last comment in the block
|
|
57
|
+
def end_line: () -> Integer
|
|
58
|
+
|
|
59
|
+
# The character index of `#comment_buffer` at the start of the lines
|
|
60
|
+
#
|
|
61
|
+
def line_starts: () -> Array[Integer]
|
|
62
|
+
|
|
63
|
+
# Returns the text content of the comment
|
|
64
|
+
def text: (Integer index) -> String
|
|
65
|
+
|
|
66
|
+
# Yields paragraph and annotation
|
|
67
|
+
#
|
|
68
|
+
# A paragraph is a sequence of lines that are separated by annotations.
|
|
69
|
+
# An annotation starts with a line starting with `@rbs` or `:`, and may continue with lines that has more leading spaces.
|
|
70
|
+
#
|
|
71
|
+
# ```
|
|
72
|
+
# # Line 1 ^ Paragraph 1
|
|
73
|
+
# # Line 2 |
|
|
74
|
+
# # |
|
|
75
|
+
# # Line 3 v
|
|
76
|
+
# # @rbs ... < Annotation 1
|
|
77
|
+
# # @rbs ... ^ Annotation 2
|
|
78
|
+
# # ... |
|
|
79
|
+
# # |
|
|
80
|
+
# # ... v
|
|
81
|
+
# # ^ Paragraph 2
|
|
82
|
+
# # Line 4 |
|
|
83
|
+
# # Line 5 v
|
|
84
|
+
# ```
|
|
85
|
+
#
|
|
86
|
+
def each_paragraph: (Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void
|
|
87
|
+
| (Array[Symbol] variables) -> Enumerator[Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError]
|
|
88
|
+
|
|
89
|
+
# Returns a trailing annotation if it exists
|
|
90
|
+
#
|
|
91
|
+
# * Returns `nil` if the block is not a type annotation
|
|
92
|
+
# * Returns an annotation if the block has a type annotation
|
|
93
|
+
# * Returns AnnotationSyntaxError if the annotation has a syntax error
|
|
94
|
+
#
|
|
95
|
+
def trailing_annotation: (Array[Symbol] variables) -> (AST::Ruby::Annotations::trailing_annotation | AnnotationSyntaxError | nil)
|
|
96
|
+
|
|
97
|
+
class AnnotationSyntaxError
|
|
98
|
+
attr_reader location: Location
|
|
99
|
+
|
|
100
|
+
attr_reader error: ParsingError
|
|
101
|
+
|
|
102
|
+
def initialize: (Location, ParsingError) -> void
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
private def yield_paragraph: (Integer start_line, Integer current_line, Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void
|
|
106
|
+
|
|
107
|
+
private def yield_annotation: (Integer start_line, Integer end_line, Integer current_line, Array[Symbol] variables) { (Location | AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError) -> void } -> void
|
|
108
|
+
|
|
109
|
+
private def parse_annotation_lines: (Integer start_line, Integer end_line, Array[Symbol] variables) -> (AST::Ruby::Annotations::leading_annotation | AnnotationSyntaxError)
|
|
110
|
+
|
|
111
|
+
def comments: () -> Array[Comment]
|
|
112
|
+
|
|
113
|
+
def line_location: (Integer start_line, Integer end_line) -> Location
|
|
114
|
+
|
|
115
|
+
private def leading_annotation?: (Integer index) -> bool
|
|
116
|
+
end
|
|
117
|
+
end
|
|
118
|
+
end
|
|
119
|
+
end
|