steep 1.4.0.dev.2 → 1.4.0.dev.3
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/ruby.yml +1 -2
- data/Gemfile +1 -1
- data/Gemfile.lock +7 -9
- data/Gemfile.steep +1 -2
- data/Gemfile.steep.lock +9 -10
- data/README.md +7 -1
- data/Steepfile +0 -3
- data/bin/rbs +0 -1
- data/guides/README.md +5 -0
- data/guides/src/gem-rbs-collection/gem-rbs-collection.md +143 -0
- data/guides/src/getting-started/getting-started.md +164 -0
- data/guides/src/nil-optional/nil-optional.md +195 -0
- data/lib/steep/diagnostic/ruby.rb +79 -4
- data/lib/steep/drivers/check.rb +4 -4
- data/lib/steep/interface/block.rb +10 -0
- data/lib/steep/module_helper.rb +13 -11
- data/lib/steep/path_helper.rb +4 -0
- data/lib/steep/server/interaction_worker.rb +105 -92
- data/lib/steep/services/type_name_completion.rb +157 -0
- data/lib/steep/source.rb +1 -0
- data/lib/steep/type_construction.rb +402 -229
- data/lib/steep/type_inference/block_params.rb +13 -0
- data/lib/steep/type_inference/context.rb +3 -3
- data/lib/steep/type_inference/method_params.rb +42 -16
- data/lib/steep/type_inference/send_args.rb +79 -50
- data/lib/steep/type_inference/type_env.rb +7 -1
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +1 -0
- data/rbs_collection.steep.lock.yaml +0 -28
- data/rbs_collection.steep.yaml +10 -9
- data/sample/lib/conference.rb +12 -0
- data/sample/sig/conference.rbs +5 -0
- data/sig/shims/language-server_protocol.rbs +12 -0
- data/sig/shims/parser/nodes.rbs +37 -0
- data/sig/shims/parser.rbs +1 -0
- data/sig/shims/string.rbs +4 -0
- data/sig/steep/ast/types/factory.rbs +10 -8
- data/sig/steep/diagnostic/lsp_formatter.rbs +1 -1
- data/sig/steep/diagnostic/ruby.rbs +38 -2
- data/sig/steep/drivers/check.rbs +1 -1
- data/sig/steep/drivers/checkfile.rbs +1 -1
- data/sig/steep/drivers/diagnostic_printer.rbs +1 -1
- data/sig/steep/drivers/watch.rbs +1 -1
- data/sig/steep/index/signature_symbol_provider.rbs +1 -1
- data/sig/steep/interface/block.rbs +2 -0
- data/sig/steep/interface/builder.rbs +5 -3
- data/sig/steep/interface/method_type.rbs +5 -3
- data/sig/steep/module_helper.rbs +9 -0
- data/sig/steep/path_helper.rbs +3 -1
- data/sig/steep/server/base_worker.rbs +1 -1
- data/sig/steep/server/interaction_worker.rbs +46 -17
- data/sig/steep/server/master.rbs +1 -1
- data/sig/steep/server/type_check_worker.rbs +7 -5
- data/sig/steep/server/worker_process.rbs +6 -4
- data/sig/steep/services/completion_provider.rbs +2 -0
- data/sig/steep/services/type_name_completion.rbs +122 -0
- data/sig/steep/type_construction.rbs +99 -30
- data/sig/steep/type_inference/block_params.rbs +4 -0
- data/sig/steep/type_inference/context.rbs +70 -22
- data/sig/steep/type_inference/method_params.rbs +43 -24
- data/sig/steep/type_inference/multiple_assignment.rbs +1 -1
- data/sig/steep/type_inference/send_args.rbs +13 -3
- data/sig/steep/typing.rbs +7 -2
- data/smoke/diagnostics/test_expectations.yml +1 -0
- data/steep.gemspec +0 -1
- metadata +10 -16
@@ -20,6 +20,8 @@ module Steep
|
|
20
20
|
|
21
21
|
include NodeHelper
|
22
22
|
|
23
|
+
include ModuleHelper
|
24
|
+
|
23
25
|
attr_reader checker: Subtyping::Check
|
24
26
|
|
25
27
|
attr_reader source: Source
|
@@ -30,9 +32,7 @@ module Steep
|
|
30
32
|
|
31
33
|
attr_reader context: TypeInference::Context
|
32
34
|
|
33
|
-
%a{pure} def module_context: () -> TypeInference::Context::ModuleContext
|
34
|
-
|
35
|
-
def module_context!: () -> TypeInference::Context::ModuleContext
|
35
|
+
%a{pure} def module_context: () -> TypeInference::Context::ModuleContext
|
36
36
|
|
37
37
|
%a{pure} def method_context: () -> TypeInference::Context::MethodContext?
|
38
38
|
|
@@ -40,6 +40,8 @@ module Steep
|
|
40
40
|
|
41
41
|
%a{pure} def block_context: () -> TypeInference::Context::BlockContext?
|
42
42
|
|
43
|
+
def block_context!: () -> TypeInference::Context::BlockContext
|
44
|
+
|
43
45
|
%a{pure} def break_context: () -> TypeInference::Context::BreakContext?
|
44
46
|
|
45
47
|
%a{pure} def self_type: () -> AST::Types::t
|
@@ -58,7 +60,7 @@ module Steep
|
|
58
60
|
|
59
61
|
def update_type_env: () { (TypeInference::TypeEnv) -> TypeInference::TypeEnv } -> TypeConstruction
|
60
62
|
|
61
|
-
def check_relation: (sub_type: AST::Types::t, super_type: AST::Types::t, ?constraints: Subtyping::Constraints) -> Subtyping::Result::
|
63
|
+
def check_relation: (sub_type: AST::Types::t, super_type: AST::Types::t, ?constraints: Subtyping::Constraints) -> Subtyping::Result::t
|
62
64
|
|
63
65
|
# This is a variation of `#check_relation` method.
|
64
66
|
# It checks if given subtyping relation `sub_type <: super_type` holds or not, and returns truthy when *doesn't* hold.
|
@@ -82,7 +84,7 @@ module Steep
|
|
82
84
|
|
83
85
|
def implement_module: (module_name: RBS::TypeName, annotations: AST::Annotation::Collection, ?super_name: RBS::TypeName?) -> AST::Annotation::Implements::Module?
|
84
86
|
|
85
|
-
def default_module_context: (
|
87
|
+
def default_module_context: (AST::Annotation::Implements::Module? implement_module_name, nesting: RBS::Resolver::context) -> TypeInference::Context::ModuleContext
|
86
88
|
|
87
89
|
def for_module: (untyped node, untyped new_module_name) -> untyped
|
88
90
|
|
@@ -104,7 +106,7 @@ module Steep
|
|
104
106
|
|
105
107
|
def for_sclass: (Parser::AST::Node node, AST::Types::t `type`) -> TypeConstruction?
|
106
108
|
|
107
|
-
def for_branch: (Parser::AST::Node node, ?break_context: TypeInference::Context::BreakContext?) ->
|
109
|
+
def for_branch: (Parser::AST::Node node, ?break_context: TypeInference::Context::BreakContext?) -> TypeConstruction
|
108
110
|
|
109
111
|
def add_typing: (Parser::AST::Node node, type: AST::Types::t, ?constr: TypeConstruction) -> Pair
|
110
112
|
|
@@ -112,7 +114,7 @@ module Steep
|
|
112
114
|
|
113
115
|
def synthesize: (Parser::AST::Node node, ?hint: AST::Types::t?, ?condition: bool) -> Pair
|
114
116
|
|
115
|
-
def check: (Parser::AST::Node node, AST::Types::t `type`, ?constraints: Subtyping::Constraints) { (AST::Types::t, AST::Types::t, Subtyping::Result::
|
117
|
+
def check: (Parser::AST::Node node, AST::Types::t `type`, ?constraints: Subtyping::Constraints) { (AST::Types::t, AST::Types::t, Subtyping::Result::t) -> void } -> Pair
|
116
118
|
|
117
119
|
def masgn_lhs?: (untyped lhs) -> untyped
|
118
120
|
|
@@ -126,13 +128,43 @@ module Steep
|
|
126
128
|
|
127
129
|
def constant_typename: (Parser::AST::Node parent, Symbol name) -> RBS::TypeName?
|
128
130
|
|
129
|
-
|
131
|
+
# Synthesize a constant declaration -- :cdecl, :class, or :module
|
132
|
+
#
|
133
|
+
# * `node` is the node that references a constant
|
134
|
+
# * `parent_node` is the parent (namespace) of a constant reference
|
135
|
+
# * `constant_name` is the name of constant
|
136
|
+
#
|
137
|
+
# Yields a block that is expected to add an error, or it reports Diagnostic::Ruby::UnknownConstant if not given.
|
138
|
+
#
|
139
|
+
# Returns a tuple of
|
140
|
+
#
|
141
|
+
# * The type of the constant
|
142
|
+
# * TypeConstruction instance after the evaluation
|
143
|
+
# * The full name of the constant
|
144
|
+
#
|
145
|
+
def synthesize_constant_decl: (Parser::AST::Node? node, Parser::AST::Node? parent_node, Symbol constant_name) ?{ () -> void } -> [AST::Types::t, TypeConstruction, RBS::TypeName?]
|
146
|
+
|
147
|
+
# Synthesize a constant reference
|
148
|
+
#
|
149
|
+
# * `node` is the node that references a constant
|
150
|
+
# * `parent_node` is the parent (namespace) of a constant reference
|
151
|
+
# * `constant_name` is the name of constant
|
152
|
+
#
|
153
|
+
# Yields a block that is expected to add an error, or it reports Diagnostic::Ruby::UnknownConstant if not given.
|
154
|
+
#
|
155
|
+
# Returns a tuple of
|
156
|
+
#
|
157
|
+
# * The type of the constant
|
158
|
+
# * TypeConstruction instance after the evaluation
|
159
|
+
# * The full name of the constant
|
160
|
+
#
|
161
|
+
def synthesize_constant: (Parser::AST::Node? node, Parser::AST::Node? parent_node, Symbol constant_name) ?{ () -> void } -> [AST::Types::t, TypeConstruction, RBS::TypeName?]
|
130
162
|
|
131
163
|
def optional_proc?: (untyped `type`) -> (untyped | nil | nil | nil | nil)
|
132
164
|
|
133
|
-
def type_lambda: (Parser::AST::Node node, params_node: Parser::AST::Node, body_node: Parser::AST::Node, type_hint: AST::Types::t?) -> Pair
|
165
|
+
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
|
134
166
|
|
135
|
-
def synthesize_children: (Parser::AST::Node node, ?skips: Array[Parser::AST::Node]) -> TypeConstruction
|
167
|
+
def synthesize_children: (Parser::AST::Node node, ?skips: Array[Parser::AST::Node?]) -> TypeConstruction
|
136
168
|
|
137
169
|
# Synthesize `:send`, `:csend`, `:block`, and `:numblock` node
|
138
170
|
#
|
@@ -255,7 +287,13 @@ module Steep
|
|
255
287
|
|
256
288
|
def eliminate_vars: (untyped `type`, untyped variables, ?to: untyped) -> untyped
|
257
289
|
|
290
|
+
# Type check arguments
|
291
|
+
#
|
292
|
+
# * Receives the `method_name` of a method that is being called
|
293
|
+
# * `method_name` is `nil` if it type checks arguments of block or proc
|
294
|
+
#
|
258
295
|
def type_check_args: (
|
296
|
+
Symbol | nil,
|
259
297
|
TypeInference::SendArgs,
|
260
298
|
Subtyping::Constraints,
|
261
299
|
Array[Diagnostic::Ruby::Base]
|
@@ -263,7 +301,7 @@ module Steep
|
|
263
301
|
|
264
302
|
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
|
265
303
|
|
266
|
-
def type_block_without_hint: (node: Parser::AST::Node, block_annotations: AST::Annotation::Collection, block_params: TypeInference::BlockParams?, block_body: Parser::AST::Node?) ?{ (Diagnostic::Ruby::Base) -> void } -> void
|
304
|
+
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
|
267
305
|
|
268
306
|
def set_up_block_mlhs_params_env: (
|
269
307
|
Parser::AST::Node mlhs_node,
|
@@ -299,15 +337,19 @@ module Steep
|
|
299
337
|
|
300
338
|
# Synthesize the block body and returns the type of the body
|
301
339
|
#
|
302
|
-
# The constructor can be discarded because it cannot change anything outer than block.
|
340
|
+
# The constructor can be safely discarded because it cannot change anything outer than block.
|
303
341
|
#
|
304
|
-
def synthesize_block: (
|
342
|
+
def synthesize_block: (
|
343
|
+
node: Parser::AST::Node & Parser::AST::_BlockNode,
|
344
|
+
block_type_hint: AST::Types::t?,
|
345
|
+
block_body: Parser::AST::Node?
|
346
|
+
) -> AST::Types::t
|
305
347
|
|
306
|
-
def nesting: () -> RBS::Resolver::context
|
348
|
+
%a{pure} def nesting: () -> RBS::Resolver::context
|
307
349
|
|
308
350
|
def absolute_name: (untyped name) -> untyped
|
309
351
|
|
310
|
-
def union_type: (*AST::Types::t types) -> AST::Types::t
|
352
|
+
def union_type: (*AST::Types::t? types) -> AST::Types::t
|
311
353
|
|
312
354
|
# Returns union type of given types
|
313
355
|
#
|
@@ -328,27 +370,35 @@ module Steep
|
|
328
370
|
#
|
329
371
|
def union_of_tuple_to_tuple_of_union: (AST::Types::Union) -> AST::Types::Tuple?
|
330
372
|
|
331
|
-
def validate_method_definitions: (
|
373
|
+
def validate_method_definitions: (Parser::AST::Node node, AST::Annotation::Implements::Module module_name) -> void
|
332
374
|
|
333
375
|
def fallback_to_any: (Parser::AST::Node node) ?{ () -> Diagnostic::Ruby::Base } -> Pair
|
334
376
|
|
335
|
-
|
377
|
+
# Return `true` if `node` is `self.class`
|
378
|
+
def self_class?: (Parser::AST::Node node) -> bool
|
336
379
|
|
337
|
-
|
380
|
+
# Returns `true` if the given `node` is a `class` or `module` declaration that only contains module/class definitions
|
381
|
+
#
|
382
|
+
def namespace_module?: (Parser::AST::Node node) -> bool
|
338
383
|
|
339
384
|
def type_any_rec: (Parser::AST::Node node) -> Pair
|
340
385
|
|
341
386
|
def unwrap: (AST::Types::t `type`) -> AST::Types::t
|
342
387
|
|
388
|
+
# Returns `nil` if `type` is recursive
|
389
|
+
#
|
390
|
+
# See `Factory#deep_expand_alias`.
|
391
|
+
#
|
343
392
|
def deep_expand_alias: (AST::Types::t `type`) -> AST::Types::t?
|
344
393
|
|
345
|
-
|
394
|
+
# `A | B | ... | Z` => `[A, B, ..., Z]`
|
395
|
+
def flatten_union: (AST::Types::t) -> Array[AST::Types::t]
|
346
396
|
|
347
|
-
def select_flatten_types: (
|
397
|
+
def select_flatten_types: (AST::Types::t) { (AST::Types::t) -> boolish } -> Array[AST::Types::t]
|
348
398
|
|
349
|
-
def partition_flatten_types: (AST::Types::t
|
399
|
+
def partition_flatten_types: (AST::Types::t) { (AST::Types::t) -> boolish } -> [Array[AST::Types::t], Array[AST::Types::t]]
|
350
400
|
|
351
|
-
def flatten_array_elements: (
|
401
|
+
def flatten_array_elements: (AST::Types::t) -> Array[AST::Types::t]
|
352
402
|
|
353
403
|
def expand_alias: (AST::Types::t `type`) -> AST::Types::t
|
354
404
|
| [A] (AST::Types::t) { (AST::Types::t) -> A } -> A
|
@@ -357,7 +407,12 @@ module Steep
|
|
357
407
|
|
358
408
|
def to_instance_type: (untyped `type`, ?args: untyped?) -> untyped
|
359
409
|
|
360
|
-
|
410
|
+
# Synthesize the type of a node, assuming it has tuple type when possible
|
411
|
+
#
|
412
|
+
# * Try `#try_tuple_type` if applicable, or
|
413
|
+
# * Run the normal `#synthesize` else
|
414
|
+
#
|
415
|
+
def try_tuple_type!: (Parser::AST::Node node, ?hint: AST::Types::t?) -> Pair
|
361
416
|
|
362
417
|
# Try to give `array_node` a tuple type
|
363
418
|
#
|
@@ -428,22 +483,36 @@ module Steep
|
|
428
483
|
# * When hint is union type, it tries recursively with the union cases.
|
429
484
|
# * Otherwise, it tries to be a hash instance.
|
430
485
|
#
|
431
|
-
def type_hash: (
|
486
|
+
def type_hash: (Parser::AST::Node hash_node, hint: AST::Types::t?) -> untyped
|
432
487
|
|
433
488
|
# Returns the first one from elements of `types` that returns a type `t` where `t <: hint`.
|
434
489
|
#
|
435
490
|
def pick_one_of: (Array[AST::Types::t] types, range: untyped) { (AST::Types::t hint, TypeConstruction) -> Pair? } -> Pair?
|
436
491
|
|
437
|
-
|
492
|
+
# *Commit* the transaction (current typing) and returns a `TypeConstruction` with saved typing
|
493
|
+
#
|
494
|
+
# ```ruby
|
495
|
+
# transaction = typing.new_child(range) {|child| constr.with_new_typing(child) }
|
496
|
+
#
|
497
|
+
# # Do something that may fail
|
498
|
+
#
|
499
|
+
# if succeeded
|
500
|
+
# # Commit the may-fail operation
|
501
|
+
# constr = transaction.save_typing()
|
502
|
+
# else
|
503
|
+
# # Abort the transaction
|
504
|
+
# end
|
505
|
+
# ```
|
506
|
+
def save_typing: () -> TypeConstruction
|
438
507
|
|
439
|
-
# Returns `true` if a method call can be identified as _pure_
|
508
|
+
# Returns `true` if a method call can be identified as _pure_:
|
440
509
|
#
|
441
|
-
# * The `node` is not a call with
|
442
|
-
# * It always calls _pure_ method
|
443
|
-
# * The `receiver` is _pure_
|
510
|
+
# * The `node` is not a call with block,
|
511
|
+
# * It always calls _pure_ method,
|
512
|
+
# * The `receiver` is _pure_, and
|
444
513
|
# * All of the arguments are _pure_
|
445
514
|
#
|
446
|
-
def pure_send?: (TypeInference::MethodCall::Typed call, Parser::AST::Node receiver, Array[Parser::AST::Node] arguments) -> bool
|
515
|
+
def pure_send?: (TypeInference::MethodCall::Typed call, Parser::AST::Node? receiver, Array[Parser::AST::Node] arguments) -> bool
|
447
516
|
|
448
517
|
# Transform given `node` to a node that has a local variable instead of the outer most call/non-value node
|
449
518
|
#
|
@@ -149,6 +149,10 @@ module Steep
|
|
149
149
|
|
150
150
|
def each: () { (Param | MultipleParam) -> void } -> void
|
151
151
|
| () -> Enumerator[Param | MultipleParam, void]
|
152
|
+
|
153
|
+
# Yields `Param` recursively
|
154
|
+
#
|
155
|
+
def each_single_param: () { (Param) -> void } -> void
|
152
156
|
end
|
153
157
|
end
|
154
158
|
end
|
@@ -1,31 +1,45 @@
|
|
1
|
+
use Steep::Interface::Function::Params, Steep::Interface::Block
|
2
|
+
|
1
3
|
module Steep
|
2
4
|
module TypeInference
|
5
|
+
# Type checking context
|
3
6
|
class Context
|
7
|
+
# Information about the method which the body is being type checked
|
8
|
+
#
|
4
9
|
class MethodContext
|
10
|
+
# Name of the method
|
5
11
|
attr_reader name: Symbol?
|
6
12
|
|
13
|
+
# `nil` when RBS doesn't have the corresponding method definition
|
7
14
|
attr_reader method: RBS::Definition::Method?
|
8
15
|
|
16
|
+
# `nil` when no method type is given
|
9
17
|
attr_reader method_type: Interface::MethodType?
|
10
18
|
|
19
|
+
# Falls back to `untyped`
|
11
20
|
attr_reader return_type: AST::Types::t
|
12
21
|
|
13
|
-
|
14
|
-
|
22
|
+
# The *super* method if identified
|
15
23
|
attr_reader super_method: RBS::Definition::Method?
|
16
24
|
|
25
|
+
# The type of forwarding params when `...` is given
|
26
|
+
attr_reader forward_arg_type: [Params, Block?]?
|
27
|
+
|
17
28
|
def initialize: (
|
18
29
|
name: Symbol,
|
19
30
|
method: RBS::Definition::Method?,
|
20
31
|
method_type: Interface::MethodType?,
|
21
32
|
return_type: AST::Types::t,
|
22
|
-
|
23
|
-
|
33
|
+
super_method: RBS::Definition::Method?,
|
34
|
+
forward_arg_type: [Params, Block?]?
|
24
35
|
) -> void
|
25
36
|
|
37
|
+
# Type of the block of the current method type
|
26
38
|
def block_type: () -> Interface::Block?
|
27
39
|
end
|
28
40
|
|
41
|
+
# Information about the block which the body is being type checked
|
42
|
+
#
|
29
43
|
class BlockContext
|
30
44
|
# The type of block itself
|
31
45
|
#
|
@@ -38,6 +52,7 @@ module Steep
|
|
38
52
|
def subst: (Interface::Substitution) -> BlockContext
|
39
53
|
end
|
40
54
|
|
55
|
+
# Context about the `break` syntax
|
41
56
|
class BreakContext
|
42
57
|
# Type of arguments to `break` statement
|
43
58
|
#
|
@@ -54,23 +69,40 @@ module Steep
|
|
54
69
|
def subst: (Interface::Substitution) -> BreakContext
|
55
70
|
end
|
56
71
|
|
72
|
+
# Information about the module which the body is being type checked
|
73
|
+
#
|
57
74
|
class ModuleContext
|
75
|
+
# The type of an instance of current module
|
58
76
|
attr_reader instance_type: AST::Types::t
|
59
77
|
|
78
|
+
# The type of singleton of current module
|
60
79
|
attr_reader module_type: AST::Types::t
|
61
80
|
|
62
|
-
|
81
|
+
# The set of name of instance methods that is defined in the `module`/`class` statement
|
82
|
+
attr_reader defined_instance_methods: Set[Symbol]
|
63
83
|
|
64
|
-
|
84
|
+
# The set of name of singleton methods that is defined in the `module`/`class` statement
|
85
|
+
attr_reader defined_module_methods: Set[Symbol]
|
65
86
|
|
87
|
+
# The nesting of current module
|
88
|
+
#
|
89
|
+
# Cannot be `nil`.
|
90
|
+
#
|
66
91
|
attr_reader nesting: RBS::Resolver::context
|
67
92
|
|
68
|
-
|
93
|
+
# The name that is given to `@implements` annotation
|
94
|
+
#
|
95
|
+
# `nil` when no `@implements` annotation is given.
|
96
|
+
#
|
97
|
+
attr_reader implement_name: AST::Annotation::Implements::Module?
|
69
98
|
|
99
|
+
# The name of the class/module.
|
70
100
|
attr_reader class_name: RBS::TypeName
|
71
101
|
|
102
|
+
# The definition of the instance of the module
|
72
103
|
attr_reader instance_definition: RBS::Definition?
|
73
104
|
|
105
|
+
# The definition of the singleton of the module
|
74
106
|
attr_reader module_definition: RBS::Definition?
|
75
107
|
|
76
108
|
@class_variables: Hash[Symbol, RBS::Types::t]?
|
@@ -78,19 +110,20 @@ module Steep
|
|
78
110
|
def initialize: (
|
79
111
|
instance_type: AST::Types::t,
|
80
112
|
module_type: AST::Types::t,
|
81
|
-
implement_name:
|
113
|
+
implement_name: AST::Annotation::Implements::Module?,
|
82
114
|
class_name: RBS::TypeName,
|
83
115
|
nesting: RBS::Resolver::context,
|
84
116
|
?instance_definition: RBS::Definition?,
|
85
117
|
?module_definition: RBS::Definition?
|
86
118
|
) -> void
|
87
119
|
|
88
|
-
|
120
|
+
# Returns a hash from the name of a class variable to its type
|
121
|
+
%a{pure} def class_variables: () -> Hash[Symbol, RBS::Types::t]?
|
89
122
|
|
90
123
|
def update: (
|
91
124
|
?instance_type: AST::Types::t,
|
92
125
|
?module_type: AST::Types::t,
|
93
|
-
?implement_name:
|
126
|
+
?implement_name: AST::Annotation::Implements::Module?,
|
94
127
|
?class_name: RBS::TypeName,
|
95
128
|
?instance_definition: RBS::Definition?,
|
96
129
|
?module_definition: RBS::Definition?,
|
@@ -98,6 +131,8 @@ module Steep
|
|
98
131
|
) -> ModuleContext
|
99
132
|
end
|
100
133
|
|
134
|
+
# Information about the free type variables
|
135
|
+
#
|
101
136
|
class TypeVariableContext
|
102
137
|
attr_reader table: Hash[Symbol, Interface::TypeParam]
|
103
138
|
|
@@ -105,6 +140,7 @@ module Steep
|
|
105
140
|
|
106
141
|
def initialize: (Array[Interface::TypeParam] type_params, ?parent_context: TypeVariableContext?) -> void
|
107
142
|
|
143
|
+
# Returns the upper bound of a type variable
|
108
144
|
def []: (Symbol name) -> AST::Types::t?
|
109
145
|
|
110
146
|
def upper_bounds: () -> Hash[Symbol, AST::Types::t]
|
@@ -112,9 +148,14 @@ module Steep
|
|
112
148
|
def self.empty: () -> TypeVariableContext
|
113
149
|
end
|
114
150
|
|
115
|
-
|
151
|
+
# The caller where a method is called from
|
152
|
+
attr_reader call_context: MethodCall::context
|
116
153
|
|
117
|
-
|
154
|
+
# MethodContext for current execution point
|
155
|
+
#
|
156
|
+
# `nil` when not in any method definition.
|
157
|
+
#
|
158
|
+
attr_reader method_context: MethodContext?
|
118
159
|
|
119
160
|
# BlockContext for current execution point
|
120
161
|
#
|
@@ -122,10 +163,17 @@ module Steep
|
|
122
163
|
#
|
123
164
|
attr_reader block_context: BlockContext?
|
124
165
|
|
166
|
+
# BreakContext for current execution point
|
167
|
+
#
|
168
|
+
# `nil` if `break` is not allowed.
|
169
|
+
#
|
125
170
|
attr_reader break_context: BreakContext?
|
126
171
|
|
127
|
-
|
172
|
+
# ModuleContext for current execution point
|
173
|
+
attr_reader module_context: ModuleContext
|
128
174
|
|
175
|
+
# The type of `self`
|
176
|
+
#
|
129
177
|
attr_reader self_type: AST::Types::t
|
130
178
|
|
131
179
|
attr_reader type_env: TypeEnv
|
@@ -133,25 +181,25 @@ module Steep
|
|
133
181
|
attr_reader variable_context: TypeVariableContext
|
134
182
|
|
135
183
|
def initialize: (
|
136
|
-
method_context:
|
184
|
+
method_context: MethodContext?,
|
137
185
|
block_context: BlockContext?,
|
138
186
|
break_context: BreakContext?,
|
139
|
-
module_context: ModuleContext
|
140
|
-
self_type:
|
187
|
+
module_context: ModuleContext,
|
188
|
+
self_type: AST::Types::t,
|
141
189
|
type_env: TypeEnv,
|
142
|
-
call_context:
|
190
|
+
call_context: MethodCall::context,
|
143
191
|
variable_context: TypeVariableContext
|
144
192
|
) -> void
|
145
193
|
|
146
194
|
def with: (
|
147
|
-
?method_context:
|
195
|
+
?method_context: MethodContext?,
|
148
196
|
?block_context: BlockContext?,
|
149
197
|
?break_context: BreakContext?,
|
150
|
-
?module_context: ModuleContext
|
151
|
-
?self_type:
|
198
|
+
?module_context: ModuleContext,
|
199
|
+
?self_type: AST::Types::t,
|
152
200
|
?type_env: TypeEnv,
|
153
|
-
?call_context:
|
154
|
-
?variable_context:
|
201
|
+
?call_context: MethodCall::context,
|
202
|
+
?variable_context: TypeVariableContext
|
155
203
|
) -> Context
|
156
204
|
|
157
205
|
def factory: () -> AST::Types::Factory
|
@@ -1,24 +1,31 @@
|
|
1
|
+
use Parser::AST::Node, Steep::Interface::MethodType
|
2
|
+
use Steep::Interface::Function::Params, Steep::Interface::Block
|
3
|
+
|
1
4
|
module Steep
|
2
5
|
module TypeInference
|
6
|
+
# A MethodParams object provides the information of parameters from MethodType and nodes
|
7
|
+
#
|
8
|
+
# It primarly provides a mapping from a local variable (method parameter) to its type.
|
9
|
+
#
|
3
10
|
class MethodParams
|
4
11
|
class BaseParameter
|
5
12
|
attr_reader name: Symbol
|
6
13
|
|
7
|
-
attr_reader type:
|
14
|
+
attr_reader type: AST::Types::t?
|
8
15
|
|
9
|
-
attr_reader node:
|
16
|
+
attr_reader node: Node
|
10
17
|
|
11
|
-
def initialize: (name: Symbol, type:
|
18
|
+
def initialize: (name: Symbol, type: AST::Types::t?, node: Node) -> void
|
12
19
|
|
13
20
|
def optional?: () -> bool
|
14
21
|
|
15
|
-
def value: () ->
|
22
|
+
def value: () -> Node?
|
16
23
|
|
17
24
|
def var_type: () -> AST::Types::t
|
18
25
|
|
19
26
|
def untyped?: () -> bool
|
20
27
|
|
21
|
-
def ==: (untyped other) ->
|
28
|
+
def ==: (untyped other) -> bool
|
22
29
|
|
23
30
|
alias eql? ==
|
24
31
|
|
@@ -34,27 +41,25 @@ module Steep
|
|
34
41
|
class BaseRestParameter
|
35
42
|
attr_reader name: Symbol
|
36
43
|
|
37
|
-
attr_reader type:
|
44
|
+
attr_reader type: AST::Types::t?
|
38
45
|
|
39
|
-
attr_reader node:
|
46
|
+
attr_reader node: Node
|
40
47
|
|
41
|
-
def initialize: (name: Symbol, type:
|
48
|
+
def initialize: (name: Symbol, type: AST::Types::t?, node: Node) -> void
|
42
49
|
|
43
50
|
def ==: (untyped other) -> bool
|
44
51
|
|
45
52
|
alias eql? ==
|
46
53
|
|
47
54
|
def hash: () -> Integer
|
48
|
-
|
49
|
-
def var_type: () -> AST::Types::t
|
50
55
|
end
|
51
56
|
|
52
57
|
class PositionalRestParameter < BaseRestParameter
|
53
|
-
def var_type: () -> AST::Types::
|
58
|
+
def var_type: () -> AST::Types::Name::Instance
|
54
59
|
end
|
55
60
|
|
56
61
|
class KeywordRestParameter < BaseRestParameter
|
57
|
-
def var_type: () -> AST::Types::
|
62
|
+
def var_type: () -> AST::Types::Name::Instance
|
58
63
|
end
|
59
64
|
|
60
65
|
class BlockParameter
|
@@ -62,11 +67,11 @@ module Steep
|
|
62
67
|
|
63
68
|
attr_reader type: Interface::Function?
|
64
69
|
|
65
|
-
attr_reader node:
|
70
|
+
attr_reader node: Node
|
66
71
|
|
67
72
|
attr_reader self_type: AST::Types::t?
|
68
73
|
|
69
|
-
def initialize: (name: Symbol, type: Interface::Function?, node:
|
74
|
+
def initialize: (name: Symbol, type: Interface::Function?, node: Node, optional: boolish, self_type: AST::Types::t?) -> void
|
70
75
|
|
71
76
|
@optional: boolish
|
72
77
|
|
@@ -81,28 +86,42 @@ module Steep
|
|
81
86
|
def hash: () -> Integer
|
82
87
|
end
|
83
88
|
|
84
|
-
|
89
|
+
type param = PositionalParameter | KeywordParameter | PositionalRestParameter | KeywordRestParameter | BlockParameter
|
90
|
+
|
91
|
+
# The children of `:args` node
|
92
|
+
attr_reader args: Array[Node]
|
93
|
+
|
94
|
+
attr_reader method_type: MethodType?
|
85
95
|
|
86
|
-
|
96
|
+
# Mapping from the name of parameter to parameter object
|
97
|
+
attr_reader params: Hash[Symbol, param]
|
87
98
|
|
88
|
-
attr_reader
|
99
|
+
attr_reader errors: Array[Diagnostic::Ruby::Base]
|
89
100
|
|
90
|
-
|
101
|
+
# The type of `...`
|
102
|
+
#
|
103
|
+
# `nil` if the node doesn't have it.
|
104
|
+
#
|
105
|
+
attr_reader forward_arg_type: [Params, Block?]?
|
91
106
|
|
92
|
-
def initialize: (args:
|
107
|
+
def initialize: (args: Array[Node], method_type: MethodType?, forward_arg_type: [Params, Block?]?) -> void
|
93
108
|
|
94
|
-
def []: (
|
109
|
+
def []: (Symbol name) -> param
|
110
|
+
|
111
|
+
def param?: (Symbol) -> bool
|
95
112
|
|
96
113
|
def size: () -> Integer
|
97
114
|
|
98
|
-
def each_param: () { (
|
99
|
-
| () -> Enumerator[
|
115
|
+
def each_param: () { (param) -> void } -> void
|
116
|
+
| () -> Enumerator[param, void]
|
100
117
|
|
101
118
|
def each: () { (Symbol, AST::Types::t) -> void } -> void
|
102
119
|
|
103
|
-
def
|
120
|
+
def update: (?forward_arg_type: [Params, Block?]?) -> MethodParams
|
121
|
+
|
122
|
+
def self.empty: (node: Node) -> MethodParams
|
104
123
|
|
105
|
-
def self.build: (node:
|
124
|
+
def self.build: (node: Node, method_type: MethodType) -> MethodParams
|
106
125
|
end
|
107
126
|
end
|
108
127
|
end
|
@@ -59,7 +59,7 @@ module Steep
|
|
59
59
|
# Returns a type hint for multiple assignment right hand side
|
60
60
|
#
|
61
61
|
# It constructs a structure of tuple types, based on the assignment lhs, and variable types.
|
62
|
-
#
|
62
|
+
#
|
63
63
|
def hint_for_mlhs: (Parser::AST::Node mlhs, TypeEnv env) -> AST::Types::t?
|
64
64
|
|
65
65
|
private
|
@@ -68,7 +68,7 @@ module Steep
|
|
68
68
|
|
69
69
|
def following_args: () -> Array[Parser::AST::Node]
|
70
70
|
|
71
|
-
def param: () -> Interface::Function::Params::PositionalParams::param?
|
71
|
+
%a{pure} def param: () -> Interface::Function::Params::PositionalParams::param?
|
72
72
|
|
73
73
|
def update: (?index: Integer, ?positional_params: Interface::Function::Params::PositionalParams?, ?uniform: bool) -> PositionalArgs
|
74
74
|
|
@@ -198,6 +198,14 @@ module Steep
|
|
198
198
|
def node_type: () -> AST::Types::t
|
199
199
|
end
|
200
200
|
|
201
|
+
class ForwardedArgs
|
202
|
+
attr_reader node: Parser::AST::Node
|
203
|
+
|
204
|
+
attr_reader params: Interface::Function::Params
|
205
|
+
|
206
|
+
def initialize: (node: Parser::AST::Node, params: Interface::Function::Params) -> void
|
207
|
+
end
|
208
|
+
|
201
209
|
attr_reader node: Parser::AST::Node
|
202
210
|
|
203
211
|
attr_reader arguments: Array[Parser::AST::Node]
|
@@ -216,14 +224,16 @@ module Steep
|
|
216
224
|
|
217
225
|
def kwargs_node: () -> Parser::AST::Node?
|
218
226
|
|
227
|
+
def forwarded_args_node: () -> Parser::AST::Node?
|
228
|
+
|
219
229
|
def positional_arg: () -> PositionalArgs
|
220
230
|
|
221
231
|
def keyword_args: () -> KeywordArgs
|
222
232
|
|
223
233
|
def block_pass_arg: () -> BlockPassArg
|
224
234
|
|
225
|
-
def each: () { (PositionalArgs::arg | KeywordArgs::arg) -> void } -> Array[Diagnostic::Ruby::Base]
|
226
|
-
| () -> Enumerator[PositionalArgs::arg | KeywordArgs::arg, Array[Diagnostic::Ruby::Base]]
|
235
|
+
def each: () { (PositionalArgs::arg | KeywordArgs::arg) -> void } -> [ForwardedArgs?, Array[Diagnostic::Ruby::Base]]
|
236
|
+
| () -> Enumerator[PositionalArgs::arg | KeywordArgs::arg, [ForwardedArgs?, Array[Diagnostic::Ruby::Base]]]
|
227
237
|
end
|
228
238
|
end
|
229
239
|
end
|