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
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
module RBS
|
|
2
|
+
module AST
|
|
3
|
+
module Ruby
|
|
4
|
+
module Declarations
|
|
5
|
+
type t = ClassDecl | ModuleDecl
|
|
6
|
+
|
|
7
|
+
class Base
|
|
8
|
+
attr_reader buffer: Buffer
|
|
9
|
+
|
|
10
|
+
include Helpers::ConstantHelper
|
|
11
|
+
include Helpers::LocationHelper
|
|
12
|
+
|
|
13
|
+
def initialize: (Buffer) -> void
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
class ClassDecl < Base
|
|
17
|
+
type member = t | Members::t
|
|
18
|
+
|
|
19
|
+
attr_reader class_name: TypeName
|
|
20
|
+
|
|
21
|
+
attr_reader node: Prism::ClassNode
|
|
22
|
+
|
|
23
|
+
attr_reader members: Array[member]
|
|
24
|
+
|
|
25
|
+
def initialize: (Buffer, TypeName, Prism::ClassNode) -> void
|
|
26
|
+
|
|
27
|
+
def each_decl: () { (t) -> void } -> void
|
|
28
|
+
| () -> Enumerator[t]
|
|
29
|
+
|
|
30
|
+
def super_class: () -> nil
|
|
31
|
+
|
|
32
|
+
def type_params: () -> Array[AST::TypeParam]
|
|
33
|
+
|
|
34
|
+
def location: () -> Location
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
class ModuleDecl < Base
|
|
38
|
+
type member = t | Members::t
|
|
39
|
+
|
|
40
|
+
attr_reader module_name: TypeName
|
|
41
|
+
|
|
42
|
+
attr_reader node: Prism::ModuleNode
|
|
43
|
+
|
|
44
|
+
attr_reader members: Array[member]
|
|
45
|
+
|
|
46
|
+
def initialize: (Buffer, TypeName, Prism::ModuleNode) -> void
|
|
47
|
+
|
|
48
|
+
def each_decl: () { (t) -> void } -> void
|
|
49
|
+
| () -> Enumerator[t]
|
|
50
|
+
|
|
51
|
+
def type_params: () -> Array[AST::TypeParam]
|
|
52
|
+
|
|
53
|
+
def location: () -> Location
|
|
54
|
+
|
|
55
|
+
def self_types: () -> Array[AST::Declarations::Module::Self]
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
module RBS
|
|
2
|
+
module AST
|
|
3
|
+
module Ruby
|
|
4
|
+
module Members
|
|
5
|
+
class Base
|
|
6
|
+
attr_reader buffer: Buffer
|
|
7
|
+
|
|
8
|
+
def initialize: (Buffer) -> void
|
|
9
|
+
|
|
10
|
+
include Helpers::LocationHelper
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
type t = DefMember
|
|
14
|
+
|
|
15
|
+
class MethodTypeAnnotation
|
|
16
|
+
class DocStyle
|
|
17
|
+
attr_accessor return_type_annotation: Annotations::ReturnTypeAnnotation | Annotations::NodeTypeAssertion | nil
|
|
18
|
+
|
|
19
|
+
def initialize: () -> void
|
|
20
|
+
|
|
21
|
+
def map_type_name: () { (TypeName) -> TypeName } -> self
|
|
22
|
+
|
|
23
|
+
def method_type: () -> MethodType
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
type type_annotations = DocStyle | Array[Annotations::ColonMethodTypeAnnotation | Annotations::MethodTypesAnnotation] | nil
|
|
27
|
+
|
|
28
|
+
attr_reader type_annotations: type_annotations
|
|
29
|
+
|
|
30
|
+
def initialize: (type_annotations: type_annotations) -> void
|
|
31
|
+
|
|
32
|
+
def map_type_name: { (TypeName) -> TypeName } -> self
|
|
33
|
+
|
|
34
|
+
# Returns the method type annotations from the comment block
|
|
35
|
+
#
|
|
36
|
+
# Returns a tuple of `DefAnnotations` object, array of unused leading annotations, and unused trailing annotation.
|
|
37
|
+
#
|
|
38
|
+
def self.build: (CommentBlock? leading_block, CommentBlock? trailing_block, Array[Symbol]) -> [
|
|
39
|
+
MethodTypeAnnotation,
|
|
40
|
+
Array[Annotations::leading_annotation | CommentBlock::AnnotationSyntaxError],
|
|
41
|
+
Annotations::trailing_annotation | CommentBlock::AnnotationSyntaxError | nil
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
# Returns `true` if it doesn't have any annotation
|
|
45
|
+
def empty?: () -> bool
|
|
46
|
+
|
|
47
|
+
# Returns the method type overloads
|
|
48
|
+
#
|
|
49
|
+
def overloads: () -> Array[AST::Members::MethodDefinition::Overload]
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
class DefMember < Base
|
|
53
|
+
class Overload = AST::Members::MethodDefinition::Overload
|
|
54
|
+
|
|
55
|
+
attr_reader name: Symbol
|
|
56
|
+
attr_reader node: Prism::DefNode
|
|
57
|
+
attr_reader method_type: MethodTypeAnnotation
|
|
58
|
+
|
|
59
|
+
def initialize: (Buffer, Symbol name, Prism::DefNode node, MethodTypeAnnotation) -> void
|
|
60
|
+
|
|
61
|
+
def location: () -> Location
|
|
62
|
+
|
|
63
|
+
def overloads: () -> Array[Overload]
|
|
64
|
+
|
|
65
|
+
def overloading?: () -> bool
|
|
66
|
+
|
|
67
|
+
def annotations: () -> Array[AST::Annotation]
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
data/sig/buffer.rbs
CHANGED
|
@@ -6,21 +6,45 @@ module RBS
|
|
|
6
6
|
type loc = [Integer, Integer]
|
|
7
7
|
|
|
8
8
|
# Name to identify Buffer.
|
|
9
|
-
attr_reader name:
|
|
9
|
+
attr_reader name: Pathname
|
|
10
10
|
|
|
11
11
|
# The content of the buffer.
|
|
12
12
|
attr_reader content: String
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
attr_reader parent: [Buffer, Array[Range[Integer]]]?
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def initialize: (name: untyped name, content: String content) -> void
|
|
16
|
+
def initialize: (name: Pathname name, content: String content) -> void
|
|
17
|
+
| (content: String content, parent: [Buffer, Array[Range[Integer]]] parent) -> void
|
|
19
18
|
|
|
19
|
+
# Array of lines of the content, without the EOL
|
|
20
|
+
#
|
|
21
|
+
# ```rb
|
|
22
|
+
# buffer = Buffer.new(name: name, content: "123\nabc")
|
|
23
|
+
# buffer.lines # => ["123", "abc"]
|
|
24
|
+
# ```
|
|
25
|
+
#
|
|
26
|
+
# If the input has EOL at the end of the file, the `lines` has an empty string at the end.
|
|
27
|
+
#
|
|
28
|
+
# ```rb
|
|
29
|
+
# buffer = Buffer.new(name: name, content: "123\nabc\n")
|
|
30
|
+
# buffer.lines # => ["123", "abc", ""]
|
|
31
|
+
# ```
|
|
32
|
+
#
|
|
20
33
|
def lines: () -> Array[String]
|
|
21
34
|
|
|
35
|
+
@ranges: Array[Range[Integer]]?
|
|
36
|
+
# Array of ranges that stores the ranges of the each line, without the EOL
|
|
37
|
+
#
|
|
38
|
+
# ```rb
|
|
39
|
+
# buffer = Buffer.new(name: name, content: "123\nabc\n")
|
|
40
|
+
# buffer.ranges # => [0...3, 4...7, 8...8]
|
|
41
|
+
# ```
|
|
42
|
+
#
|
|
22
43
|
def ranges: () -> Array[Range[Integer]]
|
|
23
44
|
|
|
45
|
+
# Returns the number of the lines
|
|
46
|
+
def line_count: () -> Integer
|
|
47
|
+
|
|
24
48
|
# Translate position to location.
|
|
25
49
|
def pos_to_loc: (Integer pos) -> loc
|
|
26
50
|
|
|
@@ -28,5 +52,39 @@ module RBS
|
|
|
28
52
|
def loc_to_pos: (loc loc) -> Integer
|
|
29
53
|
|
|
30
54
|
def last_position: () -> Integer
|
|
55
|
+
|
|
56
|
+
# Translate `Prism::Location` to `RBS::Location` attached to this buffer
|
|
57
|
+
#
|
|
58
|
+
# It assumes the `Prism::Location` has a source which is equivalent to `self`.
|
|
59
|
+
#
|
|
60
|
+
def rbs_location: (Prism::Location) -> Location
|
|
61
|
+
| (Prism::Location, Prism::Location) -> Location
|
|
62
|
+
|
|
63
|
+
# Construct a buffer from substrings of this buffer.
|
|
64
|
+
#
|
|
65
|
+
# The returned buffer contains lines from given ranges.
|
|
66
|
+
#
|
|
67
|
+
# ```rb
|
|
68
|
+
# buffer = Buffer.new(name: name, content: <<TEXT)
|
|
69
|
+
# 12345
|
|
70
|
+
# abcde
|
|
71
|
+
# ABCDE
|
|
72
|
+
# TEXT
|
|
73
|
+
#
|
|
74
|
+
# buffer.sub_buffer(lines: [0...1, 2...3]) # => Buffer with content = 1\n34
|
|
75
|
+
# buffer.sub_buffer(lines: [5..7]) # => Raises an error because the range contains newline
|
|
76
|
+
# ```
|
|
77
|
+
#
|
|
78
|
+
%a{pure} def sub_buffer: (lines: Array[Range[Integer]]) -> Buffer
|
|
79
|
+
|
|
80
|
+
%a{pure} def parent_buffer: () -> Buffer?
|
|
81
|
+
|
|
82
|
+
%a{pure} def parent_position: (Integer) -> Integer?
|
|
83
|
+
|
|
84
|
+
%a{pure} def absolute_position: (Integer) -> Integer?
|
|
85
|
+
|
|
86
|
+
%a{pure} def top_buffer: () -> Buffer
|
|
87
|
+
|
|
88
|
+
%a{pure} def detach: () -> Buffer
|
|
31
89
|
end
|
|
32
90
|
end
|
data/sig/definition.rbs
CHANGED
data/sig/definition_builder.rbs
CHANGED
|
@@ -103,7 +103,7 @@ module RBS
|
|
|
103
103
|
|
|
104
104
|
def validate_type_params: (Definition, ancestors: AncestorBuilder::OneAncestors, methods: MethodBuilder::Methods) -> void
|
|
105
105
|
|
|
106
|
-
def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t) -> Location[untyped, untyped]?
|
|
106
|
+
def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t | AST::Ruby::Declarations::t) -> Location[untyped, untyped]?
|
|
107
107
|
|
|
108
108
|
def validate_variable: (Definition::Variable) -> void
|
|
109
109
|
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module RBS
|
|
2
|
+
class Environment
|
|
3
|
+
# Represents a class entry in the environment
|
|
4
|
+
#
|
|
5
|
+
# ```rb
|
|
6
|
+
# entry = ClassEntry.new(TypeName.parse("::String"))
|
|
7
|
+
# entry << [nil, declaration]
|
|
8
|
+
# entry << [[nil, TypeName.parse("::Kernel")], declaration]
|
|
9
|
+
# ```
|
|
10
|
+
class ClassEntry
|
|
11
|
+
attr_reader name: TypeName
|
|
12
|
+
|
|
13
|
+
type declaration = AST::Declarations::Class | AST::Ruby::Declarations::ClassDecl
|
|
14
|
+
|
|
15
|
+
type context_decl = [Resolver::context, declaration]
|
|
16
|
+
|
|
17
|
+
attr_reader context_decls: Array[context_decl]
|
|
18
|
+
|
|
19
|
+
@primary_decl: declaration?
|
|
20
|
+
|
|
21
|
+
def initialize: (TypeName) -> void
|
|
22
|
+
|
|
23
|
+
def <<: (context_decl) -> self
|
|
24
|
+
|
|
25
|
+
def each_decl: { (declaration) -> void } -> void
|
|
26
|
+
| () -> Enumerator[declaration]
|
|
27
|
+
|
|
28
|
+
# Returns true if the entry doesn't have any declaration
|
|
29
|
+
#
|
|
30
|
+
def empty?: () -> bool
|
|
31
|
+
|
|
32
|
+
# Find the *primary* declaration of the class
|
|
33
|
+
#
|
|
34
|
+
# * Returns the first declaration with super class
|
|
35
|
+
# * Returns the first declaration if the declaration doesn't have super class
|
|
36
|
+
#
|
|
37
|
+
%a{pure} def primary_decl: () -> declaration
|
|
38
|
+
|
|
39
|
+
# Returns the generics declaration
|
|
40
|
+
#
|
|
41
|
+
def type_params: () -> Array[AST::TypeParam]
|
|
42
|
+
|
|
43
|
+
# Confirms if the type parameters in the declaration are compatible
|
|
44
|
+
#
|
|
45
|
+
# * Raises `GenericParameterMismatchError` if incompatible declaration is detected.
|
|
46
|
+
#
|
|
47
|
+
def validate_type_params: () -> void
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module RBS
|
|
2
|
+
class Environment
|
|
3
|
+
# Represents a class entry in the environment
|
|
4
|
+
#
|
|
5
|
+
# ```rb
|
|
6
|
+
# entry = ModuleEntry.new(TypeName.parse("::Kernel"))
|
|
7
|
+
# entry << [nil, declaration]
|
|
8
|
+
# entry << [[nil, TypeName.parse("::Object")], declaration]
|
|
9
|
+
# ```
|
|
10
|
+
#
|
|
11
|
+
class ModuleEntry
|
|
12
|
+
attr_reader name: TypeName
|
|
13
|
+
|
|
14
|
+
type declaration = AST::Declarations::Module | AST::Ruby::Declarations::ModuleDecl
|
|
15
|
+
|
|
16
|
+
type context_decl = [Resolver::context, declaration]
|
|
17
|
+
|
|
18
|
+
attr_reader context_decls: Array[context_decl]
|
|
19
|
+
|
|
20
|
+
def initialize: (TypeName) -> void
|
|
21
|
+
|
|
22
|
+
def <<: (context_decl) -> self
|
|
23
|
+
|
|
24
|
+
def each_decl: { (declaration) -> void } -> void
|
|
25
|
+
| () -> Enumerator[declaration]
|
|
26
|
+
|
|
27
|
+
# Returns true if the entry doesn't have any declaration
|
|
28
|
+
#
|
|
29
|
+
def empty?: () -> bool
|
|
30
|
+
|
|
31
|
+
# Returns the first declaration
|
|
32
|
+
#
|
|
33
|
+
# This method helps using the class with `ClassEntry` objects.
|
|
34
|
+
#
|
|
35
|
+
def primary_decl: () -> declaration
|
|
36
|
+
|
|
37
|
+
# Returns the generics declaration
|
|
38
|
+
#
|
|
39
|
+
def type_params: () -> Array[AST::TypeParam]
|
|
40
|
+
|
|
41
|
+
# Confirms if the type parameters in the declaration are compatible
|
|
42
|
+
#
|
|
43
|
+
# * Raises `GenericParameterMismatchError` if incompatible declaration is detected.
|
|
44
|
+
#
|
|
45
|
+
def validate_type_params: () -> void
|
|
46
|
+
|
|
47
|
+
def self_types: () -> Array[AST::Declarations::Module::Self]
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
data/sig/environment.rbs
CHANGED
|
@@ -2,75 +2,14 @@ module RBS
|
|
|
2
2
|
class Environment
|
|
3
3
|
type module_decl = AST::Declarations::Class | AST::Declarations::Module
|
|
4
4
|
|
|
5
|
-
interface _ModuleOrClass
|
|
6
|
-
def name: () -> TypeName
|
|
7
|
-
|
|
8
|
-
def type_params: () -> Array[AST::TypeParam]
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
interface _NamedDecl
|
|
12
|
-
def name: () -> TypeName
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
module ContextUtil
|
|
16
|
-
def calculate_context: (Array[_NamedDecl]) -> Resolver::context
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
# Name of object, it's (multiple) declarations with the outer module declarations
|
|
20
|
-
#
|
|
21
|
-
class MultiEntry[M < _ModuleOrClass]
|
|
22
|
-
class D[M < _ModuleOrClass]
|
|
23
|
-
attr_reader decl: M
|
|
24
|
-
attr_reader outer: Array[module_decl]
|
|
25
|
-
|
|
26
|
-
def initialize: (decl: M, outer: Array[module_decl]) -> void
|
|
27
|
-
|
|
28
|
-
include ContextUtil
|
|
29
|
-
|
|
30
|
-
@context: Resolver::context
|
|
31
|
-
|
|
32
|
-
def context: () -> Resolver::context
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
attr_reader name: TypeName
|
|
36
|
-
attr_reader decls: Array[D[M]]
|
|
37
|
-
|
|
38
|
-
@primary: D[M]?
|
|
39
|
-
|
|
40
|
-
def initialize: (name: TypeName) -> void
|
|
41
|
-
|
|
42
|
-
def insert: (decl: M, outer: Array[module_decl]) -> void
|
|
43
|
-
|
|
44
|
-
def validate_type_params: () -> void
|
|
45
|
-
|
|
46
|
-
def compatible_params?: (Array[AST::TypeParam], Array[AST::TypeParam]) -> boolish
|
|
47
|
-
|
|
48
|
-
def type_params: () -> Array[AST::TypeParam]
|
|
49
|
-
|
|
50
|
-
def primary: () -> D[M]
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
class ModuleEntry < MultiEntry[AST::Declarations::Module]
|
|
54
|
-
def self_types: () -> Array[AST::Declarations::Module::Self]
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
class ClassEntry < MultiEntry[AST::Declarations::Class]
|
|
58
|
-
end
|
|
59
|
-
|
|
60
5
|
# Name of object, it's (single) declaration, and the outer module declarations
|
|
61
6
|
#
|
|
62
7
|
class SingleEntry[N, D]
|
|
63
8
|
attr_reader name: N
|
|
64
9
|
attr_reader decl: D
|
|
65
|
-
attr_reader
|
|
66
|
-
|
|
67
|
-
def initialize: (name: N, decl: D, outer: Array[module_decl]) -> void
|
|
68
|
-
|
|
69
|
-
include ContextUtil
|
|
70
|
-
|
|
71
|
-
@context: Resolver::context
|
|
10
|
+
attr_reader context: Resolver::context
|
|
72
11
|
|
|
73
|
-
def
|
|
12
|
+
def initialize: (name: N, decl: D, context: Resolver::context) -> void
|
|
74
13
|
end
|
|
75
14
|
|
|
76
15
|
class ModuleAliasEntry < SingleEntry[TypeName, AST::Declarations::ModuleAlias]
|
|
@@ -91,8 +30,9 @@ module RBS
|
|
|
91
30
|
class GlobalEntry < SingleEntry[Symbol, AST::Declarations::Global]
|
|
92
31
|
end
|
|
93
32
|
|
|
94
|
-
#
|
|
95
|
-
|
|
33
|
+
# Array of source objects loaded in the environment
|
|
34
|
+
#
|
|
35
|
+
attr_reader sources: Array[Source::t]
|
|
96
36
|
|
|
97
37
|
# Class declarations
|
|
98
38
|
attr_reader class_decls: Hash[TypeName, ModuleEntry | ClassEntry]
|
|
@@ -111,10 +51,6 @@ module RBS
|
|
|
111
51
|
# Global declarations
|
|
112
52
|
attr_reader global_decls: Hash[Symbol, GlobalEntry]
|
|
113
53
|
|
|
114
|
-
# A hash from Buffer to it's contents
|
|
115
|
-
#
|
|
116
|
-
attr_reader signatures: Hash[Buffer, [Array[AST::Directives::t], Array[AST::Declarations::t]]]
|
|
117
|
-
|
|
118
54
|
def initialize: () -> void
|
|
119
55
|
|
|
120
56
|
def initialize_copy: (Environment) -> void
|
|
@@ -123,15 +59,21 @@ module RBS
|
|
|
123
59
|
#
|
|
124
60
|
def self.from_loader: (EnvironmentLoader) -> Environment
|
|
125
61
|
|
|
126
|
-
def
|
|
62
|
+
def add_source: (Source::t) -> void
|
|
63
|
+
|
|
64
|
+
def each_rbs_source: () { (Source::RBS) -> void } -> void
|
|
65
|
+
| () -> Enumerator[Source::RBS]
|
|
127
66
|
|
|
128
|
-
|
|
67
|
+
def each_ruby_source: () { (Source::Ruby) -> void } -> void
|
|
68
|
+
| () -> Enumerator[Source::Ruby]
|
|
69
|
+
|
|
70
|
+
# Insert a declaration into the environment
|
|
129
71
|
#
|
|
130
|
-
def
|
|
72
|
+
private def insert_rbs_decl: (AST::Declarations::t, context: Resolver::context, namespace: Namespace) -> void
|
|
131
73
|
|
|
132
74
|
# Insert a declaration into the environment
|
|
133
75
|
#
|
|
134
|
-
private def
|
|
76
|
+
private def insert_ruby_decl: (AST::Ruby::Declarations::t, context: Resolver::context, namespace: Namespace) -> void
|
|
135
77
|
|
|
136
78
|
# Resolve all type names in the environment to absolute type names.
|
|
137
79
|
# Relative type name will be left if absolute type name cannot be found.
|
|
@@ -190,58 +132,22 @@ module RBS
|
|
|
190
132
|
# Returns true if the type name is a class alias
|
|
191
133
|
def class_alias?: (TypeName) -> bool
|
|
192
134
|
|
|
193
|
-
|
|
194
|
-
#
|
|
195
|
-
# Returns `nil` when:
|
|
196
|
-
#
|
|
197
|
-
# * The type name is not found
|
|
198
|
-
# * The type name is not a class
|
|
199
|
-
#
|
|
200
|
-
# It normalizes when `normalized: true` is given -- returns `ClassEntry` or `nil`.
|
|
201
|
-
#
|
|
202
|
-
def class_entry: (TypeName, normalized: true) -> ClassEntry?
|
|
203
|
-
| (TypeName, ?normalized: bool) -> (ClassEntry | ClassAliasEntry | nil)
|
|
135
|
+
def class_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | nil)
|
|
204
136
|
|
|
205
137
|
# Returns ClassEntry if the class definition is found, normalized in case of alias
|
|
206
138
|
#
|
|
207
|
-
%a{deprecated: Use `class_entry(type_name, normalized: true)` instead. }
|
|
208
139
|
def normalized_class_entry: (TypeName) -> ClassEntry?
|
|
209
140
|
|
|
210
|
-
|
|
211
|
-
#
|
|
212
|
-
# Returns `nil` when:
|
|
213
|
-
#
|
|
214
|
-
# * The type name is not found
|
|
215
|
-
# * The type name is not a module
|
|
216
|
-
#
|
|
217
|
-
# It normalizes when `normalized: true` is given -- returns `ModuleEntry` or `nil`.
|
|
218
|
-
#
|
|
219
|
-
def module_entry: (TypeName, normalized: true) -> ModuleEntry?
|
|
220
|
-
| (TypeName, ?normalized: bool) -> (ModuleEntry | ModuleAliasEntry | nil)
|
|
141
|
+
def module_entry: (TypeName) -> (ModuleEntry | ModuleAliasEntry | nil)
|
|
221
142
|
|
|
222
143
|
# Returns ModuleEntry if the module definition is found, normalized in case of alias
|
|
223
144
|
#
|
|
224
|
-
%a{deprecated: Use `module_entry(type_name, normalized: true)` instead. }
|
|
225
145
|
def normalized_module_entry: (TypeName) -> ModuleEntry?
|
|
226
146
|
|
|
227
|
-
|
|
228
|
-
#
|
|
229
|
-
# The entry is one of ClassEntry, ModuleEntry, ConstantEntry, ClassAliasEntry, or ModuleAliasEntry.
|
|
230
|
-
# When `normalized: true` is given, it returns normalized entry -- one of ClassEntry, ModuleEntry, or ConstantEntry.
|
|
231
|
-
#
|
|
232
|
-
# Returns `nil` if not found.
|
|
233
|
-
#
|
|
234
|
-
def constant_entry: (TypeName, normalized: true) -> (ClassEntry | ModuleEntry | ConstantEntry | nil)
|
|
235
|
-
| (TypeName, ?normalized: bool) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | ConstantEntry | nil)
|
|
147
|
+
def constant_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | ConstantEntry | nil)
|
|
236
148
|
|
|
237
|
-
|
|
238
|
-
#
|
|
239
|
-
# Normalizes when `normalized: true` is given.
|
|
240
|
-
#
|
|
241
|
-
def module_class_entry: (TypeName, normalized: true) -> (ClassEntry | ModuleEntry | nil)
|
|
242
|
-
| (TypeName, ?normalized: bool) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | nil)
|
|
149
|
+
def module_class_entry: (TypeName) -> (ClassEntry | ClassAliasEntry | ModuleEntry | ModuleAliasEntry | nil)
|
|
243
150
|
|
|
244
|
-
%a{deprecated: Use `module_class_entry(type_name, normalized: true)` instead. }
|
|
245
151
|
def normalized_module_class_entry: (TypeName) -> (ClassEntry | ModuleEntry | nil)
|
|
246
152
|
|
|
247
153
|
@normalize_module_name_cache: Hash[TypeName, TypeName | false | nil]
|
|
@@ -252,39 +158,26 @@ module RBS
|
|
|
252
158
|
# * Returns `nil` if the rhs name cannot be found
|
|
253
159
|
# * Returns `false` if the name is cyclic
|
|
254
160
|
#
|
|
255
|
-
# Note that this method assumes the declarations have resolved type names.
|
|
256
|
-
#
|
|
257
161
|
def normalize_module_name?: (TypeName) -> (TypeName | nil | false)
|
|
258
162
|
|
|
259
|
-
# Returns the original module name that is defined with `module
|
|
163
|
+
# Returns the original module name that is defined with `module` declaration
|
|
260
164
|
#
|
|
261
|
-
# * Raises an error if given type name is not module
|
|
165
|
+
# * Raises an error if given type name is not module
|
|
262
166
|
# * Calls `#absolute!` for relative module names
|
|
263
167
|
# * Returns the name itself if the name cannot be normalized to a class/module
|
|
264
168
|
#
|
|
265
|
-
# Note that this method assumes the declarations have resolved type names.
|
|
266
|
-
#
|
|
267
169
|
def normalize_module_name: (TypeName) -> TypeName
|
|
268
170
|
|
|
269
|
-
# Returns the original module name that is defined with `module`/`class` declaration
|
|
270
|
-
#
|
|
271
|
-
# * Raises an error if given type name is not a module/class
|
|
272
|
-
def normalize_module_name!: (TypeName) -> TypeName
|
|
273
|
-
|
|
274
171
|
# Returns a normalized module/class name or a type name with a normalized namespace
|
|
275
172
|
#
|
|
276
173
|
# * Calls `#absolute!` for relative module names
|
|
277
174
|
# * Returns `nil` if the typename cannot be found
|
|
278
175
|
# * Returns `false` if the name is cyclic
|
|
279
176
|
#
|
|
280
|
-
# Note that this method assumes the declarations have resolved type names.
|
|
281
|
-
#
|
|
282
177
|
def normalize_type_name?: (TypeName) -> (TypeName | nil | false)
|
|
283
178
|
|
|
284
179
|
# Normalize the type name or raises an error
|
|
285
180
|
#
|
|
286
|
-
# Note that this method assumes the declarations have resolved type names.
|
|
287
|
-
#
|
|
288
181
|
def normalize_type_name!: (TypeName) -> TypeName
|
|
289
182
|
|
|
290
183
|
# Returns a normalized module/class name or a type name with a normalized namespace
|
|
@@ -292,8 +185,6 @@ module RBS
|
|
|
292
185
|
# * Calls `#absolute!` for relative module names
|
|
293
186
|
# * Returns the typename itself if the name cannot be normalized
|
|
294
187
|
#
|
|
295
|
-
# Note that this method assumes the declarations have resolved type names.
|
|
296
|
-
#
|
|
297
188
|
def normalize_type_name: (TypeName) -> TypeName
|
|
298
189
|
|
|
299
190
|
# Returns `true` if given type name is normalized
|
|
@@ -315,7 +206,7 @@ module RBS
|
|
|
315
206
|
|
|
316
207
|
def append_context: (Resolver::context, module_decl) -> Resolver::context
|
|
317
208
|
|
|
318
|
-
def resolve_declaration: (Resolver::TypeNameResolver resolver, UseMap map, AST::Declarations::t decl,
|
|
209
|
+
def resolve_declaration: (Resolver::TypeNameResolver resolver, UseMap map, AST::Declarations::t decl, context: Resolver::context, prefix: Namespace) -> AST::Declarations::t
|
|
319
210
|
|
|
320
211
|
def resolve_member: (Resolver::TypeNameResolver, UseMap map, AST::Members::t, context: Resolver::context) -> AST::Members::t
|
|
321
212
|
|
|
@@ -323,8 +214,12 @@ module RBS
|
|
|
323
214
|
|
|
324
215
|
def resolve_type_params: (Resolver::TypeNameResolver resolver, UseMap map, Array[AST::TypeParam], context: Resolver::context) -> Array[AST::TypeParam]
|
|
325
216
|
|
|
326
|
-
def
|
|
217
|
+
def resolve_ruby_decl: (Resolver::TypeNameResolver, AST::Ruby::Declarations::t, context: Resolver::context, prefix: Namespace) -> AST::Ruby::Declarations::t
|
|
218
|
+
|
|
219
|
+
def resolve_ruby_member: (Resolver::TypeNameResolver, AST::Ruby::Members::t, context: Resolver::context) -> AST::Ruby::Members::t
|
|
220
|
+
|
|
221
|
+
def absolute_type: (Resolver::TypeNameResolver, UseMap? map, Types::t, context: Resolver::context) -> Types::t
|
|
327
222
|
|
|
328
|
-
def absolute_type_name: (Resolver::TypeNameResolver, UseMap map, TypeName, context: Resolver::context) -> TypeName
|
|
223
|
+
def absolute_type_name: (Resolver::TypeNameResolver, UseMap? map, TypeName, context: Resolver::context) -> TypeName
|
|
329
224
|
end
|
|
330
225
|
end
|
data/sig/errors.rbs
CHANGED
|
@@ -226,28 +226,35 @@ module RBS
|
|
|
226
226
|
class InvalidOverloadMethodError < DefinitionError
|
|
227
227
|
include DetailedMessageable
|
|
228
228
|
|
|
229
|
+
type member = AST::Members::MethodDefinition | AST::Ruby::Members::DefMember
|
|
230
|
+
|
|
229
231
|
attr_reader type_name: TypeName
|
|
230
232
|
attr_reader method_name: Symbol
|
|
231
233
|
attr_reader kind: :instance | :singleton
|
|
232
|
-
attr_reader members: Array[
|
|
234
|
+
attr_reader members: Array[member]
|
|
233
235
|
|
|
234
|
-
def initialize: (type_name: TypeName, method_name: Symbol, kind: :instance | :singleton, members: Array[
|
|
236
|
+
def initialize: (type_name: TypeName, method_name: Symbol, kind: :instance | :singleton, members: Array[member]) -> void
|
|
235
237
|
|
|
236
238
|
def location: () -> AST::Members::MethodDefinition::loc?
|
|
237
239
|
end
|
|
238
240
|
|
|
239
241
|
class GenericParameterMismatchError < LoadingError
|
|
242
|
+
type decl = AST::Declarations::Class | AST::Declarations::Module
|
|
243
|
+
| AST::Ruby::Declarations::ClassDecl | AST::Ruby::Declarations::ModuleDecl
|
|
244
|
+
|
|
240
245
|
attr_reader name: TypeName
|
|
241
|
-
attr_reader decl:
|
|
246
|
+
attr_reader decl: decl
|
|
242
247
|
|
|
243
|
-
def initialize: (name: TypeName, decl:
|
|
248
|
+
def initialize: (name: TypeName, decl: decl, ?location: Location) -> void
|
|
244
249
|
end
|
|
245
250
|
|
|
246
251
|
class DuplicatedDeclarationError < LoadingError
|
|
252
|
+
type declaration = AST::Declarations::t | AST::Ruby::Declarations::t
|
|
253
|
+
|
|
247
254
|
attr_reader name: TypeName | Symbol
|
|
248
|
-
attr_reader decls: Array[
|
|
255
|
+
attr_reader decls: Array[declaration]
|
|
249
256
|
|
|
250
|
-
def initialize: (TypeName | Symbol, *
|
|
257
|
+
def initialize: (TypeName | Symbol, *declaration) -> void
|
|
251
258
|
end
|
|
252
259
|
|
|
253
260
|
class InvalidVarianceAnnotationError < DefinitionError
|