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.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.vscode/steep-shared.code-snippets +41 -0
  4. data/CHANGELOG.md +37 -0
  5. data/Gemfile +2 -5
  6. data/Gemfile.lock +20 -17
  7. data/Gemfile.steep +1 -1
  8. data/Gemfile.steep.lock +6 -6
  9. data/Rakefile +198 -0
  10. data/Steepfile +3 -1
  11. data/lib/steep/ast/builtin.rb +9 -7
  12. data/lib/steep/ast/node/type_application.rb +13 -5
  13. data/lib/steep/ast/node/type_assertion.rb +28 -9
  14. data/lib/steep/ast/types/factory.rb +39 -7
  15. data/lib/steep/cli.rb +2 -1
  16. data/lib/steep/diagnostic/deprecated/else_on_exhaustive_case.rb +20 -0
  17. data/lib/steep/diagnostic/lsp_formatter.rb +3 -3
  18. data/lib/steep/diagnostic/ruby.rb +73 -12
  19. data/lib/steep/drivers/annotations.rb +1 -0
  20. data/lib/steep/drivers/check.rb +18 -13
  21. data/lib/steep/drivers/checkfile.rb +1 -1
  22. data/lib/steep/drivers/diagnostic_printer.rb +6 -4
  23. data/lib/steep/drivers/init.rb +2 -1
  24. data/lib/steep/drivers/print_project.rb +3 -1
  25. data/lib/steep/drivers/stats.rb +1 -1
  26. data/lib/steep/drivers/utils/driver_helper.rb +10 -8
  27. data/lib/steep/drivers/utils/jobs_option.rb +6 -1
  28. data/lib/steep/drivers/validate.rb +9 -5
  29. data/lib/steep/drivers/watch.rb +8 -3
  30. data/lib/steep/expectations.rb +144 -75
  31. data/lib/steep/index/signature_symbol_provider.rb +22 -13
  32. data/lib/steep/node_helper.rb +172 -0
  33. data/lib/steep/server/base_worker.rb +2 -1
  34. data/lib/steep/server/change_buffer.rb +17 -15
  35. data/lib/steep/server/interaction_worker.rb +20 -0
  36. data/lib/steep/server/lsp_formatter.rb +20 -1
  37. data/lib/steep/server/master.rb +51 -36
  38. data/lib/steep/server/type_check_worker.rb +18 -2
  39. data/lib/steep/server/worker_process.rb +19 -2
  40. data/lib/steep/services/completion_provider.rb +189 -3
  41. data/lib/steep/services/file_loader.rb +1 -1
  42. data/lib/steep/services/goto_service.rb +123 -27
  43. data/lib/steep/services/signature_help_provider.rb +1 -6
  44. data/lib/steep/signature/validator.rb +6 -1
  45. data/lib/steep/source.rb +165 -108
  46. data/lib/steep/subtyping/check.rb +5 -3
  47. data/lib/steep/subtyping/variable_variance.rb +11 -0
  48. data/lib/steep/thread_waiter.rb +35 -0
  49. data/lib/steep/type_construction.rb +416 -171
  50. data/lib/steep/type_inference/block_params.rb +50 -9
  51. data/lib/steep/type_inference/context.rb +4 -0
  52. data/lib/steep/type_inference/context_array.rb +6 -6
  53. data/lib/steep/type_inference/logic_type_interpreter.rb +202 -68
  54. data/lib/steep/typing.rb +5 -4
  55. data/lib/steep/version.rb +1 -1
  56. data/lib/steep.rb +21 -14
  57. data/sample/Steepfile +1 -0
  58. data/sig/shims/bundler.rbs +3 -0
  59. data/sig/shims/language-server_protocol.rbs +151 -10
  60. data/sig/shims/parser/nodes.rbs +210 -0
  61. data/sig/shims/parser.rbs +10 -0
  62. data/sig/steep/ast/builtin.rbs +2 -2
  63. data/sig/steep/ast/node/type_application.rbs +2 -2
  64. data/sig/steep/ast/node/type_assertion.rbs +8 -2
  65. data/sig/steep/ast/types/factory.rbs +28 -1
  66. data/sig/steep/diagnostic/deprecated/else_on_exhaustive_case.rbs +13 -0
  67. data/sig/steep/diagnostic/lsp_formatter.rbs +5 -2
  68. data/sig/steep/diagnostic/ruby.rbs +76 -6
  69. data/sig/steep/drivers/annotations.rbs +5 -5
  70. data/sig/steep/drivers/check.rbs +11 -11
  71. data/sig/steep/drivers/diagnostic_printer.rbs +9 -9
  72. data/sig/steep/drivers/init.rbs +6 -6
  73. data/sig/steep/drivers/print_project.rbs +4 -4
  74. data/sig/steep/drivers/utils/driver_helper.rbs +8 -6
  75. data/sig/steep/drivers/validate.rbs +4 -4
  76. data/sig/steep/drivers/watch.rbs +1 -1
  77. data/sig/steep/expectations.rbs +72 -0
  78. data/sig/steep/index/signature_symbol_provider.rbs +22 -10
  79. data/sig/steep/interface/block.rbs +2 -0
  80. data/sig/steep/interface/function.rbs +2 -2
  81. data/sig/steep/node_helper.rbs +56 -0
  82. data/sig/steep/path_helper.rbs +1 -1
  83. data/sig/steep/project/options.rbs +1 -1
  84. data/sig/steep/range_extension.rbs +2 -2
  85. data/sig/steep/server/master.rbs +16 -2
  86. data/sig/steep/server/type_check_worker.rbs +5 -1
  87. data/sig/steep/server/worker_process.rbs +5 -1
  88. data/sig/steep/services/completion_provider.rbs +31 -1
  89. data/sig/steep/services/goto_service.rbs +80 -19
  90. data/sig/steep/source.rbs +27 -4
  91. data/sig/steep/subtyping/variable_variance.rbs +9 -9
  92. data/sig/steep/thread_waiter.rbs +13 -0
  93. data/sig/steep/type_construction.rbs +26 -9
  94. data/sig/steep/type_inference/block_params.rbs +13 -1
  95. data/sig/steep/type_inference/context.rbs +5 -1
  96. data/sig/steep/type_inference/context_array.rbs +16 -15
  97. data/sig/steep/type_inference/logic_type_interpreter.rbs +36 -6
  98. data/sig/steep/type_inference/type_env_builder.rbs +4 -0
  99. data/sig/steep/typing.rbs +22 -20
  100. data/sig/steep.rbs +14 -13
  101. data/smoke/and/a.rb +1 -1
  102. data/smoke/and/test_expectations.yml +5 -7
  103. data/smoke/diagnostics/incompatible_annotation.rb +1 -1
  104. data/smoke/diagnostics/test_expectations.yml +2 -2
  105. data/smoke/enumerator/a.rb +0 -7
  106. data/smoke/enumerator/b.rb +0 -2
  107. data/smoke/enumerator/test_expectations.yml +17 -105
  108. data/smoke/lambda/a.rb +0 -5
  109. data/smoke/lambda/test_expectations.yml +0 -22
  110. data/smoke/type_case/test_expectations.yml +10 -0
  111. data/steep.gemspec +2 -2
  112. metadata +16 -9
