steep 1.0.0 → 1.1.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/.github/workflows/ruby-windows.yml +34 -0
- data/.github/workflows/ruby.yml +7 -2
- data/.gitignore +1 -0
- data/CHANGELOG.md +59 -0
- data/Gemfile +7 -4
- data/Gemfile.lock +17 -21
- data/Gemfile.steep +3 -0
- data/Gemfile.steep.lock +49 -0
- data/Rakefile +5 -0
- data/Steepfile +6 -1
- data/bin/setup +2 -0
- data/bin/steep +19 -0
- data/lib/steep/ast/builtin.rb +2 -2
- data/lib/steep/ast/types/factory.rb +7 -3
- data/lib/steep/ast/types/proc.rb +2 -0
- data/lib/steep/cli.rb +3 -1
- data/lib/steep/diagnostic/ruby.rb +50 -4
- data/lib/steep/diagnostic/signature.rb +18 -0
- data/lib/steep/drivers/check.rb +3 -3
- data/lib/steep/drivers/watch.rb +3 -1
- data/lib/steep/method_name.rb +9 -3
- data/lib/steep/node_helper.rb +49 -0
- data/lib/steep/path_helper.rb +22 -0
- data/lib/steep/project.rb +3 -15
- data/lib/steep/server/base_worker.rb +1 -0
- data/lib/steep/server/change_buffer.rb +1 -1
- data/lib/steep/server/interaction_worker.rb +3 -5
- data/lib/steep/server/master.rb +61 -45
- data/lib/steep/server/type_check_worker.rb +10 -25
- data/lib/steep/services/completion_provider.rb +25 -18
- data/lib/steep/services/goto_service.rb +2 -4
- data/lib/steep/services/hover_provider/rbs.rb +1 -1
- data/lib/steep/services/hover_provider/ruby.rb +30 -12
- data/lib/steep/services/stats_calculator.rb +0 -1
- data/lib/steep/services/type_check_service.rb +15 -12
- data/lib/steep/shims/symbol_start_with.rb +18 -0
- data/lib/steep/signature/validator.rb +25 -1
- data/lib/steep/source.rb +1 -1
- data/lib/steep/subtyping/check.rb +0 -3
- data/lib/steep/subtyping/constraints.rb +43 -14
- data/lib/steep/type_construction.rb +721 -764
- data/lib/steep/type_inference/constant_env.rb +0 -2
- data/lib/steep/type_inference/context.rb +23 -17
- data/lib/steep/type_inference/logic_type_interpreter.rb +210 -117
- data/lib/steep/type_inference/method_call.rb +80 -6
- data/lib/steep/type_inference/multiple_assignment.rb +189 -0
- data/lib/steep/type_inference/send_args.rb +1 -2
- data/lib/steep/type_inference/type_env.rb +273 -116
- data/lib/steep/type_inference/type_env_builder.rb +138 -0
- data/lib/steep/typing.rb +2 -0
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +7 -5
- data/rbs_collection.steep.lock.yaml +112 -0
- data/rbs_collection.steep.yaml +19 -0
- data/sample/sig/conference.rbs +8 -0
- data/sig/shims/parser/source/map.rbs +146 -0
- data/sig/shims/parser/source/range.rbs +237 -0
- data/sig/shims/parser.rbs +17 -0
- data/sig/steep/ast/annotation/collection.rbs +75 -0
- data/sig/steep/ast/annotation.rbs +126 -0
- data/sig/steep/ast/builtin.rbs +69 -0
- data/sig/steep/ast/type_params.rbs +11 -0
- data/sig/steep/ast/types/any.rbs +29 -0
- data/sig/steep/ast/types/boolean.rbs +31 -0
- data/sig/steep/ast/types/bot.rbs +29 -0
- data/sig/steep/ast/types/class.rbs +29 -0
- data/sig/steep/ast/types/factory.rbs +76 -0
- data/sig/steep/ast/types/helper.rbs +19 -0
- data/sig/steep/ast/types/instance.rbs +29 -0
- data/sig/steep/ast/types/intersection.rbs +35 -0
- data/sig/steep/ast/types/literal.rbs +33 -0
- data/sig/steep/ast/types/logic.rbs +78 -0
- data/sig/steep/ast/types/name.rbs +71 -0
- data/sig/steep/ast/types/nil.rbs +31 -0
- data/sig/steep/ast/types/proc.rbs +46 -0
- data/sig/steep/ast/types/record.rbs +38 -0
- data/sig/steep/ast/types/self.rbs +29 -0
- data/sig/steep/ast/types/top.rbs +29 -0
- data/sig/steep/ast/types/tuple.rbs +34 -0
- data/sig/steep/ast/types/union.rbs +38 -0
- data/sig/steep/ast/types/var.rbs +37 -0
- data/sig/steep/ast/types/void.rbs +29 -0
- data/sig/steep/ast/types.rbs +37 -0
- data/sig/steep/diagnostic/deprecated/unknown_constant_assigned.rbs +15 -0
- data/sig/steep/diagnostic/helper.rbs +9 -0
- data/sig/steep/diagnostic/lsp_formatter.rbs +29 -0
- data/sig/steep/diagnostic/ruby.rbs +494 -0
- data/sig/steep/diagnostic/signature.rbs +215 -0
- data/sig/steep/interface/block.rbs +35 -0
- data/sig/steep/interface/function.rbs +253 -0
- data/sig/steep/interface/interface.rbs +23 -0
- data/sig/steep/interface/method_type.rbs +55 -0
- data/sig/steep/interface/substitution.rbs +53 -0
- data/sig/steep/interface/type_param.rbs +35 -0
- data/sig/steep/method_name.rbs +26 -0
- data/sig/steep/module_helper.rbs +7 -0
- data/sig/steep/node_helper.rbs +11 -0
- data/sig/steep/project/dsl.rbs +94 -0
- data/sig/steep/project/options.rbs +15 -0
- data/sig/steep/project/pattern.rbs +25 -0
- data/sig/steep/project/target.rbs +25 -0
- data/sig/steep/project.rbs +19 -0
- data/sig/steep/services/completion_provider.rbs +123 -0
- data/sig/steep/services/content_change.rbs +35 -0
- data/sig/steep/services/file_loader.rbs +13 -0
- data/sig/steep/services/goto_service.rbs +45 -0
- data/sig/steep/services/hover_provider/rbs.rbs +21 -0
- data/sig/steep/services/hover_provider/ruby.rbs +109 -0
- data/sig/steep/services/hover_provider/singleton_methods.rbs +11 -0
- data/sig/steep/services/path_assignment.rbs +21 -0
- data/sig/steep/services/signature_service.rbs +91 -0
- data/sig/steep/services/stats_calculator.rbs +17 -0
- data/sig/steep/services/type_check_service.rbs +93 -0
- data/sig/steep/source.rbs +55 -0
- data/sig/steep/subtyping/cache.rbs +17 -0
- data/sig/steep/subtyping/check.rbs +93 -0
- data/sig/steep/subtyping/constraints.rbs +111 -0
- data/sig/steep/subtyping/relation.rbs +51 -0
- data/sig/steep/subtyping/result.rbs +157 -0
- data/sig/steep/subtyping/variable_variance.rbs +23 -0
- data/sig/steep/type_construction.rbs +285 -0
- data/sig/steep/type_inference/block_params.rbs +52 -0
- data/sig/steep/type_inference/constant_env.rbs +27 -0
- data/sig/steep/type_inference/context.rbs +137 -0
- data/sig/steep/type_inference/logic_type_interpreter.rbs +72 -0
- data/sig/steep/type_inference/method_call.rbs +124 -0
- data/sig/steep/type_inference/method_params.rbs +104 -0
- data/sig/steep/type_inference/multiple_assignment.rbs +76 -0
- data/sig/steep/type_inference/type_env.rbs +158 -0
- data/sig/steep/type_inference/type_env_builder.rbs +77 -0
- data/sig/steep/typing.rbs +68 -0
- data/sig/steep.rbs +31 -0
- data/smoke/class/f.rb +1 -0
- data/smoke/class/test_expectations.yml +2 -2
- data/smoke/diagnostics/test_expectations.yml +4 -2
- data/smoke/regression/lambda.rb +3 -0
- data/smoke/regression/test_expectations.yml +12 -0
- data/steep.gemspec +1 -1
- metadata +95 -9
- data/lib/steep/subtyping/variable_occurrence.rb +0 -51
- data/lib/steep/type_inference/local_variable_type_env.rb +0 -249
- data/lib/steep/type_inference/logic.rb +0 -161
@@ -0,0 +1,104 @@
|
|
1
|
+
module Steep
|
2
|
+
module TypeInference
|
3
|
+
class MethodParams
|
4
|
+
class BaseParameter
|
5
|
+
attr_reader name: Symbol
|
6
|
+
|
7
|
+
attr_reader type: untyped
|
8
|
+
|
9
|
+
attr_reader node: Parser::AST::Node
|
10
|
+
|
11
|
+
def initialize: (name: Symbol, type: untyped, node: Parser::AST::Node) -> void
|
12
|
+
|
13
|
+
def optional?: () -> bool
|
14
|
+
|
15
|
+
def value: () -> Parser::AST::Node
|
16
|
+
|
17
|
+
def var_type: () -> AST::Types::t
|
18
|
+
|
19
|
+
def untyped?: () -> bool
|
20
|
+
|
21
|
+
def ==: (untyped other) -> untyped
|
22
|
+
|
23
|
+
alias eql? ==
|
24
|
+
|
25
|
+
def hash: () -> Integer
|
26
|
+
end
|
27
|
+
|
28
|
+
class PositionalParameter < BaseParameter
|
29
|
+
end
|
30
|
+
|
31
|
+
class KeywordParameter < BaseParameter
|
32
|
+
end
|
33
|
+
|
34
|
+
class BaseRestParameter
|
35
|
+
attr_reader name: Symbol
|
36
|
+
|
37
|
+
attr_reader type: untyped
|
38
|
+
|
39
|
+
attr_reader node: Parser::AST::Node
|
40
|
+
|
41
|
+
def initialize: (name: Symbol, type: untyped, node: Parser::AST::Node) -> void
|
42
|
+
|
43
|
+
def ==: (untyped other) -> bool
|
44
|
+
|
45
|
+
alias eql? ==
|
46
|
+
|
47
|
+
def hash: () -> Integer
|
48
|
+
|
49
|
+
def var_type: () -> AST::Types::t
|
50
|
+
end
|
51
|
+
|
52
|
+
class PositionalRestParameter < BaseRestParameter
|
53
|
+
def var_type: () -> AST::Types::t
|
54
|
+
end
|
55
|
+
|
56
|
+
class KeywordRestParameter < BaseRestParameter
|
57
|
+
def var_type: () -> AST::Types::t
|
58
|
+
end
|
59
|
+
|
60
|
+
class BlockParameter
|
61
|
+
attr_reader name: untyped
|
62
|
+
|
63
|
+
attr_reader type: untyped
|
64
|
+
|
65
|
+
attr_reader node: untyped
|
66
|
+
|
67
|
+
def initialize: (name: untyped, type: untyped, node: untyped, optional: untyped) -> void
|
68
|
+
|
69
|
+
def optional?: () -> (true | false)
|
70
|
+
|
71
|
+
def var_type: () -> AST::Types::t
|
72
|
+
|
73
|
+
def ==: (untyped other) -> untyped
|
74
|
+
|
75
|
+
alias eql? ==
|
76
|
+
|
77
|
+
def hash: () -> untyped
|
78
|
+
end
|
79
|
+
|
80
|
+
attr_reader args: untyped
|
81
|
+
|
82
|
+
attr_reader method_type: untyped
|
83
|
+
|
84
|
+
attr_reader params: untyped
|
85
|
+
|
86
|
+
attr_reader errors: untyped
|
87
|
+
|
88
|
+
def initialize: (args: untyped, method_type: untyped) -> void
|
89
|
+
|
90
|
+
def []: (untyped name) -> untyped
|
91
|
+
|
92
|
+
def size: () -> Integer
|
93
|
+
|
94
|
+
def each_param: () { (BaseParameter | BaseRestParameter | BlockParameter) -> void } -> void
|
95
|
+
| () -> Enumerator[BaseParameter | BaseRestParameter | BlockParameter, void]
|
96
|
+
|
97
|
+
def each: () { (Symbol, BaseRestParameter | BaseRestParameter | BlockParameter) -> void } -> void
|
98
|
+
|
99
|
+
def self.empty: (node: Parser::AST::Node) -> MethodParams
|
100
|
+
|
101
|
+
def self.build: (node: Parser::AST::Node, method_type: untyped) -> MethodParams
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module Steep
|
2
|
+
module TypeInference
|
3
|
+
# This class provides an abstraction for multiple assignments.
|
4
|
+
#
|
5
|
+
class MultipleAssignment
|
6
|
+
type node_type_pair = [Parser::AST::Node, AST::Types::t]
|
7
|
+
|
8
|
+
# Encapsulate assignments included in one `masgn` node
|
9
|
+
#
|
10
|
+
# ```ruby
|
11
|
+
# a, *b, c = rhs
|
12
|
+
# # ^ Leading assignments
|
13
|
+
# # ^^ Splat assignment
|
14
|
+
# # ^ Trailing assignments
|
15
|
+
# ```
|
16
|
+
#
|
17
|
+
class Assignments
|
18
|
+
attr_reader rhs_type: AST::Types::t
|
19
|
+
|
20
|
+
attr_reader optional: bool
|
21
|
+
|
22
|
+
# Assignments before `*` assignment
|
23
|
+
attr_reader leading_assignments: Array[node_type_pair]
|
24
|
+
|
25
|
+
# Assignments after `*` assignment
|
26
|
+
#
|
27
|
+
# Empty if there is no splat assignment.
|
28
|
+
#
|
29
|
+
attr_reader trailing_assignments: Array[node_type_pair]
|
30
|
+
|
31
|
+
# Splat assignment if present
|
32
|
+
attr_reader splat_assignment: node_type_pair?
|
33
|
+
|
34
|
+
def initialize: (
|
35
|
+
rhs_type: AST::Types::t,
|
36
|
+
optional: bool,
|
37
|
+
leading_assignments: Array[node_type_pair],
|
38
|
+
trailing_assignments: Array[node_type_pair],
|
39
|
+
splat_assignment: node_type_pair?
|
40
|
+
) -> void
|
41
|
+
|
42
|
+
def each: () { (node_type_pair) -> void } -> void
|
43
|
+
| () -> Enumerator[node_type_pair, void]
|
44
|
+
end
|
45
|
+
|
46
|
+
def initialize: () -> void
|
47
|
+
|
48
|
+
# Receives multiple assignment left hand side, right hand side type, and `optional` flag, and returns Assignments object
|
49
|
+
#
|
50
|
+
# This implements a case analysis on `rhs_type`:
|
51
|
+
#
|
52
|
+
# 1. If `rhs_type` is tuple, it returns an Assignments object with corresponding assignments
|
53
|
+
# 2. If `rhs_type` is an array, it returns an Assignments object with corresponding assignments
|
54
|
+
# 3. If `rhs_type` is `untyped`, it returns an Assignments with `untyped` type
|
55
|
+
# 4. It returns `nil` otherwise
|
56
|
+
#
|
57
|
+
def expand: (Parser::AST::Node mlhs, AST::Types::t rhs_type, bool optional) -> Assignments?
|
58
|
+
|
59
|
+
# Returns a type hint for multiple assignment right hand side
|
60
|
+
#
|
61
|
+
# It constructs a structure of tuple types, based on the assignment lhs, and variable types.
|
62
|
+
#
|
63
|
+
def hint_for_mlhs: (Parser::AST::Node mlhs, TypeEnv env) -> AST::Types::t?
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def expand_tuple: (Array[Parser::AST::Node] assignments, AST::Types::t rhs_type, Array[AST::Types::t] types, bool optional) -> Assignments
|
68
|
+
|
69
|
+
def expand_array: (Array[Parser::AST::Node] assignments, AST::Types::Name::Instance rhs_type, bool optional) -> Assignments
|
70
|
+
|
71
|
+
def expand_any: (Array[Parser::AST::Node] assignments, AST::Types::t rhs_type, AST::Types::t element_type, bool optional) -> Assignments
|
72
|
+
|
73
|
+
def expand_else: (Array[Parser::AST::Node] assignments, AST::Types::t rhs_type, bool optional) -> Assignments
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,158 @@
|
|
1
|
+
module Steep
|
2
|
+
module TypeInference
|
3
|
+
# TypeEnv is the one-stop class to manage type of variables.
|
4
|
+
#
|
5
|
+
# ### Local variables primitive operations
|
6
|
+
#
|
7
|
+
# * Assigning to a local variable
|
8
|
+
# * Adding local variable type enforcement
|
9
|
+
# * Refine local variable types
|
10
|
+
# * Resetting refinements
|
11
|
+
#
|
12
|
+
# ### Pure calls primitive operations
|
13
|
+
#
|
14
|
+
# * Adding pure calls
|
15
|
+
# * Removing pure calls
|
16
|
+
# * Refine pure call types
|
17
|
+
# * Resetting pure call refinements
|
18
|
+
#
|
19
|
+
# ### Branch operations
|
20
|
+
#
|
21
|
+
# * Start branching with refinements
|
22
|
+
# * Merge branches
|
23
|
+
#
|
24
|
+
#
|
25
|
+
class TypeEnv
|
26
|
+
include NodeHelper
|
27
|
+
|
28
|
+
type local_variable_entry = [AST::Types::t, AST::Types::t?]
|
29
|
+
|
30
|
+
attr_reader local_variable_types: Hash[Symbol, local_variable_entry]
|
31
|
+
|
32
|
+
attr_reader pure_method_calls: Hash[Parser::AST::Node, [MethodCall::Typed, AST::Types::t?]]
|
33
|
+
|
34
|
+
attr_reader instance_variable_types: Hash[Symbol, AST::Types::t]
|
35
|
+
|
36
|
+
attr_reader global_types: Hash[Symbol, AST::Types::t]
|
37
|
+
|
38
|
+
attr_reader constant_types: Hash[RBS::TypeName, AST::Types::t]
|
39
|
+
|
40
|
+
attr_reader constant_env: ConstantEnv
|
41
|
+
|
42
|
+
@pure_node_descendants: Hash[Parser::AST::Node, Set[Parser::AST::Node]]
|
43
|
+
|
44
|
+
def initialize: (
|
45
|
+
ConstantEnv,
|
46
|
+
?local_variable_types: Hash[Symbol, local_variable_entry],
|
47
|
+
?instance_variable_types: Hash[Symbol, AST::Types::t],
|
48
|
+
?global_types: Hash[Symbol, AST::Types::t],
|
49
|
+
?constant_types: Hash[RBS::TypeName, AST::Types::t],
|
50
|
+
?pure_method_calls: Hash[Parser::AST::Node, [MethodCall::Typed, AST::Types::t?]]
|
51
|
+
) -> void
|
52
|
+
|
53
|
+
def update: (
|
54
|
+
?local_variable_types: Hash[Symbol, local_variable_entry],
|
55
|
+
?instance_variable_types: Hash[Symbol, AST::Types::t],
|
56
|
+
?global_types: Hash[Symbol, AST::Types::t],
|
57
|
+
?constant_types: Hash[RBS::TypeName, AST::Types::t],
|
58
|
+
?pure_method_calls: Hash[Parser::AST::Node, [MethodCall::Typed, AST::Types::t?]]
|
59
|
+
) -> TypeEnv
|
60
|
+
|
61
|
+
def merge: (
|
62
|
+
?local_variable_types: Hash[Symbol, local_variable_entry],
|
63
|
+
?instance_variable_types: Hash[Symbol, AST::Types::t],
|
64
|
+
?global_types: Hash[Symbol, AST::Types::t],
|
65
|
+
?constant_types: Hash[RBS::TypeName, AST::Types::t],
|
66
|
+
?pure_method_calls: Hash[Parser::AST::Node, [MethodCall::Typed, AST::Types::t?]]
|
67
|
+
) -> TypeEnv
|
68
|
+
|
69
|
+
# Returns type of `name`.
|
70
|
+
#
|
71
|
+
def []: (Symbol name) -> AST::Types::t?
|
72
|
+
| (Parser::AST::Node node) -> AST::Types::t?
|
73
|
+
|
74
|
+
# Tells the environment that local variables are updated.
|
75
|
+
# Keeps their enforced types and invalidates related nodes.
|
76
|
+
#
|
77
|
+
def assign_local_variables: (Hash[Symbol, AST::Types::t]) -> TypeEnv
|
78
|
+
|
79
|
+
# Tells the environment that the local variable is updated with it's enforced type.
|
80
|
+
#
|
81
|
+
# Invalidates related nodes.
|
82
|
+
#
|
83
|
+
def assign_local_variable: (Symbol name, AST::Types::t type, AST::Types::t? enforced_type) -> TypeEnv
|
84
|
+
|
85
|
+
# Refines types of local variables and pure calls.
|
86
|
+
#
|
87
|
+
# * Receives types of updated local variables and pure calls.
|
88
|
+
# * The local variable types will be
|
89
|
+
#
|
90
|
+
def refine_types: (?local_variable_types: Hash[Symbol, AST::Types::t], ?pure_call_types: Hash[Parser::AST::Node, AST::Types::t]) -> TypeEnv
|
91
|
+
|
92
|
+
def enforced_type: (Symbol name) -> AST::Types::t?
|
93
|
+
|
94
|
+
# Returns type of constant of `const_name`, or `const_name` under `mod_name`.
|
95
|
+
#
|
96
|
+
# Returns `nil` if no such constant found.
|
97
|
+
#
|
98
|
+
def constant: (Symbol const_name, bool toplevel) -> ConstantEnv::constant_tuple?
|
99
|
+
| (RBS::TypeName mod_name, Symbol const_name) -> ConstantEnv::constant_tuple?
|
100
|
+
|
101
|
+
def annotated_constant: (RBS::TypeName) -> AST::Types::t?
|
102
|
+
|
103
|
+
# _Pin_ the local variables if array is given.
|
104
|
+
# When `nil` is given, all local variables are _pinned_.
|
105
|
+
#
|
106
|
+
def pin_local_variables: (Array[Symbol]? names) -> Hash[Symbol, local_variable_entry]
|
107
|
+
|
108
|
+
# _Unpin_ the local variables if array is given.
|
109
|
+
# When `nil` is given, all local variables are _unpinned_.
|
110
|
+
#
|
111
|
+
def unpin_local_variables: (Array[Symbol]? names) -> TypeEnv
|
112
|
+
|
113
|
+
def to_s: () -> String
|
114
|
+
|
115
|
+
# Apply the substitution to the type of local variables.
|
116
|
+
#
|
117
|
+
def subst: (Interface::Substitution) -> TypeEnv
|
118
|
+
|
119
|
+
# Returns a `TypeEnv` such that:
|
120
|
+
#
|
121
|
+
# * All of the given environments are result of the type checking of branches from `self`,
|
122
|
+
# * All of the branches meet at one point, with the returned `TypeEnv`
|
123
|
+
#
|
124
|
+
# See the example below:
|
125
|
+
#
|
126
|
+
# ```ruby
|
127
|
+
# if foo() # The original environment `self` is for after the evaluation of `foo()`
|
128
|
+
# a = bar() # One environment `env1` can be given from after the evaluation of `bar()`
|
129
|
+
# else
|
130
|
+
# b = baz() # Another environment `env2` is from after the evaluation of `baz`
|
131
|
+
# end
|
132
|
+
#
|
133
|
+
# ??? # How is the environment for here is `self.merge(env1, env2)`
|
134
|
+
# # The environment has both optional types of `a` and `b`
|
135
|
+
# ```
|
136
|
+
#
|
137
|
+
def join: (*TypeEnv) -> TypeEnv
|
138
|
+
|
139
|
+
def add_pure_call: (Parser::AST::Node, MethodCall::Typed, AST::Types::t?) -> TypeEnv
|
140
|
+
|
141
|
+
def replace_pure_call_type: (Parser::AST::Node, AST::Types::t) -> TypeEnv
|
142
|
+
|
143
|
+
def invalidate_pure_node: (Parser::AST::Node) -> TypeEnv
|
144
|
+
|
145
|
+
private
|
146
|
+
|
147
|
+
def pure_node_invalidation: (Enumerable[Parser::AST::Node] invalidated_nodes) -> Hash[Parser::AST::Node, [MethodCall::Typed, AST::Types::t?]]
|
148
|
+
|
149
|
+
def invalidated_pure_nodes: (Parser::AST::Node) -> Set[Parser::AST::Node]
|
150
|
+
|
151
|
+
def local_variable_name?: (Symbol) -> bool
|
152
|
+
|
153
|
+
def instance_variable_name?: (Symbol) -> bool
|
154
|
+
|
155
|
+
def global_name?: (Symbol) -> bool
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
@@ -0,0 +1,77 @@
|
|
1
|
+
module Steep
|
2
|
+
module TypeInference
|
3
|
+
class TypeEnvBuilder
|
4
|
+
module Command
|
5
|
+
interface _Base
|
6
|
+
def call: (TypeEnv) -> TypeEnv
|
7
|
+
end
|
8
|
+
|
9
|
+
class RBSBase
|
10
|
+
attr_reader environment: RBS::Environment
|
11
|
+
|
12
|
+
attr_reader factory: AST::Types::Factory
|
13
|
+
|
14
|
+
def initialize: (AST::Types::Factory) -> void
|
15
|
+
end
|
16
|
+
|
17
|
+
class AnnotationsBase
|
18
|
+
attr_reader annotations: AST::Annotation::Collection
|
19
|
+
|
20
|
+
def initialize: (AST::Annotation::Collection) -> void
|
21
|
+
end
|
22
|
+
|
23
|
+
# Insert local variable annotations.
|
24
|
+
#
|
25
|
+
# * When _merge mode_ is on, adds and overwrite local variables.
|
26
|
+
# * When _merge mode_ is off, it wipes all existing local variables and adds from annotations.
|
27
|
+
#
|
28
|
+
class ImportLocalVariableAnnotations < AnnotationsBase
|
29
|
+
include _Base
|
30
|
+
|
31
|
+
attr_reader on_duplicate: (^(Symbol, AST::Types::t, AST::Types::t) -> void)?
|
32
|
+
|
33
|
+
@merge: bool
|
34
|
+
|
35
|
+
# Set _merge mode_ `on`.
|
36
|
+
def merge!: (?bool) -> self
|
37
|
+
|
38
|
+
def on_duplicate!: () { (Symbol name, AST::Types::t original, AST::Types::t annotation) -> void } -> self
|
39
|
+
end
|
40
|
+
|
41
|
+
# Insert global variable types into type environment from `RBS::Environment`.
|
42
|
+
#
|
43
|
+
class ImportGlobalDeclarations < RBSBase
|
44
|
+
def merge!: (?bool) -> self
|
45
|
+
|
46
|
+
@merge: bool
|
47
|
+
|
48
|
+
include _Base
|
49
|
+
end
|
50
|
+
|
51
|
+
class ImportInstanceVariableAnnotations < AnnotationsBase
|
52
|
+
include _Base
|
53
|
+
end
|
54
|
+
|
55
|
+
class ImportInstanceVariableDefinition
|
56
|
+
attr_reader definition: RBS::Definition?
|
57
|
+
|
58
|
+
attr_reader factory: AST::Types::Factory
|
59
|
+
|
60
|
+
def initialize: (RBS::Definition?, AST::Types::Factory) -> void
|
61
|
+
|
62
|
+
include _Base
|
63
|
+
end
|
64
|
+
|
65
|
+
class ImportConstantAnnotations < AnnotationsBase
|
66
|
+
include _Base
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
attr_reader commands: Array[Command::_Base]
|
71
|
+
|
72
|
+
def initialize: (*Command::_Base) -> void
|
73
|
+
|
74
|
+
def build: (TypeEnv) -> TypeEnv
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Steep
|
2
|
+
class Typing
|
3
|
+
class UnknownNodeError < StandardError
|
4
|
+
attr_reader op: untyped
|
5
|
+
|
6
|
+
attr_reader node: untyped
|
7
|
+
|
8
|
+
def initialize: (untyped op, node: untyped) -> void
|
9
|
+
end
|
10
|
+
|
11
|
+
attr_reader source: Source
|
12
|
+
|
13
|
+
attr_reader errors: untyped
|
14
|
+
|
15
|
+
attr_reader typing: untyped
|
16
|
+
|
17
|
+
attr_reader parent: untyped
|
18
|
+
|
19
|
+
attr_reader parent_last_update: untyped
|
20
|
+
|
21
|
+
attr_reader last_update: untyped
|
22
|
+
|
23
|
+
attr_reader should_update: untyped
|
24
|
+
|
25
|
+
attr_reader contexts: untyped
|
26
|
+
|
27
|
+
attr_reader root_context: untyped
|
28
|
+
|
29
|
+
attr_reader method_calls: untyped
|
30
|
+
|
31
|
+
attr_reader source_index: untyped
|
32
|
+
|
33
|
+
def initialize: (source: untyped, root_context: untyped, ?parent: untyped?, ?parent_last_update: untyped, ?contexts: untyped?, ?source_index: untyped?) -> void
|
34
|
+
|
35
|
+
def add_error: (untyped error) -> untyped
|
36
|
+
|
37
|
+
def add_typing: (Parser::AST::Node node, AST::Types::t `type`, TypeInference::Context _context) -> untyped
|
38
|
+
|
39
|
+
def add_call: (untyped node, untyped call) -> untyped
|
40
|
+
|
41
|
+
def add_context: (Range[Integer] range, context: TypeInference::Context) -> void
|
42
|
+
|
43
|
+
def has_type?: (untyped node) -> untyped
|
44
|
+
|
45
|
+
def type_of: (node: Parser::AST::Node) -> AST::Types::t
|
46
|
+
|
47
|
+
def call_of: (node: untyped) -> untyped
|
48
|
+
|
49
|
+
def add_context_for_node: (untyped node, context: untyped) -> untyped
|
50
|
+
|
51
|
+
def block_range: (untyped node) -> ::Range[untyped]
|
52
|
+
|
53
|
+
def add_context_for_body: (untyped node, context: untyped) -> untyped
|
54
|
+
|
55
|
+
def context_at: (line: Integer, column: Integer) -> TypeInference::Context
|
56
|
+
|
57
|
+
def dump: (untyped io) -> untyped
|
58
|
+
|
59
|
+
def self.summary: (untyped node) -> ::String
|
60
|
+
|
61
|
+
def new_child: [A] (Range[Integer] range) { (Typing) -> A } -> A
|
62
|
+
| (Range[Integer]) -> Typing
|
63
|
+
|
64
|
+
def each_typing: () { () -> untyped } -> untyped
|
65
|
+
|
66
|
+
def save!: () -> void
|
67
|
+
end
|
68
|
+
end
|
data/sig/steep.rbs
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
module Steep
|
2
|
+
def self.logger: () -> Logger
|
3
|
+
|
4
|
+
def self.new_logger: (untyped output, untyped prev_level) -> untyped
|
5
|
+
|
6
|
+
def self.log_output: () -> untyped
|
7
|
+
|
8
|
+
def self.log_output=: (untyped output) -> untyped
|
9
|
+
|
10
|
+
def self.measure: (untyped message, ?level: ::Symbol) { () -> untyped } -> untyped
|
11
|
+
|
12
|
+
def self.log_error: (untyped exn, ?message: ::String) -> untyped
|
13
|
+
|
14
|
+
class Sampler
|
15
|
+
def initialize: () -> void
|
16
|
+
|
17
|
+
def sample: (untyped message) { () -> untyped } -> untyped
|
18
|
+
|
19
|
+
def count: () -> untyped
|
20
|
+
|
21
|
+
def total: () -> untyped
|
22
|
+
|
23
|
+
def slowests: (untyped num) -> untyped
|
24
|
+
|
25
|
+
def average: () -> (untyped | 0)
|
26
|
+
|
27
|
+
def percentile: (untyped p) -> untyped
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.measure2: (untyped message, ?level: ::Symbol) { (untyped) -> untyped } -> untyped
|
31
|
+
end
|
data/smoke/class/f.rb
CHANGED
@@ -489,8 +489,10 @@
|
|
489
489
|
line: 2
|
490
490
|
character: 10
|
491
491
|
severity: ERROR
|
492
|
-
message:
|
493
|
-
|
492
|
+
message: |-
|
493
|
+
Cannot break with a value of type `::Integer` because type `nil` is assumed
|
494
|
+
::Integer <: nil
|
495
|
+
code: Ruby::BreakTypeMismatch
|
494
496
|
- file: unexpected_keyword.rb
|
495
497
|
diagnostics:
|
496
498
|
- range:
|
@@ -40,6 +40,18 @@
|
|
40
40
|
| (::Numeric) -> ::Time
|
41
41
|
| (::Time) -> ::Float
|
42
42
|
code: Ruby::UnresolvedOverloading
|
43
|
+
- file: lambda.rb
|
44
|
+
diagnostics:
|
45
|
+
- range:
|
46
|
+
start:
|
47
|
+
line: 1
|
48
|
+
character: 7
|
49
|
+
end:
|
50
|
+
line: 1
|
51
|
+
character: 10
|
52
|
+
severity: ERROR
|
53
|
+
message: 'Cannot find the declaration of module: `Mod`'
|
54
|
+
code: Ruby::UnknownConstant
|
43
55
|
- file: set_divide.rb
|
44
56
|
diagnostics:
|
45
57
|
- range:
|
data/steep.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
|
29
29
|
spec.required_ruby_version = '>= 2.6.0'
|
30
30
|
|
31
|
-
spec.add_runtime_dependency "parser", ">= 3.
|
31
|
+
spec.add_runtime_dependency "parser", ">= 3.1"
|
32
32
|
spec.add_runtime_dependency "activesupport", ">= 5.1"
|
33
33
|
spec.add_runtime_dependency "rainbow", ">= 2.2.2", "< 4.0"
|
34
34
|
spec.add_runtime_dependency "listen", "~> 3.0"
|