steep 1.4.0 → 1.5.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.vscode/steep-shared.code-snippets +41 -0
- data/CHANGELOG.md +37 -0
- data/Gemfile +2 -5
- data/Gemfile.lock +20 -17
- data/Gemfile.steep +1 -1
- data/Gemfile.steep.lock +6 -6
- data/Rakefile +198 -0
- data/Steepfile +3 -1
- data/lib/steep/ast/builtin.rb +9 -7
- data/lib/steep/ast/node/type_application.rb +13 -5
- data/lib/steep/ast/node/type_assertion.rb +28 -9
- data/lib/steep/ast/types/factory.rb +39 -7
- data/lib/steep/cli.rb +2 -1
- data/lib/steep/diagnostic/deprecated/else_on_exhaustive_case.rb +20 -0
- data/lib/steep/diagnostic/lsp_formatter.rb +3 -3
- data/lib/steep/diagnostic/ruby.rb +73 -12
- data/lib/steep/drivers/annotations.rb +1 -0
- data/lib/steep/drivers/check.rb +18 -13
- data/lib/steep/drivers/checkfile.rb +1 -1
- data/lib/steep/drivers/diagnostic_printer.rb +6 -4
- data/lib/steep/drivers/init.rb +2 -1
- data/lib/steep/drivers/print_project.rb +3 -1
- data/lib/steep/drivers/stats.rb +1 -1
- data/lib/steep/drivers/utils/driver_helper.rb +10 -8
- data/lib/steep/drivers/utils/jobs_option.rb +6 -1
- data/lib/steep/drivers/validate.rb +9 -5
- data/lib/steep/drivers/watch.rb +8 -3
- data/lib/steep/expectations.rb +144 -75
- data/lib/steep/index/signature_symbol_provider.rb +22 -13
- data/lib/steep/node_helper.rb +172 -0
- data/lib/steep/server/base_worker.rb +2 -1
- data/lib/steep/server/change_buffer.rb +17 -15
- data/lib/steep/server/interaction_worker.rb +20 -0
- data/lib/steep/server/lsp_formatter.rb +20 -1
- data/lib/steep/server/master.rb +51 -36
- data/lib/steep/server/type_check_worker.rb +18 -2
- data/lib/steep/server/worker_process.rb +19 -2
- data/lib/steep/services/completion_provider.rb +189 -3
- data/lib/steep/services/file_loader.rb +1 -1
- data/lib/steep/services/goto_service.rb +123 -27
- data/lib/steep/services/signature_help_provider.rb +1 -6
- data/lib/steep/signature/validator.rb +6 -1
- data/lib/steep/source.rb +165 -108
- data/lib/steep/subtyping/check.rb +5 -3
- data/lib/steep/subtyping/variable_variance.rb +11 -0
- data/lib/steep/thread_waiter.rb +35 -0
- data/lib/steep/type_construction.rb +416 -171
- data/lib/steep/type_inference/block_params.rb +50 -9
- data/lib/steep/type_inference/context.rb +4 -0
- data/lib/steep/type_inference/context_array.rb +6 -6
- data/lib/steep/type_inference/logic_type_interpreter.rb +202 -68
- data/lib/steep/typing.rb +5 -4
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +21 -14
- data/sample/Steepfile +1 -0
- data/sig/shims/bundler.rbs +3 -0
- data/sig/shims/language-server_protocol.rbs +151 -10
- data/sig/shims/parser/nodes.rbs +210 -0
- data/sig/shims/parser.rbs +10 -0
- data/sig/steep/ast/builtin.rbs +2 -2
- data/sig/steep/ast/node/type_application.rbs +2 -2
- data/sig/steep/ast/node/type_assertion.rbs +8 -2
- data/sig/steep/ast/types/factory.rbs +28 -1
- data/sig/steep/diagnostic/deprecated/else_on_exhaustive_case.rbs +13 -0
- data/sig/steep/diagnostic/lsp_formatter.rbs +5 -2
- data/sig/steep/diagnostic/ruby.rbs +76 -6
- data/sig/steep/drivers/annotations.rbs +5 -5
- data/sig/steep/drivers/check.rbs +11 -11
- data/sig/steep/drivers/diagnostic_printer.rbs +9 -9
- data/sig/steep/drivers/init.rbs +6 -6
- data/sig/steep/drivers/print_project.rbs +4 -4
- data/sig/steep/drivers/utils/driver_helper.rbs +8 -6
- data/sig/steep/drivers/validate.rbs +4 -4
- data/sig/steep/drivers/watch.rbs +1 -1
- data/sig/steep/expectations.rbs +72 -0
- data/sig/steep/index/signature_symbol_provider.rbs +22 -10
- data/sig/steep/interface/block.rbs +2 -0
- data/sig/steep/interface/function.rbs +2 -2
- data/sig/steep/node_helper.rbs +56 -0
- data/sig/steep/path_helper.rbs +1 -1
- data/sig/steep/project/options.rbs +1 -1
- data/sig/steep/range_extension.rbs +2 -2
- data/sig/steep/server/master.rbs +16 -2
- data/sig/steep/server/type_check_worker.rbs +5 -1
- data/sig/steep/server/worker_process.rbs +5 -1
- data/sig/steep/services/completion_provider.rbs +31 -1
- data/sig/steep/services/goto_service.rbs +80 -19
- data/sig/steep/source.rbs +27 -4
- data/sig/steep/subtyping/variable_variance.rbs +9 -9
- data/sig/steep/thread_waiter.rbs +13 -0
- data/sig/steep/type_construction.rbs +26 -9
- data/sig/steep/type_inference/block_params.rbs +13 -1
- data/sig/steep/type_inference/context.rbs +5 -1
- data/sig/steep/type_inference/context_array.rbs +16 -15
- data/sig/steep/type_inference/logic_type_interpreter.rbs +36 -6
- data/sig/steep/type_inference/type_env_builder.rbs +4 -0
- data/sig/steep/typing.rbs +22 -20
- data/sig/steep.rbs +14 -13
- data/smoke/and/a.rb +1 -1
- data/smoke/and/test_expectations.yml +5 -7
- data/smoke/diagnostics/incompatible_annotation.rb +1 -1
- data/smoke/diagnostics/test_expectations.yml +2 -2
- data/smoke/enumerator/a.rb +0 -7
- data/smoke/enumerator/b.rb +0 -2
- data/smoke/enumerator/test_expectations.yml +17 -105
- data/smoke/lambda/a.rb +0 -5
- data/smoke/lambda/test_expectations.yml +0 -22
- data/smoke/type_case/test_expectations.yml +10 -0
- data/steep.gemspec +2 -2
- metadata +16 -9
@@ -152,7 +152,29 @@ module Steep
|
|
152
152
|
) -> void
|
153
153
|
end
|
154
154
|
|
155
|
-
|
155
|
+
class TypeNameItem
|
156
|
+
attr_reader env: Environment
|
157
|
+
|
158
|
+
attr_reader absolute_type_name: TypeName
|
159
|
+
|
160
|
+
attr_reader relative_type_name: TypeName
|
161
|
+
|
162
|
+
attr_reader range: Range
|
163
|
+
|
164
|
+
def initialize: (absolute_type_name: TypeName, relative_type_name: TypeName, env: Environment, range: Range) -> void
|
165
|
+
|
166
|
+
def decl: () -> Server::LSPFormatter::summarizable_decl
|
167
|
+
|
168
|
+
def comments: () -> Array[RBS::AST::Comment]
|
169
|
+
end
|
170
|
+
|
171
|
+
type item = InstanceVariableItem
|
172
|
+
| LocalVariableItem
|
173
|
+
| ConstantItem
|
174
|
+
| SimpleMethodNameItem
|
175
|
+
| ComplexMethodNameItem
|
176
|
+
| GeneratedMethodNameItem
|
177
|
+
| TypeNameItem
|
156
178
|
|
157
179
|
attr_reader source_text: String
|
158
180
|
|
@@ -176,6 +198,8 @@ module Steep
|
|
176
198
|
|
177
199
|
def range_from_loc: (Parser::Source::Range loc) -> Range
|
178
200
|
|
201
|
+
def at_comment?: (Position pos) -> bool
|
202
|
+
|
179
203
|
def at_end?: (Position pos, of: Parser::Source::Map | Parser::Source::Range | nil) -> boolish
|
180
204
|
|
181
205
|
def range_for: (Position position, ?prefix: ::String) -> Range
|
@@ -184,10 +208,14 @@ module Steep
|
|
184
208
|
|
185
209
|
def items_for_dot: (position: Position) -> Array[item]
|
186
210
|
|
211
|
+
def items_for_qcall: (position: Position) -> Array[item]
|
212
|
+
|
187
213
|
def items_for_colon2: (position: Position) -> Array[item]
|
188
214
|
|
189
215
|
def items_for_atmark: (position: Position) -> Array[item]
|
190
216
|
|
217
|
+
def items_for_rbs: (position: Position, buffer: RBS::Buffer) -> Array[item]
|
218
|
+
|
191
219
|
def method_items_for_receiver_type: (AST::Types::t, include_private: bool, prefix: String, position: Position, items: Array[item]) -> void
|
192
220
|
|
193
221
|
def word_name?: (String name) -> bool
|
@@ -202,6 +230,8 @@ module Steep
|
|
202
230
|
|
203
231
|
def disallowed_method?: (Symbol name) -> bool
|
204
232
|
|
233
|
+
def unwrap_optional: (AST::Types::t) -> AST::Types::t
|
234
|
+
|
205
235
|
end
|
206
236
|
end
|
207
237
|
end
|
@@ -1,45 +1,106 @@
|
|
1
|
+
use RBS::TypeName, RBS::Location
|
2
|
+
|
1
3
|
module Steep
|
2
4
|
module Services
|
3
5
|
class GotoService
|
4
6
|
include ModuleHelper
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
+
# Where the query is issued from
|
9
|
+
#
|
10
|
+
# * `:ruby` if the query is issued from a Ruby code
|
11
|
+
# * `:rbs` if the query is issued from a RBS file
|
12
|
+
#
|
13
|
+
type from = :ruby | :rbs
|
14
|
+
|
15
|
+
module SourceHelper : _From
|
16
|
+
interface _From
|
17
|
+
def from: () -> from
|
18
|
+
end
|
19
|
+
|
20
|
+
def from_ruby?: () -> bool
|
21
|
+
|
22
|
+
def from_rbs?: () -> bool
|
23
|
+
end
|
24
|
+
|
25
|
+
# Query a constant
|
26
|
+
#
|
27
|
+
class ConstantQuery
|
28
|
+
include SourceHelper
|
29
|
+
|
30
|
+
attr_reader name: TypeName
|
31
|
+
|
32
|
+
# Where the query is issued from
|
33
|
+
attr_reader from: from
|
34
|
+
|
35
|
+
def initialize: (name: TypeName, from: from) -> void
|
36
|
+
end
|
37
|
+
|
38
|
+
# Query a method
|
39
|
+
#
|
40
|
+
class MethodQuery
|
41
|
+
include SourceHelper
|
42
|
+
|
43
|
+
attr_reader name: method_name
|
8
44
|
|
9
|
-
|
45
|
+
# Where the query is issued from
|
46
|
+
attr_reader from: from
|
47
|
+
|
48
|
+
def initialize: (name: method_name, from: from) -> void
|
10
49
|
end
|
11
50
|
|
12
|
-
|
51
|
+
# Query a type name
|
52
|
+
#
|
53
|
+
#
|
54
|
+
#
|
55
|
+
class TypeNameQuery
|
56
|
+
attr_reader name: TypeName
|
57
|
+
|
58
|
+
def initialize: (name: TypeName) -> void
|
59
|
+
end
|
60
|
+
|
61
|
+
type query = ConstantQuery | MethodQuery | TypeNameQuery
|
62
|
+
|
63
|
+
type loc = Location[bot, bot] | Parser::Source::Range
|
64
|
+
|
65
|
+
attr_reader type_check: TypeCheckService
|
13
66
|
|
14
|
-
|
67
|
+
attr_reader assignment: PathAssignment
|
15
68
|
|
16
|
-
|
69
|
+
def initialize: (type_check: TypeCheckService, assignment: PathAssignment) -> void
|
17
70
|
|
18
|
-
|
71
|
+
def project: () -> Project
|
19
72
|
|
20
|
-
|
73
|
+
# Returns array of locations that is a response to a *Go to implementation* request
|
74
|
+
#
|
75
|
+
def implementation: (path: Pathname, line: Integer, column: Integer) -> Array[loc]
|
21
76
|
|
22
|
-
|
77
|
+
# Returns array of locations that is a response to a *Go to definition* request
|
78
|
+
#
|
79
|
+
def definition: (path: Pathname, line: Integer, column: Integer) -> Array[loc]
|
23
80
|
|
24
|
-
|
81
|
+
# Returns array of locations that is a response to a *Go to type-definition* request
|
82
|
+
#
|
83
|
+
def type_definition: (path: Pathname, line: Integer, column: Integer) -> Array[loc]
|
25
84
|
|
26
|
-
|
85
|
+
private
|
27
86
|
|
28
|
-
|
87
|
+
# Returns a set of queries
|
88
|
+
def query_at: (path: Pathname, line: Integer, column: Integer) -> Array[query]
|
29
89
|
|
30
|
-
def
|
90
|
+
def each_type_name: (AST::Types::t) { (TypeName) -> void } -> void
|
91
|
+
| (AST::Types::t) -> Enumerator[TypeName, void]
|
31
92
|
|
32
|
-
def
|
93
|
+
def test_ast_location: (Parser::Source::Range loc, line: Integer, column: Integer) -> bool
|
33
94
|
|
34
|
-
def type_check_path: (target:
|
95
|
+
def type_check_path: (target: Project::Target, path: Pathname, content: String, line: Integer, column: Integer) -> [Typing, SignatureService]?
|
35
96
|
|
36
|
-
def constant_definition_in_rbs: (
|
97
|
+
def constant_definition_in_rbs: (TypeName name, locations: Array[loc]) -> Array[loc]
|
37
98
|
|
38
|
-
def constant_definition_in_ruby: (
|
99
|
+
def constant_definition_in_ruby: (TypeName name, locations: Array[loc]) -> Array[loc]
|
39
100
|
|
40
|
-
def method_locations: (
|
101
|
+
def method_locations: (method_name, in_ruby: bool, in_rbs: bool, locations: Array[loc]) -> Array[loc]
|
41
102
|
|
42
|
-
def type_name_locations: (
|
103
|
+
def type_name_locations: (TypeName name, ?locations: Array[loc]) -> Array[loc]
|
43
104
|
end
|
44
105
|
end
|
45
106
|
end
|
data/sig/steep/source.rbs
CHANGED
@@ -2,19 +2,29 @@ module Steep
|
|
2
2
|
class Source
|
3
3
|
extend NodeHelper
|
4
4
|
|
5
|
+
attr_reader buffer: RBS::Buffer
|
6
|
+
|
5
7
|
attr_reader path: Pathname
|
6
8
|
|
7
9
|
attr_reader node: Parser::AST::Node?
|
8
10
|
|
9
11
|
attr_reader mapping: Hash[Parser::AST::Node, Array[AST::Annotation::t]]
|
10
12
|
|
11
|
-
|
13
|
+
attr_reader comments: Array[Parser::Source::Comment]
|
14
|
+
|
15
|
+
def initialize: (
|
16
|
+
buffer: RBS::Buffer,
|
17
|
+
path: Pathname,
|
18
|
+
node: Parser::AST::Node?,
|
19
|
+
mapping: Hash[Parser::AST::Node, Array[AST::Annotation::t]],
|
20
|
+
comments: Array[Parser::Source::Comment]
|
21
|
+
) -> void
|
12
22
|
|
13
23
|
class Builder < ::Parser::Builders::Default
|
14
24
|
def string_value: (untyped token) -> untyped
|
15
25
|
end
|
16
26
|
|
17
|
-
def self.new_parser: () -> Parser::
|
27
|
+
def self.new_parser: () -> Parser::Ruby32
|
18
28
|
|
19
29
|
def self.parse: (String source_code, path: Pathname, factory: AST::Types::Factory) -> Source
|
20
30
|
|
@@ -36,8 +46,8 @@ module Steep
|
|
36
46
|
#
|
37
47
|
# Yields arrays, inner node first, outer node last -- `[heredoc_node, *outer_node, node]`.
|
38
48
|
#
|
39
|
-
def each_heredoc_node: (?Parser::AST::Node? node, ?Array[Parser::AST::Node] parents) { (Array[Parser::AST::Node]) -> void } -> void
|
40
|
-
| (?Parser::AST::Node? node, ?Array[Parser::AST::Node] parents) -> Enumerator[Array[Parser::AST::Node], void]
|
49
|
+
def each_heredoc_node: (?Parser::AST::Node? node, ?Array[Parser::AST::Node] parents) { ([Array[Parser::AST::Node], Parser::Source::Map & Parser::AST::_Heredoc]) -> void } -> void
|
50
|
+
| (?Parser::AST::Node? node, ?Array[Parser::AST::Node] parents) -> Enumerator[[Array[Parser::AST::Node], Parser::Source::Map & Parser::AST::_Heredoc], void]
|
41
51
|
|
42
52
|
# Returns array of nodes that is located inside heredoc
|
43
53
|
#
|
@@ -58,6 +68,19 @@ module Steep
|
|
58
68
|
# Returns a node and it's outer nodes
|
59
69
|
def find_nodes: (line: Integer, column: Integer) -> ::Array[Parser::AST::Node]?
|
60
70
|
|
71
|
+
# Returns comment at the given position
|
72
|
+
#
|
73
|
+
# Note that a cursor position that is at the beginning of a comment returns `nil`.
|
74
|
+
#
|
75
|
+
# ```ruby
|
76
|
+
# .#. .H.e.l.l.o.
|
77
|
+
# ^ => Returns nil
|
78
|
+
# ^ => Returns the comment
|
79
|
+
# ^ => Returns the comment
|
80
|
+
# ```
|
81
|
+
#
|
82
|
+
def find_comment: (line: Integer, column: Integer) -> Parser::Source::Comment?
|
83
|
+
|
61
84
|
def self.delete_defs: (Parser::AST::Node node, Set[Parser::AST::Node] allow_list) -> Parser::AST::Node
|
62
85
|
|
63
86
|
def without_unrelated_defs: (line: Integer, column: Integer) -> Source
|
@@ -1,25 +1,25 @@
|
|
1
1
|
module Steep
|
2
2
|
module Subtyping
|
3
3
|
class VariableVariance
|
4
|
-
attr_reader covariants:
|
4
|
+
attr_reader covariants: Set[Symbol]
|
5
5
|
|
6
|
-
attr_reader contravariants:
|
6
|
+
attr_reader contravariants: Set[Symbol]
|
7
7
|
|
8
|
-
def initialize: (covariants:
|
8
|
+
def initialize: (covariants: Set[Symbol], contravariants: Set[Symbol]) -> void
|
9
9
|
|
10
|
-
def covariant?: (
|
10
|
+
def covariant?: (Symbol var) -> bool
|
11
11
|
|
12
|
-
def contravariant?: (
|
12
|
+
def contravariant?: (Symbol var) -> bool
|
13
13
|
|
14
|
-
def invariant?: (
|
14
|
+
def invariant?: (Symbol var) -> bool
|
15
15
|
|
16
16
|
def self.from_type: (AST::Types::t) -> VariableVariance
|
17
17
|
|
18
|
-
def self.from_method_type: (
|
18
|
+
def self.from_method_type: (Interface::MethodType method_type) -> VariableVariance
|
19
19
|
|
20
|
-
def self.add_params: (
|
20
|
+
def self.add_params: (Interface::Function::Params params, block: bool, covariants: Set[Symbol], contravariants: Set[Symbol]) -> void
|
21
21
|
|
22
|
-
def self.add_type: (
|
22
|
+
def self.add_type: (AST::Types::t `type`, variance: :covariant | :contravariant | :invariant, covariants: Set[Symbol], contravariants: Set[Symbol]) -> void
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
use Steep::AST::Types
|
2
|
+
|
1
3
|
module Steep
|
2
4
|
class TypeConstruction
|
3
5
|
class Pair
|
@@ -34,6 +36,8 @@ module Steep
|
|
34
36
|
|
35
37
|
%a{pure} def module_context: () -> TypeInference::Context::ModuleContext
|
36
38
|
|
39
|
+
# `method_context` is `nil` outside of any `def` syntax
|
40
|
+
#
|
37
41
|
%a{pure} def method_context: () -> TypeInference::Context::MethodContext?
|
38
42
|
|
39
43
|
def method_context!: () -> TypeInference::Context::MethodContext
|
@@ -162,9 +166,11 @@ module Steep
|
|
162
166
|
#
|
163
167
|
def synthesize_constant: (Parser::AST::Node? node, Parser::AST::Node? parent_node, Symbol constant_name) ?{ () -> void } -> [AST::Types::t, TypeConstruction, RBS::TypeName?]
|
164
168
|
|
165
|
-
|
169
|
+
# Returns a proc type if given type is a two clause union with the proc type and `nil`
|
170
|
+
#
|
171
|
+
def optional_proc?: (AST::Types::t) -> AST::Types::Proc?
|
166
172
|
|
167
|
-
def type_lambda: (Parser::AST::Node & Parser::AST::_BlockNode node, params_node: Parser::AST::Node, body_node: Parser::AST::Node
|
173
|
+
def type_lambda: (Parser::AST::Node & Parser::AST::_BlockNode node, params_node: Parser::AST::Node, body_node: Parser::AST::Node?, type_hint: AST::Types::t?) -> Pair
|
168
174
|
|
169
175
|
def synthesize_children: (Parser::AST::Node node, ?skips: Array[Parser::AST::Node?]) -> TypeConstruction
|
170
176
|
|
@@ -184,7 +190,8 @@ module Steep
|
|
184
190
|
block_params: Parser::AST::Node?,
|
185
191
|
block_body: Parser::AST::Node?,
|
186
192
|
?unwrap: bool,
|
187
|
-
tapp: AST::Node::TypeApplication
|
193
|
+
tapp: AST::Node::TypeApplication?,
|
194
|
+
hint: Types::t?
|
188
195
|
) -> Pair
|
189
196
|
|
190
197
|
# The second step to type check method calls, which handles type refinements on *pure* calls
|
@@ -201,7 +208,8 @@ module Steep
|
|
201
208
|
arguments: Array[Parser::AST::Node],
|
202
209
|
block_params: Parser::AST::Node?,
|
203
210
|
block_body: Parser::AST::Node?,
|
204
|
-
tapp: AST::Node::TypeApplication
|
211
|
+
tapp: AST::Node::TypeApplication?,
|
212
|
+
hint: Types::t?
|
205
213
|
) -> Pair
|
206
214
|
|
207
215
|
# The third step to type check method calls, which tries all of the overlods defined for the method
|
@@ -218,7 +226,8 @@ module Steep
|
|
218
226
|
arguments: Array[Parser::AST::Node],
|
219
227
|
block_params: Parser::AST::Node?,
|
220
228
|
block_body: Parser::AST::Node?,
|
221
|
-
tapp: AST::Node::TypeApplication
|
229
|
+
tapp: AST::Node::TypeApplication?,
|
230
|
+
hint: Types::t?
|
222
231
|
) -> [TypeInference::MethodCall::t, TypeConstruction]?
|
223
232
|
|
224
233
|
# The core to type check method calls, which implements type checking arguments including blocks and type inference
|
@@ -233,7 +242,8 @@ module Steep
|
|
233
242
|
arguments: Array[Parser::AST::Node],
|
234
243
|
block_params: Parser::AST::Node?,
|
235
244
|
block_body: Parser::AST::Node?,
|
236
|
-
tapp: AST::Node::TypeApplication
|
245
|
+
tapp: AST::Node::TypeApplication?,
|
246
|
+
hint: Types::t?
|
237
247
|
) -> [TypeInference::MethodCall::t, TypeConstruction]
|
238
248
|
|
239
249
|
# Extra step to type check method calls, which implements custom typing rules based on the methods
|
@@ -247,7 +257,8 @@ module Steep
|
|
247
257
|
method_type: Interface::MethodType,
|
248
258
|
arguments: Array[Parser::AST::Node],
|
249
259
|
block_params: Parser::AST::Node?,
|
250
|
-
block_body: Parser::AST::Node
|
260
|
+
block_body: Parser::AST::Node?,
|
261
|
+
hint: Types::t?
|
251
262
|
) -> [TypeInference::MethodCall::t, TypeConstruction]?
|
252
263
|
|
253
264
|
def builder_config: () -> Interface::Builder::Config
|
@@ -262,7 +273,7 @@ module Steep
|
|
262
273
|
|
263
274
|
def expand_self: (untyped `type`) -> untyped
|
264
275
|
|
265
|
-
SPECIAL_METHOD_NAMES:
|
276
|
+
SPECIAL_METHOD_NAMES: Hash[Symbol, Set[method_name]]
|
266
277
|
|
267
278
|
KNOWN_PURE_METHODS: Set[method_name]
|
268
279
|
|
@@ -301,6 +312,12 @@ module Steep
|
|
301
312
|
Array[Diagnostic::Ruby::Base]
|
302
313
|
) -> TypeConstruction
|
303
314
|
|
315
|
+
# Type check arguments without known method type
|
316
|
+
#
|
317
|
+
# This handles `:splat` nodes and `:kwargs` node that appears as an argument.
|
318
|
+
#
|
319
|
+
def type_check_untyped_args: (Array[Parser::AST::Node] arguments) -> TypeConstruction
|
320
|
+
|
304
321
|
def type_check_argument: (Parser::AST::Node node, type: AST::Types::t, constraints: Subtyping::Constraints, errors: Array[Diagnostic::Ruby::Base], ?report_node: Parser::AST::Node) -> Pair
|
305
322
|
|
306
323
|
def type_block_without_hint: (node: Parser::AST::Node & Parser::AST::_BlockNode, block_annotations: AST::Annotation::Collection, block_params: TypeInference::BlockParams?, block_body: Parser::AST::Node?) ?{ (Diagnostic::Ruby::Base) -> void } -> void
|
@@ -485,7 +502,7 @@ module Steep
|
|
485
502
|
# * When hint is union type, it tries recursively with the union cases.
|
486
503
|
# * Otherwise, it tries to be a hash instance.
|
487
504
|
#
|
488
|
-
def type_hash: (Parser::AST::Node hash_node, hint: AST::Types::t?) ->
|
505
|
+
def type_hash: (Parser::AST::Node hash_node, hint: AST::Types::t?) -> Pair
|
489
506
|
|
490
507
|
# Returns the first one from elements of `types` that returns a type `t` where `t <: hint`.
|
491
508
|
#
|
@@ -89,6 +89,12 @@ module Steep
|
|
89
89
|
#
|
90
90
|
def each_param: () { (Param) -> void } -> void
|
91
91
|
| () -> Enumerator[Param, void]
|
92
|
+
|
93
|
+
# Type that is constructed from `#params` type annotations
|
94
|
+
#
|
95
|
+
# Returns `nil` any part of the params is left un-annotated.
|
96
|
+
#
|
97
|
+
def type: () -> AST::Types::t?
|
92
98
|
end
|
93
99
|
|
94
100
|
attr_reader leading_params: Array[Param | MultipleParam]
|
@@ -151,8 +157,14 @@ module Steep
|
|
151
157
|
| () -> Enumerator[Param | MultipleParam, void]
|
152
158
|
|
153
159
|
# Yields `Param` recursively
|
154
|
-
#
|
160
|
+
#
|
155
161
|
def each_single_param: () { (Param) -> void } -> void
|
162
|
+
|
163
|
+
# Returns true if the parameter is single `untyped`
|
164
|
+
#
|
165
|
+
# This will automatically distribute `untyped` on block parameters.
|
166
|
+
#
|
167
|
+
def untyped_args?: (Interface::Function::Params) -> bool
|
156
168
|
end
|
157
169
|
end
|
158
170
|
end
|
@@ -8,7 +8,7 @@ module Steep
|
|
8
8
|
#
|
9
9
|
class MethodContext
|
10
10
|
# Name of the method
|
11
|
-
attr_reader name: Symbol
|
11
|
+
attr_reader name: Symbol
|
12
12
|
|
13
13
|
# `nil` when RBS doesn't have the corresponding method definition
|
14
14
|
attr_reader method: RBS::Definition::Method?
|
@@ -36,6 +36,10 @@ module Steep
|
|
36
36
|
|
37
37
|
# Type of the block of the current method type
|
38
38
|
def block_type: () -> Interface::Block?
|
39
|
+
|
40
|
+
# Returns `true` if the method is a setter -- ends with `=`
|
41
|
+
#
|
42
|
+
def attribute_setter?: () -> bool
|
39
43
|
end
|
40
44
|
|
41
45
|
# Information about the block which the body is being type checked
|
@@ -2,36 +2,37 @@ module Steep
|
|
2
2
|
module TypeInference
|
3
3
|
class ContextArray
|
4
4
|
class Entry
|
5
|
-
attr_reader range:
|
5
|
+
attr_reader range: Range[Integer]
|
6
6
|
|
7
|
-
attr_reader context:
|
7
|
+
attr_reader context: Context
|
8
8
|
|
9
|
-
attr_reader sub_entries:
|
9
|
+
attr_reader sub_entries: Set[Entry]
|
10
10
|
|
11
|
-
def initialize: (range:
|
11
|
+
def initialize: (range: Range[Integer], context: Context) -> void
|
12
12
|
end
|
13
13
|
|
14
|
-
attr_reader buffer:
|
14
|
+
attr_reader buffer: RBS::Buffer
|
15
15
|
|
16
|
-
attr_reader root:
|
16
|
+
attr_reader root: Entry
|
17
17
|
|
18
|
-
def initialize: (buffer:
|
18
|
+
def initialize: (buffer: RBS::Buffer, context: Context, ?range: Range[Integer]) -> void
|
19
19
|
|
20
|
-
def range: () ->
|
20
|
+
def range: () -> Range[Integer]
|
21
21
|
|
22
|
-
def self.from_source: (source:
|
22
|
+
def self.from_source: (source: Source, ?range: Range[Integer]?, context: Context) -> ContextArray
|
23
23
|
|
24
|
-
def insert_context: (
|
24
|
+
def insert_context: (Range[Integer] range, context: Context, ?entry: Entry) -> void
|
25
25
|
|
26
|
-
def each_entry: () { (
|
26
|
+
def each_entry: () { (Entry) -> void } -> void
|
27
|
+
| () -> Enumerator[Entry, void]
|
27
28
|
|
28
|
-
def context_at: (
|
29
|
+
def context_at: (Integer index, ?entry: Entry) -> Context?
|
29
30
|
|
30
|
-
def []: (
|
31
|
+
def []: (Integer index) -> Context?
|
31
32
|
|
32
|
-
def at: (line:
|
33
|
+
def at: (line: Integer, column: Integer) -> Context?
|
33
34
|
|
34
|
-
def merge: (
|
35
|
+
def merge: (ContextArray subtree) -> void
|
35
36
|
end
|
36
37
|
end
|
37
38
|
end
|
@@ -1,6 +1,34 @@
|
|
1
1
|
module Steep
|
2
2
|
module TypeInference
|
3
3
|
class LogicTypeInterpreter
|
4
|
+
class Result
|
5
|
+
attr_reader env: TypeEnv
|
6
|
+
|
7
|
+
attr_reader type: AST::Types::t
|
8
|
+
|
9
|
+
attr_accessor unreachable: bool
|
10
|
+
|
11
|
+
def initialize: (env: TypeEnv, type: AST::Types::t, unreachable: bool) -> void
|
12
|
+
|
13
|
+
def update_env: () { () -> TypeEnv } -> Result
|
14
|
+
|
15
|
+
def update_type: { () -> AST::Types::t } -> Result
|
16
|
+
|
17
|
+
# Make the instance unreachable, and returns self
|
18
|
+
#
|
19
|
+
def unreachable!: () -> self
|
20
|
+
end
|
21
|
+
|
22
|
+
TRUE: AST::Types::Literal
|
23
|
+
|
24
|
+
FALSE: AST::Types::Literal
|
25
|
+
|
26
|
+
BOOL: AST::Types::Boolean
|
27
|
+
|
28
|
+
BOT: AST::Types::Bot
|
29
|
+
|
30
|
+
UNTYPED: AST::Types::Any
|
31
|
+
|
4
32
|
attr_reader subtyping: Subtyping::Check
|
5
33
|
|
6
34
|
attr_reader typing: Typing
|
@@ -11,11 +39,11 @@ module Steep
|
|
11
39
|
|
12
40
|
def initialize: (subtyping: Subtyping::Check, typing: Typing, config: Interface::Builder::Config) -> void
|
13
41
|
|
14
|
-
def eval: (env: TypeEnv, node: Parser::AST::Node) -> [
|
42
|
+
def eval: (env: TypeEnv, node: Parser::AST::Node) -> [Result, Result]
|
15
43
|
|
16
|
-
def evaluate_node: (env: TypeEnv, node: Parser::AST::Node,
|
44
|
+
def evaluate_node: (env: TypeEnv, node: Parser::AST::Node, ?type: AST::Types::t) -> [Result, Result]
|
17
45
|
|
18
|
-
def evaluate_method_call: (env: TypeEnv, type: AST::Types::Logic::Base, receiver: Parser::AST::Node?, arguments: Array[Parser::AST::Node]
|
46
|
+
def evaluate_method_call: (env: TypeEnv, type: AST::Types::Logic::Base, receiver: Parser::AST::Node?, arguments: Array[Parser::AST::Node]) -> [Result, Result]?
|
19
47
|
|
20
48
|
# Apply type refinement to `node` as `truthy_type` and `falsy_type`.
|
21
49
|
#
|
@@ -27,7 +55,7 @@ module Steep
|
|
27
55
|
# * `node` is a `lvasgn`
|
28
56
|
# * `node` is a _pure_ method call
|
29
57
|
#
|
30
|
-
def refine_node_type: (env: TypeEnv, node: Parser::AST::Node, truthy_type: AST::Types::t, falsy_type: AST::Types::t
|
58
|
+
def refine_node_type: (env: TypeEnv, node: Parser::AST::Node, truthy_type: AST::Types::t, falsy_type: AST::Types::t) -> [TypeEnv, TypeEnv]
|
31
59
|
|
32
60
|
# Returns a pair of a node and set of local variable names.
|
33
61
|
#
|
@@ -45,7 +73,9 @@ module Steep
|
|
45
73
|
|
46
74
|
private
|
47
75
|
|
48
|
-
|
76
|
+
# Assign local variables included in the assignment node and masgn node
|
77
|
+
#
|
78
|
+
def evaluate_assignment: (Parser::AST::Node node, TypeEnv env, AST::Types::t rhs_type) -> TypeEnv
|
49
79
|
|
50
80
|
def guess_type_from_method: (Parser::AST::Node node) -> (AST::Types::Logic::ReceiverIsArg | AST::Types::Logic::ReceiverIsNil | AST::Types::Logic::Not | AST::Types::Logic::ArgIsReceiver | nil)
|
51
81
|
|
@@ -64,7 +94,7 @@ module Steep
|
|
64
94
|
#
|
65
95
|
def literal_var_type_case_select: (Parser::AST::Node value_node, AST::Types::t arg_type) -> [Array[AST::Types::t], Array[AST::Types::t]]?
|
66
96
|
|
67
|
-
def type_case_select: (AST::Types::t `type`, RBS::TypeName klass) -> [AST::Types::t
|
97
|
+
def type_case_select: (AST::Types::t `type`, RBS::TypeName klass) -> [AST::Types::t?, AST::Types::t?]
|
68
98
|
|
69
99
|
def type_case_select0: (AST::Types::t `type`, RBS::TypeName klass) -> [Array[AST::Types::t], Array[AST::Types::t]]
|
70
100
|
|