@@ -152,7 +152,29 @@ module Steep
152
152
  ) -> void
153
153
  end
154
154
 
155
- type item = InstanceVariableItem | LocalVariableItem | ConstantItem | SimpleMethodNameItem | ComplexMethodNameItem | GeneratedMethodNameItem
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
- module SourceHelper
7
- def from_ruby?: () -> untyped
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
- def from_rbs?: () -> untyped
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
- ConstantQuery: untyped
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
- MethodQuery: untyped
67
+ attr_reader assignment: PathAssignment
15
68
 
16
- TypeNameQuery: untyped
69
+ def initialize: (type_check: TypeCheckService, assignment: PathAssignment) -> void
17
70
 
18
- attr_reader type_check: untyped
71
+ def project: () -> Project
19
72
 
20
- attr_reader assignment: untyped
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
- def initialize: (type_check: untyped, assignment: untyped) -> void
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
- def project: () -> untyped
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
- def implementation: (path: untyped, line: untyped, column: untyped) -> untyped
85
+ private
27
86
 
28
- def definition: (path: untyped, line: untyped, column: untyped) -> untyped
87
+ # Returns a set of queries
88
+ def query_at: (path: Pathname, line: Integer, column: Integer) -> Array[query]
29
89
 
30
- def test_ast_location: (untyped loc, line: untyped, column: untyped) -> (false | true)
90
+ def each_type_name: (AST::Types::t) { (TypeName) -> void } -> void
91
+ | (AST::Types::t) -> Enumerator[TypeName, void]
31
92
 
32
- def query_at: (path: untyped, line: untyped, column: untyped) -> untyped
93
+ def test_ast_location: (Parser::Source::Range loc, line: Integer, column: Integer) -> bool
33
94
 
34
- def type_check_path: (target: untyped, path: untyped, content: untyped, line: untyped, column: untyped) -> untyped
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: (untyped name, locations: untyped) -> untyped
97
+ def constant_definition_in_rbs: (TypeName name, locations: Array[loc]) -> Array[loc]
37
98
 
38
- def constant_definition_in_ruby: (untyped name, locations: untyped) -> untyped
99
+ def constant_definition_in_ruby: (TypeName name, locations: Array[loc]) -> Array[loc]
39
100
 
40
- def method_locations: (untyped name, in_ruby: untyped, in_rbs: untyped, locations: untyped) -> untyped
101
+ def method_locations: (method_name, in_ruby: bool, in_rbs: bool, locations: Array[loc]) -> Array[loc]
41
102
 
42
- def type_name_locations: (untyped name, ?locations: untyped) -> untyped
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
- def initialize: (path: Pathname, node: Parser::AST::Node?, mapping: Hash[Parser::AST::Node, Array[AST::Annotation::t]]) -> void
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::Ruby31
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: untyped
4
+ attr_reader covariants: Set[Symbol]
5
5
 
