rbs 2.8.4 → 3.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/CHANGELOG.md +0 -28
- data/Gemfile +1 -1
- data/Gemfile.lock +16 -16
- data/Rakefile +1 -9
- data/ext/rbs_extension/constants.c +2 -0
- data/ext/rbs_extension/constants.h +1 -0
- data/ext/rbs_extension/extconf.rb +1 -1
- data/ext/rbs_extension/parser.c +23 -13
- data/ext/rbs_extension/ruby_objs.c +15 -3
- data/ext/rbs_extension/ruby_objs.h +2 -1
- data/lib/rbs/ast/members.rb +49 -15
- data/lib/rbs/cli.rb +6 -1
- data/lib/rbs/collection/config/lockfile.rb +115 -0
- data/lib/rbs/collection/config/lockfile_generator.rb +89 -48
- data/lib/rbs/collection/config.rb +11 -39
- data/lib/rbs/collection/installer.rb +9 -13
- data/lib/rbs/collection/sources/base.rb +2 -2
- data/lib/rbs/collection/sources/git.rb +135 -62
- data/lib/rbs/collection/sources/rubygems.rb +10 -12
- data/lib/rbs/collection/sources/stdlib.rb +10 -13
- data/lib/rbs/collection/sources.rb +7 -1
- data/lib/rbs/collection.rb +1 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/method_builder.rb +3 -3
- data/lib/rbs/definition_builder.rb +449 -572
- data/lib/rbs/environment.rb +5 -3
- data/lib/rbs/environment_loader.rb +11 -10
- data/lib/rbs/locator.rb +2 -2
- data/lib/rbs/prototype/helpers.rb +29 -13
- data/lib/rbs/prototype/node_usage.rb +99 -0
- data/lib/rbs/prototype/rb.rb +3 -2
- data/lib/rbs/prototype/rbi.rb +6 -4
- data/lib/rbs/prototype/runtime.rb +25 -12
- data/lib/rbs/substitution.rb +19 -0
- data/lib/rbs/types.rb +1 -5
- data/lib/rbs/validator.rb +2 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/writer.rb +26 -17
- data/lib/rbs.rb +1 -0
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +1 -1
- data/schema/members.json +15 -10
- data/sig/collection/config/lockfile.rbs +80 -0
- data/sig/collection/config/lockfile_generator.rbs +55 -0
- data/sig/collection/config.rbs +5 -48
- data/sig/collection/installer.rbs +1 -1
- data/sig/collection/sources.rbs +66 -29
- data/sig/definition_builder.rbs +94 -81
- data/sig/environment_loader.rbs +1 -1
- data/sig/errors.rbs +21 -0
- data/sig/members.rbs +31 -7
- data/sig/prototype/node_usage.rbs +20 -0
- data/sig/shims/bundler.rbs +13 -0
- data/sig/shims/rubygems.rbs +9 -0
- data/sig/shims.rbs +0 -22
- data/sig/substitution.rbs +6 -0
- data/sig/writer.rbs +2 -0
- data/steep/Gemfile +3 -0
- data/steep/Gemfile.lock +61 -0
- metadata +13 -4
@@ -0,0 +1,55 @@
|
|
1
|
+
module RBS
|
2
|
+
module Collection
|
3
|
+
class Config
|
4
|
+
class LockfileGenerator
|
5
|
+
class GemfileLockMismatchError < StandardError
|
6
|
+
@expected: Pathname
|
7
|
+
|
8
|
+
@actual: Pathname
|
9
|
+
|
10
|
+
def initialize: (expected: Pathname, actual: Pathname) -> void
|
11
|
+
|
12
|
+
def message: () -> String
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader config: Config
|
16
|
+
attr_reader gemfile_lock: Bundler::LockfileParser
|
17
|
+
|
18
|
+
attr_reader lockfile: Lockfile
|
19
|
+
attr_reader existing_lockfile: Lockfile?
|
20
|
+
|
21
|
+
type gem_queue_entry = { name: String, version: String? }
|
22
|
+
|
23
|
+
@gem_queue: Array[gem_queue_entry]
|
24
|
+
|
25
|
+
def self.generate: (config: Config, gemfile_lock_path: Pathname, ?with_lockfile: boolish) -> Lockfile
|
26
|
+
|
27
|
+
def initialize: (config: Config, gemfile_lock_path: Pathname, with_lockfile: boolish) -> void
|
28
|
+
|
29
|
+
def generate: () -> void
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# Ensure if current `gemfile_lock_path` is the same with the path saved in `lock`
|
34
|
+
#
|
35
|
+
def validate_gemfile_lock_path!: (lock: Lockfile?, gemfile_lock_path: Pathname) -> void
|
36
|
+
|
37
|
+
def assign_gem: (name: String, version: String?, ignored_gems: Set[String], src_data: Sources::source_entry?) -> void
|
38
|
+
|
39
|
+
def assign_stdlib: (name: String, from_gem: String?) -> void
|
40
|
+
|
41
|
+
def gemfile_lock_gems: () { (untyped) -> void } -> void
|
42
|
+
|
43
|
+
def remove_ignored_gems!: () -> void
|
44
|
+
|
45
|
+
# Find a source of a gem from ones registered in `config.sources`
|
46
|
+
#
|
47
|
+
# Returns `nil` if no source contains the definition of the gem.
|
48
|
+
#
|
49
|
+
def find_source: (name: String) -> Sources::t?
|
50
|
+
|
51
|
+
def find_best_version: (version: String?, versions: Array[String]) -> Gem::Version
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
data/sig/collection/config.rbs
CHANGED
@@ -6,39 +6,6 @@ module RBS
|
|
6
6
|
def initialize: () -> void
|
7
7
|
end
|
8
8
|
|
9
|
-
class LockfileGenerator
|
10
|
-
attr_reader config: Config
|
11
|
-
attr_reader lock: Config?
|
12
|
-
attr_reader lock_path: Pathname
|
13
|
-
attr_reader gemfile_lock: Bundler::LockfileParser
|
14
|
-
|
15
|
-
type gem_queue_entry = { name: String, version: String? }
|
16
|
-
|
17
|
-
@gem_queue: Array[gem_queue_entry]
|
18
|
-
|
19
|
-
def self.generate: (config_path: Pathname, gemfile_lock_path: Pathname, ?with_lockfile: boolish) -> Config
|
20
|
-
|
21
|
-
def initialize: (config_path: Pathname, gemfile_lock_path: Pathname, with_lockfile: boolish) -> void
|
22
|
-
|
23
|
-
def generate: () -> Config
|
24
|
-
|
25
|
-
private
|
26
|
-
|
27
|
-
def validate_gemfile_lock_path!: (lock: Config?, gemfile_lock_path: Pathname) -> void
|
28
|
-
|
29
|
-
def assign_gem: (name: String, version: String?) -> void
|
30
|
-
|
31
|
-
def upsert_gem: (gem_entry? old, gem_entry new) -> void
|
32
|
-
|
33
|
-
def gemfile_lock_gems: () { (untyped) -> void } -> void
|
34
|
-
|
35
|
-
def remove_ignored_gems!: () -> void
|
36
|
-
|
37
|
-
def find_source: (name: String) -> Sources::_Source?
|
38
|
-
|
39
|
-
def find_best_version: (version: String?, versions: Array[String]) -> Gem::Version
|
40
|
-
end
|
41
|
-
|
42
9
|
PATH: Pathname
|
43
10
|
|
44
11
|
type gem_entry = {
|
@@ -48,42 +15,32 @@ module RBS
|
|
48
15
|
'source' => Sources::source_entry?
|
49
16
|
}
|
50
17
|
|
51
|
-
|
18
|
+
attr_reader config_path: Pathname
|
52
19
|
|
53
|
-
|
20
|
+
attr_reader data: untyped
|
54
21
|
|
55
22
|
@sources: Array[Sources::_Source]
|
56
23
|
|
57
24
|
def self.find_config_path: () -> Pathname?
|
58
25
|
|
59
|
-
def self.generate_lockfile: (config_path: Pathname, gemfile_lock_path: Pathname, ?with_lockfile: boolish) -> Config
|
26
|
+
def self.generate_lockfile: (config_path: Pathname, gemfile_lock_path: Pathname, ?with_lockfile: boolish) -> [Config, Lockfile]
|
60
27
|
|
61
28
|
def self.from_path: (Pathname path) -> Config
|
62
29
|
|
63
|
-
def self.lockfile_of: (Pathname config_path) -> Config?
|
64
|
-
|
65
30
|
def self.to_lockfile_path: (Pathname config_path) -> Pathname
|
66
31
|
|
67
32
|
# config_path is necessary to resolve relative repo_path
|
68
33
|
def initialize: (untyped data, config_path: Pathname) -> void
|
69
34
|
|
70
|
-
def add_gem: (gem_entry gem) -> void
|
71
|
-
|
72
35
|
def gem: (String gem_name) -> gem_entry?
|
73
36
|
|
74
37
|
def repo_path: () -> Pathname
|
75
38
|
|
76
|
-
def
|
39
|
+
def repo_path_data: () -> Pathname
|
77
40
|
|
78
|
-
def
|
41
|
+
def sources: () -> Array[Sources::t]
|
79
42
|
|
80
43
|
def gems: () -> Array[gem_entry]
|
81
|
-
|
82
|
-
def gemfile_lock_path=: (Pathname) -> Pathname
|
83
|
-
|
84
|
-
def gemfile_lock_path: () -> Pathname?
|
85
|
-
|
86
|
-
def check_rbs_availability!: () -> void
|
87
44
|
end
|
88
45
|
end
|
89
46
|
end
|
data/sig/collection/sources.rbs
CHANGED
@@ -1,27 +1,32 @@
|
|
1
1
|
module RBS
|
2
2
|
module Collection
|
3
3
|
module Sources
|
4
|
-
def self.from_config_entry: (source_entry) ->
|
4
|
+
def self.from_config_entry: (Git::source_entry) -> Git
|
5
|
+
| (source_entry) -> t
|
5
6
|
|
6
7
|
interface _Source
|
7
|
-
def has?: (
|
8
|
-
def versions: (
|
9
|
-
def install: (dest: Pathname,
|
8
|
+
def has?: (String name, String? version) -> boolish
|
9
|
+
def versions: (String name) -> Array[String]
|
10
|
+
def install: (dest: Pathname, name: String, version: String, stdout: CLI::_IO) -> void
|
10
11
|
def to_lockfile: () -> source_entry
|
11
|
-
def manifest_of: (
|
12
|
-
def dependencies_of: (
|
12
|
+
def manifest_of: (String name, String version) -> manifest_entry?
|
13
|
+
def dependencies_of: (String name, String version) -> Array[manifest_dependency]?
|
13
14
|
end
|
14
15
|
|
16
|
+
type t = Git | Stdlib | Rubygems
|
17
|
+
|
15
18
|
type source_entry = Git::source_entry
|
16
19
|
| Stdlib::source_entry
|
17
20
|
| Rubygems::source_entry
|
18
21
|
|
19
22
|
type manifest_entry = {
|
20
|
-
"dependencies" => Array[
|
23
|
+
"dependencies" => Array[manifest_dependency]?,
|
21
24
|
}
|
22
25
|
|
26
|
+
type manifest_dependency = { "name" => String }
|
27
|
+
|
23
28
|
module Base : _Source
|
24
|
-
def dependencies_of: (
|
29
|
+
def dependencies_of: (String name, String version) -> Array[manifest_dependency]?
|
25
30
|
end
|
26
31
|
|
27
32
|
class Git
|
@@ -43,32 +48,45 @@ module RBS
|
|
43
48
|
attr_reader name: String
|
44
49
|
attr_reader remote: String
|
45
50
|
attr_reader repo_dir: String
|
51
|
+
attr_reader revision: String
|
46
52
|
|
47
53
|
def initialize: (name: String, revision: String, remote: String, repo_dir: String?) -> untyped
|
48
54
|
|
49
|
-
def has?: (
|
55
|
+
def has?: (String name, String? version) -> boolish
|
50
56
|
|
51
|
-
def versions: (
|
57
|
+
def versions: (String name) -> Array[String]
|
52
58
|
|
53
|
-
def install: (dest: Pathname,
|
59
|
+
def install: (dest: Pathname, name: String, version: String, stdout: CLI::_IO) -> void
|
54
60
|
|
55
61
|
def to_lockfile: () -> source_entry
|
56
62
|
|
57
|
-
def manifest_of: (
|
63
|
+
def manifest_of: (String name, String version) -> manifest_entry?
|
64
|
+
|
65
|
+
def resolved_revision: () -> String
|
58
66
|
|
59
67
|
private
|
60
68
|
|
69
|
+
@need_setup: bool
|
70
|
+
|
61
71
|
@git_dir: Pathname?
|
62
72
|
|
63
73
|
@resolved_revision: String?
|
64
74
|
|
65
|
-
|
75
|
+
@gems_versions: Hash[String, Set[String]]?
|
76
|
+
|
77
|
+
def _install: (dest: Pathname , name: String, version: String) -> void
|
66
78
|
|
67
79
|
def cp_r: (Pathname, Pathname) -> void
|
68
80
|
|
69
|
-
|
81
|
+
# Ensure the git repository status is expected one
|
82
|
+
#
|
83
|
+
# * It exists, and
|
84
|
+
# * The `HEAD` is the `revision`
|
85
|
+
#
|
86
|
+
def setup!: [T] () { () -> T } -> T
|
87
|
+
| () -> void
|
70
88
|
|
71
|
-
def need_to_fetch?: (String revision
|
89
|
+
def need_to_fetch?: (String revision) -> bool
|
72
90
|
|
73
91
|
def git_dir: () -> Pathname
|
74
92
|
|
@@ -76,15 +94,30 @@ module RBS
|
|
76
94
|
|
77
95
|
def with_revision: [T] () { () -> T } -> T
|
78
96
|
|
79
|
-
|
80
|
-
|
81
|
-
def
|
97
|
+
# Returns `true` if `revision` looks like a commit hash
|
98
|
+
#
|
99
|
+
def commit_hash?: () -> bool
|
82
100
|
|
83
101
|
def git: (*String cmd, **untyped opt) -> String
|
84
102
|
|
103
|
+
def git?: (*String cmd, **untyped opt) -> String?
|
104
|
+
|
85
105
|
def sh!: (*String cmd, **untyped opt) -> String
|
86
106
|
|
87
|
-
def format_config_entry: (
|
107
|
+
def format_config_entry: (String name, String version) -> String
|
108
|
+
|
109
|
+
type metadata = { 'name' => String, 'version' => String, 'source' => source_entry }
|
110
|
+
|
111
|
+
def metadata_content: (name: String, version: String) -> metadata
|
112
|
+
|
113
|
+
# Write `.rbs_meta.yaml`
|
114
|
+
def write_metadata: (dir: Pathname, name: String, version: String) -> void
|
115
|
+
|
116
|
+
# Load `.rbs_meta.yaml` from the `dir`, where is the destination of the RBS file installation, and return the cleaned up content
|
117
|
+
#
|
118
|
+
def load_metadata: (dir: Pathname) -> metadata
|
119
|
+
|
120
|
+
def gems_versions: () -> Hash[String, Set[String]]
|
88
121
|
end
|
89
122
|
|
90
123
|
# signatures that are bundled in rbs gem under the stdlib/ directory
|
@@ -101,19 +134,19 @@ module RBS
|
|
101
134
|
# polyfill of singleton module
|
102
135
|
def self.instance: () -> instance
|
103
136
|
|
104
|
-
def has?: (
|
137
|
+
def has?: (String name, String? version) -> boolish
|
105
138
|
|
106
|
-
def versions: (
|
139
|
+
def versions: (String name) -> Array[String]
|
107
140
|
|
108
|
-
def install: (dest: Pathname,
|
141
|
+
def install: (dest: Pathname, name: String, version: String, stdout: CLI::_IO) -> void
|
109
142
|
|
110
143
|
def to_lockfile: () -> source_entry
|
111
144
|
|
112
|
-
def manifest_of: (
|
145
|
+
def manifest_of: (String name, String version) -> manifest_entry?
|
113
146
|
|
114
147
|
private
|
115
148
|
|
116
|
-
def lookup: (
|
149
|
+
def lookup: (String name, String? version) -> Pathname?
|
117
150
|
end
|
118
151
|
|
119
152
|
# sig/ directory
|
@@ -127,15 +160,19 @@ module RBS
|
|
127
160
|
# polyfill of singleton module
|
128
161
|
def self.instance: () -> instance
|
129
162
|
|
130
|
-
def has?: (
|
131
|
-
|
132
|
-
def
|
163
|
+
def has?: (String name, String? version) -> boolish
|
164
|
+
|
165
|
+
def versions: (String name) -> Array[String]
|
166
|
+
|
167
|
+
def install: (dest: Pathname, name: String, version: String, stdout: CLI::_IO) -> void
|
168
|
+
|
133
169
|
def to_lockfile: () -> source_entry
|
134
|
-
|
170
|
+
|
171
|
+
def manifest_of: (String name, String version) -> manifest_entry?
|
135
172
|
|
136
173
|
private
|
137
174
|
|
138
|
-
def gem_sig_path: (
|
175
|
+
def gem_sig_path: (String name, String? version) -> [Gem::Specification, Pathname]?
|
139
176
|
end
|
140
177
|
end
|
141
178
|
end
|
data/sig/definition_builder.rbs
CHANGED
@@ -1,14 +1,7 @@
|
|
1
1
|
module RBS
|
2
2
|
# DefinitionBuilder translates TypeName to Definition of the type
|
3
3
|
#
|
4
|
-
#
|
5
|
-
#
|
6
|
-
# 1. Calculate _ancestors_ of the type with AncestorBuilder
|
7
|
-
# 2. Calculate _partial_ definitions of each ancestor
|
8
|
-
# 3. Merge _partial_ definitions
|
9
|
-
#
|
10
|
-
# A _partial_ definition is a definition of one type name, in terms of it doesn't have methods of super classes nor included modules.
|
11
|
-
#
|
4
|
+
# It also provides semantic utilities that depends on Environment.
|
12
5
|
#
|
13
6
|
class DefinitionBuilder
|
14
7
|
attr_reader env: Environment
|
@@ -16,96 +9,32 @@ module RBS
|
|
16
9
|
attr_reader ancestor_builder: AncestorBuilder
|
17
10
|
attr_reader method_builder: MethodBuilder
|
18
11
|
|
19
|
-
attr_reader instance_cache: Hash[
|
12
|
+
attr_reader instance_cache: Hash[TypeName, Definition | false | nil]
|
20
13
|
attr_reader singleton_cache: Hash[TypeName, Definition | false | nil]
|
21
14
|
attr_reader singleton0_cache: Hash[TypeName, Definition | false | nil]
|
22
15
|
attr_reader interface_cache: Hash[TypeName, Definition | false | nil]
|
23
16
|
|
24
17
|
def initialize: (env: Environment, ?ancestor_builder: AncestorBuilder?, ?method_builder: MethodBuilder?) -> void
|
25
18
|
|
19
|
+
# Returns a Definition of a interface
|
20
|
+
#
|
26
21
|
def build_interface: (TypeName) -> Definition
|
27
22
|
|
28
|
-
# Returns a Definition of
|
23
|
+
# Returns a Definition of an instance type
|
29
24
|
#
|
30
25
|
# If TypeName is a module and `no_self_types` is `true`, it won't have methods of _self type constraints_.
|
31
26
|
# This typically happens when definition is being calculated for mixin.
|
32
27
|
#
|
33
|
-
def build_instance: (TypeName
|
28
|
+
def build_instance: (TypeName) -> Definition
|
34
29
|
|
30
|
+
# Returns a Definition of a singleton type
|
35
31
|
def build_singleton: (TypeName) -> Definition
|
36
32
|
|
37
|
-
|
38
|
-
|
39
|
-
def ensure_namespace!: (Namespace, location: Location[untyped, untyped]?) -> void
|
40
|
-
|
41
|
-
def build_singleton0: (TypeName) -> Definition
|
42
|
-
|
43
|
-
def merge_definition: (src: Definition, dest: Definition, subst: Substitution, ?implemented_in: :keep | TypeName | nil, ?keep_super: bool) -> void
|
44
|
-
|
45
|
-
def merge_method: (TypeName, Hash[Symbol, Definition::Method], Symbol, Definition::Method, Substitution, ?implemented_in: :keep | TypeName | nil, ?keep_super: bool) -> void
|
46
|
-
|
47
|
-
def merge_variable: (Hash[Symbol, Definition::Variable], Symbol, Definition::Variable, Substitution, ?keep_super: bool) -> void
|
48
|
-
|
49
|
-
def try_cache: (TypeName, cache: Hash[TypeName, Definition | false | nil]) { () -> Definition } -> Definition
|
50
|
-
| [A] (TypeName, cache: Hash[A, Definition | false | nil], key: A) { () -> Definition } -> Definition
|
51
|
-
|
52
|
-
def validate_params_with: (Array[AST::TypeParam], result: VarianceCalculator::Result) { (AST::TypeParam) -> void } -> void
|
53
|
-
|
54
|
-
def validate_type_params: (Definition, ancestors: AncestorBuilder::OneAncestors, methods: MethodBuilder::Methods) -> void
|
55
|
-
|
56
|
-
def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t) -> Location[untyped, untyped]?
|
57
|
-
|
58
|
-
def insert_variable: (TypeName, Hash[Symbol, Definition::Variable], name: Symbol, type: Types::t) -> void
|
59
|
-
|
60
|
-
# Add methods from `methods` to Definition
|
61
|
-
#
|
62
|
-
# * `methods`:
|
63
|
-
# * `interface_methods`: Methods of interfaces mixed into the type
|
64
|
-
# * `self_constraints_methods`: Methods of the self constraints methods
|
65
|
-
# * `super_interface_method`: `true` to have super method of existing method (`true` is the Definition is the target module)
|
66
|
-
#
|
67
|
-
def define_methods: (
|
68
|
-
Definition,
|
69
|
-
methods: MethodBuilder::Methods,
|
70
|
-
interface_methods: Hash[Symbol, Definition::Method],
|
71
|
-
methods_with_self: Hash[Symbol, Definition::Method]?,
|
72
|
-
super_interface_method: bool
|
73
|
-
) -> void
|
74
|
-
|
75
|
-
# Define methods on singleton type
|
76
|
-
#
|
77
|
-
def define_methods_singleton: (
|
78
|
-
Definition,
|
79
|
-
methods: MethodBuilder::Methods,
|
80
|
-
interface_methods: Hash[Symbol, Definition::Method]
|
81
|
-
) -> void
|
82
|
-
|
83
|
-
# Define methods on instance type
|
84
|
-
#
|
85
|
-
def define_methods_instance: (
|
86
|
-
Definition,
|
87
|
-
methods: MethodBuilder::Methods,
|
88
|
-
interface_methods: Hash[Symbol, Definition::Method]
|
89
|
-
) -> void
|
90
|
-
|
91
|
-
# Define methods on module instance type
|
33
|
+
# Validates the given Namespace and its ancestor namespaces exists
|
92
34
|
#
|
93
|
-
#
|
94
|
-
# * Pass methods from self-type-constraints to build a module instance type alone (to type check itself)
|
35
|
+
# Raises NoTypeFoundError
|
95
36
|
#
|
96
|
-
def
|
97
|
-
Definition,
|
98
|
-
methods: MethodBuilder::Methods,
|
99
|
-
interface_methods: Hash[Symbol, Definition::Method],
|
100
|
-
module_self_methods: Hash[Symbol, Definition::Method]?
|
101
|
-
) -> void
|
102
|
-
|
103
|
-
# Validates presence of type names recursively.
|
104
|
-
# Assumes the type names are already resolved.
|
105
|
-
#
|
106
|
-
def validate_type_presence: (Types::t) -> void
|
107
|
-
|
108
|
-
def validate_type_name: (TypeName, Location[untyped, untyped]?) -> void
|
37
|
+
def ensure_namespace!: (Namespace, location: Location[untyped, untyped]?) -> void
|
109
38
|
|
110
39
|
# Expand a type alias of given name without type arguments.
|
111
40
|
# Raises an error if the type alias requires arguments.
|
@@ -138,6 +67,90 @@ module RBS
|
|
138
67
|
#
|
139
68
|
def expand_alias2: (TypeName, Array[Types::t] args) -> Types::t
|
140
69
|
|
70
|
+
# Validates presence of type names recursively
|
71
|
+
#
|
72
|
+
# Assumes the type names are already resolved.
|
73
|
+
# Raises NoTypeFoundError in case of failure.
|
74
|
+
#
|
75
|
+
def validate_type_presence: (Types::t) -> void
|
76
|
+
|
77
|
+
# Validates presence of an absolute type name
|
78
|
+
#
|
79
|
+
# Raises NoTypeFoundError in case of error.
|
80
|
+
#
|
81
|
+
def validate_type_name: (TypeName, Location[untyped, untyped]?) -> void
|
82
|
+
|
83
|
+
# Returns a new DefinitionBuilder with updated Environment, AncestorBuilder, and exceptions
|
84
|
+
#
|
141
85
|
def update: (env: Environment, ancestor_builder: AncestorBuilder, except: _Each[TypeName]) -> DefinitionBuilder
|
86
|
+
|
87
|
+
private
|
88
|
+
|
89
|
+
def validate_super_class!: (TypeName, Environment::ClassEntry) -> void
|
90
|
+
|
91
|
+
def build_singleton0: (TypeName) -> Definition
|
92
|
+
|
93
|
+
# Returns `interface_methods` from given array of interface ancestors
|
94
|
+
#
|
95
|
+
def interface_methods: (Array[Definition::Ancestor::Instance] interface_ancestors) -> interface_methods
|
96
|
+
|
97
|
+
def try_cache: (TypeName, cache: Hash[TypeName, Definition | false | nil]) { () -> Definition } -> Definition
|
98
|
+
|
99
|
+
def validate_params_with: (Array[AST::TypeParam], result: VarianceCalculator::Result) { (AST::TypeParam) -> void } -> void
|
100
|
+
|
101
|
+
def validate_type_params: (Definition, ancestors: AncestorBuilder::OneAncestors, methods: MethodBuilder::Methods) -> void
|
102
|
+
|
103
|
+
def source_location: (Definition::Ancestor::Instance::source, AST::Declarations::t) -> Location[untyped, untyped]?
|
104
|
+
|
105
|
+
def insert_variable: (TypeName, Hash[Symbol, Definition::Variable], name: Symbol, type: Types::t) -> void
|
106
|
+
|
107
|
+
# Add method definition to `methods`, which will be merged to `class_definition` after defining all methods at this *level* -- class, module, or interface
|
108
|
+
#
|
109
|
+
# `class_definition` is a definition of given type, but it has definitions of prior levels.
|
110
|
+
#
|
111
|
+
def define_method: (
|
112
|
+
Hash[Symbol, Definition::Method] methods,
|
113
|
+
Definition class_definition,
|
114
|
+
MethodBuilder::Methods::Definition method_definition,
|
115
|
+
Substitution subst,
|
116
|
+
defined_in: TypeName,
|
117
|
+
?implemented_in: TypeName?
|
118
|
+
) -> void
|
119
|
+
|
120
|
+
# The `interface_methods` type describes the association between the interface name to its name and the *mixin* to a module
|
121
|
+
#
|
122
|
+
type interface_methods = Hash[
|
123
|
+
Definition::Ancestor::Instance,
|
124
|
+
[MethodBuilder::Methods, AST::Members::Include | AST::Members::Extend]
|
125
|
+
]
|
126
|
+
|
127
|
+
# Add method definitions from `module_methods` to `definition`
|
128
|
+
#
|
129
|
+
# It also processes interface mixins, with duplication detection.
|
130
|
+
# It doesn't process module mixins.
|
131
|
+
#
|
132
|
+
def import_methods: (
|
133
|
+
Definition definition,
|
134
|
+
TypeName module_name,
|
135
|
+
MethodBuilder::Methods module_methods,
|
136
|
+
interface_methods interface_methods,
|
137
|
+
Substitution subst
|
138
|
+
) -> void
|
139
|
+
|
140
|
+
# Updates `definition` with methods and variables of `type_name` that can be a module or a class
|
141
|
+
#
|
142
|
+
# It processes includes and prepends recursively.
|
143
|
+
#
|
144
|
+
def define_instance: (Definition definition, TypeName type_name, Substitution subst) -> void
|
145
|
+
|
146
|
+
def define_interface: (Definition definition, TypeName type_name, Substitution subst) -> void
|
147
|
+
|
148
|
+
# Returns a substitution that corresponds to type application
|
149
|
+
#
|
150
|
+
# ```
|
151
|
+
# tapp_subst(`::Array`, [`::Integer`]) # => Subsitution.build([:Elem], [`::Integer`])
|
152
|
+
# ```
|
153
|
+
#
|
154
|
+
def tapp_subst: (TypeName, Array[Types::t]) -> Substitution
|
142
155
|
end
|
143
156
|
end
|
data/sig/environment_loader.rbs
CHANGED
@@ -81,7 +81,7 @@ module RBS
|
|
81
81
|
def resolve_dependencies: (library: String, version: String?) -> void
|
82
82
|
|
83
83
|
# Add repository path and libraries via rbs_collection.lock.yaml.
|
84
|
-
def add_collection: (Collection::Config
|
84
|
+
def add_collection: (Collection::Config::Lockfile lockfile) -> void
|
85
85
|
|
86
86
|
# This is helper function to test if RBS for a library is available or not.
|
87
87
|
#
|
data/sig/errors.rbs
CHANGED
@@ -123,6 +123,23 @@ module RBS
|
|
123
123
|
def other_locations: () -> Array[Location[untyped, untyped]?]
|
124
124
|
end
|
125
125
|
|
126
|
+
# An interface mixin causes a duplication of a method definition
|
127
|
+
#
|
128
|
+
# ```rbs
|
129
|
+
# interface _Foo1
|
130
|
+
# def foo: () -> void
|
131
|
+
# end
|
132
|
+
#
|
133
|
+
# interface _Foo2
|
134
|
+
# def foo: () -> void
|
135
|
+
# end
|
136
|
+
#
|
137
|
+
# class Foo
|
138
|
+
# include _Foo1
|
139
|
+
# include _Foo2 # <= The error will be reported here (or the line of _Foo1)
|
140
|
+
# end
|
141
|
+
# ```
|
142
|
+
#
|
126
143
|
class DuplicatedInterfaceMethodDefinitionError < DefinitionError
|
127
144
|
type ty = Types::ClassSingleton | Types::ClassInstance | Types::Interface
|
128
145
|
type mixin_member = AST::Members::Include | AST::Members::Extend
|
@@ -138,6 +155,8 @@ module RBS
|
|
138
155
|
def qualified_method_name: () -> String
|
139
156
|
end
|
140
157
|
|
158
|
+
# The `alias` member declares an alias from unknown method
|
159
|
+
#
|
141
160
|
class UnknownMethodAliasError < DefinitionError
|
142
161
|
attr_reader type_name: TypeName
|
143
162
|
attr_reader original_name: Symbol
|
@@ -154,6 +173,8 @@ module RBS
|
|
154
173
|
def initialize: (name: TypeName, entry: Environment::ClassEntry) -> void
|
155
174
|
end
|
156
175
|
|
176
|
+
# The *overloading* method definition cannot find *non-overloading* method definition
|
177
|
+
#
|
157
178
|
class InvalidOverloadMethodError < DefinitionError
|
158
179
|
attr_reader type_name: TypeName
|
159
180
|
attr_reader method_name: Symbol
|
data/sig/members.rbs
CHANGED
@@ -15,6 +15,26 @@ module RBS
|
|
15
15
|
type visibility = :public | :private
|
16
16
|
|
17
17
|
class MethodDefinition < Base
|
18
|
+
class Overload
|
19
|
+
attr_reader method_type: MethodType
|
20
|
+
|
21
|
+
attr_reader annotations: Array[Annotation]
|
22
|
+
|
23
|
+
def initialize: (method_type: MethodType, annotations: Array[Annotation]) -> void
|
24
|
+
|
25
|
+
def ==: (untyped) -> bool
|
26
|
+
|
27
|
+
def hash: () -> Integer
|
28
|
+
|
29
|
+
alias eql? ==
|
30
|
+
|
31
|
+
def update: (?annotations: Array[Annotation], ?method_type: MethodType) -> Overload
|
32
|
+
|
33
|
+
def sub: (Substitution) -> Overload
|
34
|
+
|
35
|
+
include _ToJson
|
36
|
+
end
|
37
|
+
|
18
38
|
type kind = :instance | :singleton | :singleton_instance
|
19
39
|
|
20
40
|
# def foo: () -> void
|
@@ -26,31 +46,35 @@ module RBS
|
|
26
46
|
# ^^^ keyword
|
27
47
|
# ^^^^^ kind
|
28
48
|
# ^^^ name
|
29
|
-
# ^^^
|
49
|
+
# ^^^ overloading
|
30
50
|
#
|
31
|
-
type loc = Location[:keyword | :name, :kind | :
|
51
|
+
type loc = Location[:keyword | :name, :kind | :overloading | :visibility]
|
32
52
|
|
33
53
|
attr_reader name: Symbol
|
34
54
|
attr_reader kind: kind
|
35
|
-
attr_reader
|
55
|
+
attr_reader overloads: Array[Overload]
|
36
56
|
attr_reader annotations: Array[Annotation]
|
37
57
|
attr_reader location: loc?
|
38
58
|
attr_reader comment: Comment?
|
39
|
-
attr_reader
|
59
|
+
attr_reader overloading: bool
|
40
60
|
attr_reader visibility: visibility?
|
41
61
|
|
42
|
-
def initialize: (name: Symbol, kind: kind,
|
62
|
+
def initialize: (name: Symbol, kind: kind, overloads: Array[Overload], annotations: Array[Annotation], location: loc?, comment: Comment?, overloading: bool, visibility: visibility?) -> void
|
43
63
|
|
44
64
|
include _HashEqual
|
45
65
|
include _ToJson
|
46
66
|
|
67
|
+
# Returns true if the `def` is to define instance method
|
47
68
|
def instance?: () -> bool
|
48
69
|
|
70
|
+
# Returns true if the `def` is to define singleton method
|
49
71
|
def singleton?: () -> bool
|
50
72
|
|
51
|
-
def
|
73
|
+
# Returns true if the `def` is overloading (== with `...`)
|
74
|
+
#
|
75
|
+
def overloading?: () -> bool
|
52
76
|
|
53
|
-
def update: (?name: Symbol, ?kind: kind, ?
|
77
|
+
def update: (?name: Symbol, ?kind: kind, ?overloads: Array[Overload], ?annotations: Array[Annotation], ?location: loc?, ?comment: Comment?, ?overloading: bool, ?visibility: visibility?) -> MethodDefinition
|
54
78
|
end
|
55
79
|
|
56
80
|
module Var
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module RBS
|
2
|
+
module Prototype
|
3
|
+
class NodeUsage
|
4
|
+
include Helpers
|
5
|
+
|
6
|
+
type node = RubyVM::AbstractSyntaxTree::Node
|
7
|
+
|
8
|
+
attr_reader node: node
|
9
|
+
|
10
|
+
attr_reader conditional_nodes: Set[node]
|
11
|
+
|
12
|
+
def initialize: (node) -> void
|
13
|
+
|
14
|
+
def calculate: (node, conditional: bool) -> void
|
15
|
+
|
16
|
+
def each_conditional_node: () { (node) -> void } -> void
|
17
|
+
| () -> Enumerator[node, void]
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|