6
- attr_reader contravariants: untyped
6
+ attr_reader contravariants: Set[Symbol]
7
7
 
8
- def initialize: (covariants: untyped, contravariants: untyped) -> void
8
+ def initialize: (covariants: Set[Symbol], contravariants: Set[Symbol]) -> void
9
9
 
10
- def covariant?: (untyped var) -> untyped
10
+ def covariant?: (Symbol var) -> bool
11
11
 
12
- def contravariant?: (untyped var) -> untyped
12
+ def contravariant?: (Symbol var) -> bool
13
13
 
14
- def invariant?: (untyped var) -> untyped
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: (untyped method_type) -> untyped
18
+ def self.from_method_type: (Interface::MethodType method_type) -> VariableVariance
19
19
 
20
- def self.add_params: (untyped params, block: untyped, covariants: untyped, contravariants: untyped) -> untyped
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: (untyped `type`, variance: untyped, covariants: untyped, contravariants: untyped) -> untyped
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
@@ -0,0 +1,13 @@
1
+ module Steep
2
+ class ThreadWaiter[A]
3
+ attr_reader objects: Array[A]
4
+
5
+ attr_reader queue: Thread::Queue
6
+
7
+ attr_reader waiter_threads: Set[Thread]
8
+
9
+ def initialize: (Array[A]) { (A) -> Thread } -> void
10
+
11
+ def wait_one: () -> Thread?
12
+ end
13
+ 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
- def optional_proc?: (untyped `type`) -> (untyped | nil | nil | nil | nil)
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, type_hint: AST::Types::t?) -> Pair
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: { array_compact: untyped, hash_compact: untyped }
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?) -> untyped
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: untyped
5
+ attr_reader range: Range[Integer]
6
6
 
7
- attr_reader context: untyped
7
+ attr_reader context: Context
8
8
 
9
- attr_reader sub_entries: untyped
9
+ attr_reader sub_entries: Set[Entry]
10
10
 
11
- def initialize: (range: untyped, context: untyped) -> void
11
+ def initialize: (range: Range[Integer], context: Context) -> void
12
12
  end
13
13
 
14
- attr_reader buffer: untyped
14
+ attr_reader buffer: RBS::Buffer
15
15
 
16
- attr_reader root: untyped
16
+ attr_reader root: Entry
17
17
 
18
- def initialize: (buffer: untyped, context: untyped, ?range: untyped) -> void
18
+ def initialize: (buffer: RBS::Buffer, context: Context, ?range: Range[Integer]) -> void
19
19
 
20
- def range: () -> untyped
20
+ def range: () -> Range[Integer]
21
21
 
22
- def self.from_source: (source: untyped, ?range: untyped?, ?context: untyped?) -> untyped
22
+ def self.from_source: (source: Source, ?range: Range[Integer]?, context: Context) -> ContextArray
23
23
 
24
- def insert_context: (untyped range, context: untyped, ?entry: untyped) -> untyped
24
+ def insert_context: (Range[Integer] range, context: Context, ?entry: Entry) -> void
25
25
 
26
- def each_entry: () { (untyped) -> untyped } -> untyped
26
+ def each_entry: () { (Entry) -> void } -> void
27
+ | () -> Enumerator[Entry, void]
27
28
 
28
- def context_at: (untyped index, ?entry: untyped) -> (nil | untyped)
29
+ def context_at: (Integer index, ?entry: Entry) -> Context?
29
30
 
30
- def []: (untyped index) -> untyped
31
+ def []: (Integer index) -> Context?
31
32
 
32
- def at: (line: untyped, column: untyped) -> untyped
33
+ def at: (line: Integer, column: Integer) -> Context?
33
34
 
34
- def merge: (untyped subtree) -> untyped
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) -> [TypeEnv, TypeEnv, Set[Symbol | Parser::AST::Node], AST::Types::t, AST::Types::t]
42
+ def eval: (env: TypeEnv, node: Parser::AST::Node) -> [Result, Result]
15
43
 
16
- def evaluate_node: (env: TypeEnv, node: Parser::AST::Node, refined_objects: Set[Symbol | Parser::AST::Node]) -> [AST::Types::t, AST::Types::t, TypeEnv, TypeEnv]
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], refined_objects: Set[Symbol | Parser::AST::Node]) -> [TypeEnv, TypeEnv]?
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, refined_objects: Set[Symbol | Parser::AST::Node]) -> [TypeEnv, TypeEnv]
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
- def evaluate_assignment: (Parser::AST::Node node, TypeEnv env, AST::Types::t rhs_type, refined_objects: Set[Symbol | Parser::AST::Node]) -> TypeEnv
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, 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
 
@@ -49,7 +49,11 @@ module Steep
49
49
  end
50
50
 
51
51
  class ImportInstanceVariableAnnotations < AnnotationsBase
52
+ def merge!: (?bool) -> self
53
+
52
54
  include _Base
55
+
56
+ @merge: bool
53
57
  end
54
58
 
55
59
  class ImportInstanceVariableDefinition