steep 1.1.1 → 1.2.0.pre.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +20 -0
  3. data/Gemfile +0 -1
  4. data/Gemfile.lock +12 -11
  5. data/Gemfile.steep +1 -1
  6. data/Gemfile.steep.lock +9 -9
  7. data/README.md +3 -3
  8. data/Steepfile +23 -0
  9. data/bin/steep-prof +2 -1
  10. data/lib/steep/annotation_parser.rb +1 -1
  11. data/lib/steep/ast/types/class.rb +4 -0
  12. data/lib/steep/ast/types/factory.rb +86 -602
  13. data/lib/steep/ast/types/instance.rb +4 -0
  14. data/lib/steep/ast/types/literal.rb +1 -1
  15. data/lib/steep/ast/types/proc.rb +22 -8
  16. data/lib/steep/ast/types/self.rb +4 -0
  17. data/lib/steep/ast/types/union.rb +1 -1
  18. data/lib/steep/cli.rb +24 -1
  19. data/lib/steep/diagnostic/ruby.rb +17 -22
  20. data/lib/steep/drivers/checkfile.rb +205 -0
  21. data/lib/steep/drivers/validate.rb +3 -1
  22. data/lib/steep/equatable.rb +2 -0
  23. data/lib/steep/interface/block.rb +21 -11
  24. data/lib/steep/interface/builder.rb +756 -0
  25. data/lib/steep/interface/function.rb +32 -24
  26. data/lib/steep/interface/method_type.rb +191 -78
  27. data/lib/steep/interface/shape.rb +132 -0
  28. data/lib/steep/interface/substitution.rb +23 -12
  29. data/lib/steep/interface/type_param.rb +1 -2
  30. data/lib/steep/path_helper.rb +1 -1
  31. data/lib/steep/project.rb +5 -7
  32. data/lib/steep/server/base_worker.rb +2 -2
  33. data/lib/steep/server/change_buffer.rb +4 -3
  34. data/lib/steep/server/interaction_worker.rb +1 -1
  35. data/lib/steep/server/master.rb +69 -9
  36. data/lib/steep/server/type_check_worker.rb +13 -11
  37. data/lib/steep/server/worker_process.rb +9 -7
  38. data/lib/steep/services/completion_provider.rb +15 -3
  39. data/lib/steep/services/hover_provider/singleton_methods.rb +5 -6
  40. data/lib/steep/services/signature_service.rb +13 -8
  41. data/lib/steep/services/type_check_service.rb +2 -0
  42. data/lib/steep/signature/validator.rb +1 -1
  43. data/lib/steep/subtyping/check.rb +154 -103
  44. data/lib/steep/subtyping/relation.rb +3 -3
  45. data/lib/steep/subtyping/result.rb +20 -2
  46. data/lib/steep/subtyping/variable_variance.rb +9 -0
  47. data/lib/steep/type_construction.rb +558 -299
  48. data/lib/steep/type_inference/block_params.rb +169 -86
  49. data/lib/steep/type_inference/logic_type_interpreter.rb +9 -14
  50. data/lib/steep/type_inference/method_params.rb +12 -7
  51. data/lib/steep/type_inference/send_args.rb +41 -35
  52. data/lib/steep/type_inference/type_env_builder.rb +1 -1
  53. data/lib/steep/version.rb +1 -1
  54. data/lib/steep.rb +71 -2
  55. data/rbs_collection.steep.lock.yaml +18 -30
  56. data/rbs_collection.steep.yaml +1 -0
  57. data/sig/shims/language-server_protocol.rbs +20 -0
  58. data/sig/shims/tagged_logging.rbs +6 -0
  59. data/sig/steep/ast/annotation/collection.rbs +6 -6
  60. data/sig/steep/ast/types/class.rbs +3 -0
  61. data/sig/steep/ast/types/factory.rbs +38 -32
  62. data/sig/steep/ast/types/instance.rbs +3 -0
  63. data/sig/steep/ast/types/intersection.rbs +1 -1
  64. data/sig/steep/ast/types/literal.rbs +7 -7
  65. data/sig/steep/ast/types/name.rbs +14 -13
  66. data/sig/steep/ast/types/proc.rbs +3 -1
  67. data/sig/steep/ast/types/self.rbs +3 -0
  68. data/sig/steep/ast/types/var.rbs +1 -1
  69. data/sig/steep/diagnostic/ruby.rbs +30 -34
  70. data/sig/steep/drivers/annotations.rbs +17 -0
  71. data/sig/steep/drivers/check.rbs +33 -0
  72. data/sig/steep/drivers/checkfile.rbs +26 -0
  73. data/sig/steep/drivers/diagnostic_printer.rbs +25 -0
  74. data/sig/steep/drivers/init.rbs +19 -0
  75. data/sig/steep/drivers/langserver.rbs +35 -0
  76. data/sig/steep/drivers/print_project.rbs +15 -0
  77. data/sig/steep/drivers/stats.rbs +37 -0
  78. data/sig/steep/drivers/utils/driver_helper.rbs +23 -0
  79. data/sig/steep/drivers/utils/jobs_count.rbs +11 -0
  80. data/sig/steep/drivers/validate.rbs +15 -0
  81. data/sig/steep/drivers/vendor.rbs +19 -0
  82. data/sig/steep/drivers/watch.rbs +27 -0
  83. data/sig/steep/drivers/worker.rbs +31 -0
  84. data/sig/steep/equatable.rbs +11 -0
  85. data/sig/steep/index/rbs_index.rbs +91 -0
  86. data/sig/steep/index/signature_symbol_provider.rbs +29 -0
  87. data/sig/steep/index/source_index.rbs +63 -0
  88. data/sig/steep/interface/block.rbs +3 -1
  89. data/sig/steep/interface/builder.rbs +152 -0
  90. data/sig/steep/interface/function.rbs +67 -55
  91. data/sig/steep/interface/method_type.rbs +60 -12
  92. data/sig/steep/interface/shape.rbs +61 -0
  93. data/sig/steep/interface/substitution.rbs +18 -22
  94. data/sig/steep/interface/type_param.rbs +9 -1
  95. data/sig/steep/path_helper.rbs +7 -0
  96. data/sig/steep/project/pattern.rbs +10 -10
  97. data/sig/steep/project/target.rbs +2 -2
  98. data/sig/steep/project.rbs +15 -8
  99. data/sig/steep/server/base_worker.rbs +49 -0
  100. data/sig/steep/server/change_buffer.rbs +32 -0
  101. data/sig/steep/server/interaction_worker.rbs +41 -0
  102. data/sig/steep/server/lsp_formatter.rbs +29 -0
  103. data/sig/steep/server/master.rbs +260 -0
  104. data/sig/steep/server/type_check_worker.rbs +135 -0
  105. data/sig/steep/server/worker_process.rbs +29 -0
  106. data/sig/steep/services/completion_provider.rbs +5 -5
  107. data/sig/steep/services/content_change.rbs +14 -12
  108. data/sig/steep/services/file_loader.rbs +12 -4
  109. data/sig/steep/services/hover_provider/singleton_methods.rbs +1 -1
  110. data/sig/steep/services/path_assignment.rbs +7 -7
  111. data/sig/steep/services/signature_service.rbs +67 -40
  112. data/sig/steep/services/type_check_service.rbs +53 -39
  113. data/sig/steep/subtyping/check.rbs +80 -44
  114. data/sig/steep/subtyping/relation.rbs +24 -22
  115. data/sig/steep/subtyping/result.rbs +48 -30
  116. data/sig/steep/subtyping/variable_variance.rbs +2 -0
  117. data/sig/steep/type_construction.rbs +132 -23
  118. data/sig/steep/type_inference/block_params.rbs +120 -18
  119. data/sig/steep/type_inference/context.rbs +45 -20
  120. data/sig/steep/type_inference/context_array.rbs +37 -0
  121. data/sig/steep/type_inference/logic_type_interpreter.rbs +3 -1
  122. data/sig/steep/type_inference/method_params.rbs +13 -9
  123. data/sig/steep/type_inference/send_args.rbs +229 -0
  124. data/sig/steep/type_inference/type_env_builder.rbs +1 -1
  125. data/sig/steep/typing.rbs +4 -4
  126. data/sig/steep.rbs +4 -2
  127. data/smoke/block/e.rb +12 -0
  128. data/smoke/block/e.rbs +4 -0
  129. data/smoke/block/test_expectations.yml +12 -0
  130. data/smoke/regression/block_param_split.rb +7 -0
  131. data/smoke/regression/block_param_split.rbs +3 -0
  132. data/smoke/regression/empty_yield.rb +5 -0
  133. data/smoke/regression/empty_yield.rbs +3 -0
  134. data/smoke/regression/test_expectations.yml +12 -0
  135. data/smoke/yield/test_expectations.yml +4 -4
  136. data/steep.gemspec +2 -1
  137. metadata +61 -9
  138. data/lib/steep/interface/interface.rb +0 -34
  139. data/sig/steep/interface/interface.rbs +0 -23
  140. data/sig/version.rbs +0 -3
@@ -0,0 +1,152 @@
1
+ module Steep
2
+ module Interface
3
+ class Builder
4
+ class Config
5
+ # Type of `self` type included immediately in the type expression
6
+ #
7
+ attr_reader self_type: AST::Types::t
8
+
9
+ # Type of `class` type included immediately in the type expression
10
+ #
11
+ attr_reader class_type: AST::Types::t | nil
12
+
13
+ # Type of `instance` type included immediately in the type expression
14
+ #
15
+ attr_reader instance_type: AST::Types::t | nil
16
+
17
+ # Resolves `self` types included in shape members
18
+ #
19
+ # * `false` only when the type expression is `self`
20
+ #
21
+ attr_reader resolve_self: bool
22
+
23
+ # Resolves `class` types included in shape members
24
+ #
25
+ # * `false` only when the type expression is `class`
26
+ #
27
+ attr_reader resolve_class: bool
28
+
29
+ # Resolves `instance` types included in shape members
30
+ #
31
+ # * `false` only when the type expression is `instance`
32
+ #
33
+ attr_reader resolve_instance: bool
34
+
35
+ attr_reader variable_bounds: Hash[Symbol, AST::Types::t?]
36
+
37
+ def initialize: (
38
+ self_type: AST::Types::t,
39
+ class_type: AST::Types::t | nil,
40
+ instance_type: AST::Types::t | nil,
41
+ ?resolve_self: bool,
42
+ ?resolve_class: bool,
43
+ ?resolve_instance: bool,
44
+ variable_bounds: Hash[Symbol, AST::Types::t?]
45
+ ) -> void
46
+
47
+ def update: (
48
+ ?self_type: AST::Types::t,
49
+ ?class_type: AST::Types::t | nil,
50
+ ?instance_type: AST::Types::t | nil,
51
+ ?resolve_self: bool,
52
+ ?resolve_class: bool,
53
+ ?resolve_instance: bool,
54
+ ?variable_bounds: Hash[Symbol, AST::Types::t?]
55
+ ) -> self
56
+
57
+ @no_resolve: self?
58
+ def no_resolve: () -> self
59
+
60
+ def resolve?: () -> bool
61
+
62
+ def ==: (untyped) -> bool
63
+
64
+ alias eql? ==
65
+
66
+ def hash: () -> Integer
67
+
68
+ @subst: Substitution
69
+
70
+ # Substitution for immediate type expressions
71
+ def subst: () -> Substitution
72
+ end
73
+
74
+ attr_reader factory: AST::Types::Factory
75
+
76
+ type cache_key = [
77
+ AST::Types::t, # type
78
+ bool, # public_only
79
+ AST::Types::t | nil, # self_type
80
+ AST::Types::t | nil, # class_type
81
+ AST::Types::t | nil, # instance_type
82
+ bool, bool, bool, # resolve_self, resolve_class, resolve_instance
83
+ Hash[Symbol, AST::Types::t?]? # variable_bounds
84
+ ]
85
+ attr_reader cache: Hash[cache_key, Shape?]
86
+
87
+ # No type application (if generic), no self-instance-module resolution
88
+ attr_reader raw_instance_object_shape_cache: Hash[[RBS::TypeName, bool], Shape]
89
+
90
+ attr_reader raw_singleton_object_shape_cache: Hash[[RBS::TypeName, bool], Shape]
91
+
92
+ attr_reader raw_interface_object_shape_cache: Hash[[RBS::TypeName, bool], Shape]
93
+
94
+ def initialize: (AST::Types::Factory) -> void
95
+
96
+ # Calculates the shape of given class, based on `public_only` and Config
97
+ #
98
+ # Returns `nil` if a type that cannot calculate Shape is given.
99
+ #
100
+ # * `public_only`: If false, returns a shape with private methods.
101
+ #
102
+ def shape: (AST::Types::t, public_only: bool, config: Config) -> Shape?
103
+
104
+ private
105
+
106
+ @subtyping: Subtyping::Check?
107
+
108
+ def subtyping: () -> Subtyping::Check
109
+
110
+ # Fetch and update cache
111
+ #
112
+ # Cache if given type is cacheable:
113
+ #
114
+ # * `self`, `instance`, `class` is not cacheable
115
+ # * Type variables are not cacheable
116
+ #
117
+ def fetch_cache: (AST::Types::t, bool public_only, Config) { () -> Shape? } -> Shape?
118
+
119
+ def include_self?: (AST::Types::t) -> bool
120
+
121
+ def definition_builder: () -> RBS::DefinitionBuilder
122
+
123
+ def object_shape: (
124
+ AST::Types::Name::Instance | AST::Types::Name::Singleton | AST::Types::Name::Interface,
125
+ bool public_only,
126
+ boolish keep_self,
127
+ boolish keep_instance,
128
+ boolish keep_singleton
129
+ ) -> Shape
130
+
131
+ def raw_object_shape: (
132
+ AST::Types::Name::Instance | AST::Types::Name::Singleton | AST::Types::Name::Interface,
133
+ bool public_only,
134
+ Substitution subst
135
+ ) -> Shape
136
+
137
+ def union_shape: (AST::Types::t, Array[Shape], bool public_only) -> Shape
138
+
139
+ def intersection_shape: (AST::Types::t, Array[Shape], bool public_only) -> Shape
140
+
141
+ def tuple_shape: (AST::Types::Tuple, bool public_only, Config) -> Shape
142
+
143
+ def record_shape: (AST::Types::Record, bool public_only, Config) -> Shape?
144
+
145
+ def proc_shape: (AST::Types::Proc, bool public_only, Config) -> Shape?
146
+
147
+ def replace_primitive_method: (method_name, RBS::Definition::Method::TypeDef, MethodType) -> MethodType
148
+
149
+ def method_name_for: (RBS::Definition::Method::TypeDef, Symbol name) -> method_name
150
+ end
151
+ end
152
+ end
@@ -8,23 +8,25 @@ module Steep
8
8
  def intersection: (*AST::Types::t types) -> AST::Types::t
9
9
  end
10
10
 
11
+ type t = PositionalParams::param | KeywordParams
12
+
11
13
  class PositionalParams
12
14
  class Base
13
- attr_reader type: untyped
15
+ attr_reader type: AST::Types::t
14
16
 
15
- def initialize: (untyped `type`) -> void
17
+ def initialize: (AST::Types::t `type`) -> void
16
18
 
17
- def ==: (untyped other) -> untyped
19
+ def ==: (untyped other) -> bool
18
20
 
19
21
  alias eql? ==
20
22
 
21
- def hash: () -> untyped
23
+ def hash: () -> Integer
22
24
 
23
- def subst: (untyped s) -> untyped
25
+ def subst: (Substitution s) -> self
24
26
 
25
- def var_type: () -> untyped
27
+ def var_type: () -> AST::Types::t
26
28
 
27
- def map_type: () { (untyped) -> untyped } -> untyped
29
+ def map_type: () { (AST::Types::t) -> AST::Types::t } -> self
28
30
  end
29
31
 
30
32
  class Required < Base
@@ -36,61 +38,65 @@ module Steep
36
38
  class Rest < Base
37
39
  end
38
40
 
39
- attr_reader head: untyped
41
+ type param = Required | Optional | Rest
40
42
 
41
- attr_reader tail: untyped
43
+ attr_reader head: param
42
44
 
43
- def initialize: (head: untyped, tail: untyped) -> void
45
+ attr_reader tail: PositionalParams?
44
46
 
45
- def self.required: (untyped `type`, ?untyped? tail) -> untyped
47
+ def initialize: (head: param, tail: PositionalParams?) -> void
46
48
 
47
- def self.optional: (untyped `type`, ?untyped? tail) -> untyped
49
+ def self.required: (AST::Types::t `type`, ?PositionalParams? tail) -> PositionalParams
48
50
 
49
- def self.rest: (untyped `type`, ?untyped? tail) -> untyped
51
+ def self.optional: (AST::Types::t `type`, ?PositionalParams? tail) -> PositionalParams
50
52
 
51
- def to_ary: () -> ::Array[untyped]
53
+ def self.rest: (AST::Types::t `type`, ?PositionalParams? tail) -> PositionalParams
52
54
 
53
- def map: () { (untyped) -> untyped } -> untyped
55
+ def to_ary: () -> [param, PositionalParams?]
54
56
 
55
- def map_type: () { () -> untyped } -> untyped
57
+ def map: () { (param) -> param } -> PositionalParams
56
58
 
57
- def subst: (untyped s) -> untyped
59
+ def map_type: () { (AST::Types::t) -> AST::Types::t } -> PositionalParams
58
60
 
59
- def ==: (untyped other) -> untyped
61
+ def subst: (Substitution s) -> PositionalParams
62
+
63
+ def ==: (untyped other) -> bool
60
64
 
61
65
  alias eql? ==
62
66
 
63
- def hash: () -> untyped
67
+ def hash: () -> Integer
64
68
 
65
- def each: () { (untyped) -> untyped } -> untyped
69
+ def each: () { (param) -> void } -> void
70
+ | () -> Enumerator[param, void]
66
71
 
67
- def each_type: () { (untyped) -> untyped } -> untyped
72
+ def each_type: () { (AST::Types::t) -> void } -> void
73
+ | () -> Enumerator[AST::Types::t, void]
68
74
 
69
- def size: () -> untyped
75
+ def size: () -> Integer
70
76
 
71
- def self.build: (required: untyped, optional: untyped, rest: untyped) -> untyped
77
+ def self.build: (required: Array[AST::Types::t], optional: Array[AST::Types::t], rest: AST::Types::t?) -> PositionalParams
72
78
 
73
79
  extend Utils
74
80
 
75
81
  # Calculates xs + ys.
76
82
  # Never fails.
77
- def self.merge_for_overload: (untyped xs, untyped ys) -> untyped
83
+ def self.merge_for_overload: (PositionalParams? xs, PositionalParams? ys) -> PositionalParams
78
84
 
79
85
  # xs | ys
80
- def self.merge_for_union: (untyped xs, untyped ys) -> untyped
86
+ def self.merge_for_union: (PositionalParams? xs, PositionalParams? ys) -> PositionalParams?
81
87
 
82
88
  # Calculates xs & ys.
83
89
  # Raises when failed.
84
90
  #
85
- def self.merge_for_intersection: (untyped xs, untyped ys) -> untyped
91
+ def self.merge_for_intersection: (PositionalParams? xs, PositionalParams? ys) -> PositionalParams?
86
92
  end
87
93
 
88
94
  class KeywordParams
89
- attr_reader requireds: untyped
95
+ attr_reader requireds: Hash[Symbol, AST::Types::t]
90
96
 
91
- attr_reader optionals: untyped
97
+ attr_reader optionals: Hash[Symbol, AST::Types::t]
92
98
 
93
- attr_reader rest: untyped
99
+ attr_reader rest: AST::Types::t?
94
100
 
95
101
  def initialize: (?requireds: ::Hash[untyped, untyped], ?optionals: ::Hash[untyped, untyped], ?rest: untyped?) -> void
96
102
 
@@ -102,19 +108,21 @@ module Steep
102
108
 
103
109
  def update: (?requireds: untyped, ?optionals: untyped, ?rest: untyped) -> untyped
104
110
 
105
- def empty?: () -> untyped
111
+ def empty?: () -> bool
106
112
 
107
- def each: () { (untyped, untyped) -> untyped } -> untyped
113
+ def each: () { ([Symbol?, AST::Types::t]) -> void } -> void
114
+ | () -> Enumerator[[Symbol?, AST::Types::t], void]
108
115
 
109
- def each_type: () { (untyped) -> untyped } -> untyped
116
+ def each_type: () { (AST::Types::t) -> void } -> void
117
+ | () -> Enumerator[AST::Types::t, void]
110
118
 
111
- def map_type: () { () -> untyped } -> untyped
119
+ def map_type: () { (AST::Types::t) -> AST::Types::t } -> KeywordParams
112
120
 
113
- def subst: (untyped s) -> untyped
121
+ def subst: (Substitution s) -> KeywordParams
114
122
 
115
- def size: () -> untyped
123
+ def size: () -> Integer
116
124
 
117
- def keywords: () -> untyped
125
+ def keywords: () -> Set[Symbol]
118
126
 
119
127
  include Utils
120
128
 
@@ -134,7 +142,7 @@ module Steep
134
142
 
135
143
  def rest: () -> AST::Types::t?
136
144
 
137
- attr_reader positional_params: PositionalParams
145
+ attr_reader positional_params: PositionalParams?
138
146
 
139
147
  attr_reader keyword_params: KeywordParams
140
148
 
@@ -170,34 +178,35 @@ module Steep
170
178
 
171
179
  def has_keywords?: () -> untyped
172
180
 
173
- def each_positional_param: () { () -> untyped } -> (untyped | nil | untyped)
181
+ def each_positional_param: () { (PositionalParams::Base) -> void } -> void
174
182
 
175
183
  def without_keywords: () -> untyped
176
184
 
177
185
  def drop_first: () -> untyped
178
186
 
179
- def each_type: () { () -> untyped } -> untyped
187
+ def each_type: () { (AST::Types::t) -> void } -> void
188
+ | () -> Enumerator[AST::Types::t, void]
180
189
 
181
190
  def free_variables: () -> untyped
182
191
 
183
192
  def closed?: () -> untyped
184
193
 
185
- def subst: (untyped s) -> untyped
194
+ def subst: (Substitution s) -> Params
186
195
 
187
196
  def size: () -> untyped
188
197
 
189
198
  def to_s: () -> ::String
190
199
 
191
- def map_type: () { () -> untyped } -> untyped
200
+ def map_type: () { (AST::Types::t) -> AST::Types::t } -> Params
192
201
 
193
- def empty?: () -> untyped
202
+ def empty?: () -> bool
194
203
 
195
204
  # Returns true if all arguments are non-required.
196
- def optional?: () -> untyped
205
+ def optional?: () -> bool
197
206
 
198
207
  # self + params returns a new params for overloading.
199
208
  #
200
- def +: (untyped other) -> untyped
209
+ def +: (Params other) -> Params
201
210
 
202
211
  # Returns the intersection between self and other.
203
212
  # Returns nil if the intersection cannot be computed.
@@ -207,7 +216,7 @@ module Steep
207
216
  #
208
217
  # `self & other` accept `arg` if `arg` is acceptable for both of `self` and `other`.
209
218
  #
210
- def &: (untyped other) -> (nil | untyped)
219
+ def &: (Params other) -> Params?
211
220
 
212
221
  # Returns the union between self and other.
213
222
  #
@@ -216,34 +225,37 @@ module Steep
216
225
  #
217
226
  # `self | other` accept `arg` if `self` accepts `arg` or `other` accepts `arg`.
218
227
  #
219
- def |: (untyped other) -> (nil | untyped)
228
+ def |: (Params other) -> Params?
220
229
  end
221
230
 
222
- attr_reader params: untyped
231
+ type location = RBS::Location[untyped, untyped]
232
+
233
+ attr_reader params: Params
223
234
 
224
235
  attr_reader return_type: AST::Types::t
225
236
 
226
- attr_reader location: untyped
237
+ attr_reader location: location?
227
238
 
228
- def initialize: (params: untyped, return_type: untyped, location: untyped) -> void
239
+ def initialize: (params: Params, return_type: AST::Types::t, location: location?) -> void
229
240
 
230
- def ==: (untyped other) -> untyped
241
+ def ==: (untyped other) -> bool
231
242
 
232
243
  alias eql? ==
233
244
 
234
- def hash: () -> untyped
245
+ def hash: () -> Integer
235
246
 
236
247
  def free_variables: () -> Set[Symbol]
237
248
 
238
249
  def subst: (Substitution s) -> Function
239
250
 
240
- def each_child: () { () -> untyped } -> untyped
251
+ alias each_child each_type
241
252
 
242
- def each_type: () { (untyped) -> untyped } -> untyped
253
+ def each_type: () { (AST::Types::t) -> void } -> void
254
+ | () -> Enumerator[AST::Types::t, void]
243
255
 
244
- def map_type: () { (untyped) -> untyped } -> untyped
256
+ def map_type: () { (AST::Types::t) -> AST::Types::t } -> Function
245
257
 
246
- def with: (?params: untyped, ?return_type: untyped) -> untyped
258
+ def with: (?params: Params, ?return_type: AST::Types::t) -> Function
247
259
 
248
260
  def to_s: () -> ::String
249
261
 
@@ -5,13 +5,15 @@ module Steep
5
5
 
6
6
  attr_reader type: Function
7
7
 
8
- attr_reader block: Block
8
+ attr_reader block: Block?
9
9
 
10
- attr_reader method_decls: untyped
10
+ attr_reader method_decls: Set[TypeInference::MethodCall::MethodDecl]
11
11
 
12
- def initialize: (type_params: untyped, type: untyped, block: untyped, method_decls: untyped) -> void
12
+ @fvs: Set[Symbol]
13
13
 
14
- def ==: (untyped other) -> untyped
14
+ def initialize: (type_params: Array[TypeParam], type: Function, block: Block?, method_decls: Set[TypeInference::MethodCall::MethodDecl]) -> void
15
+
16
+ def ==: (untyped other) -> bool
15
17
 
16
18
  alias eql? ==
17
19
 
@@ -21,11 +23,12 @@ module Steep
21
23
 
22
24
  def subst: (Substitution s) -> MethodType
23
25
 
24
- def each_type: () { (untyped) -> untyped } -> untyped
26
+ def each_type: () { (AST::Types::t) -> void } -> void
27
+ | () -> Enumerator[AST::Types::t, void]
25
28
 
26
29
  def instantiate: (Substitution s) -> MethodType
27
30
 
28
- def with: (?type_params: untyped, ?type: untyped, ?block: untyped, ?method_decls: untyped) -> MethodType
31
+ def with: (?type_params: Array[TypeParam], ?type: Function, ?block: Block?, ?method_decls: Set[TypeInference::MethodCall::MethodDecl]) -> MethodType
29
32
 
30
33
  def to_s: () -> ::String
31
34
 
@@ -33,23 +36,68 @@ module Steep
33
36
 
34
37
  # Returns a new method type which can be used for the method implementation type of both `self` and `other`.
35
38
  #
36
- def unify_overload: (untyped other) -> untyped
39
+ def unify_overload: (MethodType other) -> MethodType
40
+
41
+ alias + unify_overload
42
+
43
+ def equals_modulo_type_params?: (MethodType other) -> bool
44
+
45
+ # Returns a method type which is a super-type of both `type1` and `type2`.
46
+ # `type1` <: union(`type1`, `type2`) && `type2` <: union(`type1`, `type2`)
47
+ #
48
+ # Returns `nil` if `type1` and `type2` are incompatible.
49
+ #
50
+ # This tries to generate the best result for polymorphic methods, but the support is limited.
51
+ # It works when:
52
+ #
53
+ # * `type1` and `type2` are equal modulo type parameters (`[A] () -> A` | `[B] () -> B` → `[A] () -> A`), or
54
+ # * The type parameter occurences are identical (`[A] (::Integer) -> A` | `[B] (::String) -> B` → `[A] (::Integer & ::String) -> A`)
55
+ #
56
+ # Otherwise it fails (returns `nil`).
57
+ #
58
+ def self.union: (MethodType type1, MethodType type2, Subtyping::Check) -> MethodType?
59
+
60
+ # Returns a method type which is a sub-type of both `type1` and `type2`.
61
+ #
62
+ # ```
63
+ # intersection(type1, type2) <: type1 && intersection(type1, type2) <: type2
64
+ # ```
65
+ #
66
+ # Returns `nil` if `type1` and `type2` are incompatible.
67
+ #
68
+ # This tries to generate the best result for polymorphic methods, but the support is limited.
69
+ # It works when:
70
+ #
71
+ # * `type1` and `type2` are equal modulo type parameters (`[A] () -> A` & `[B] () -> B` → `[A] () -> A`), or
72
+ # * The type parameter occurences are identical (`[A] (::Integer) -> A` & `[B] (::String) -> B` → `[A] (::Integer | ::String) -> A`)
73
+ #
74
+ # Otherwise it fails (returns `nil`).
75
+ #
76
+ def self.intersection: (MethodType type1, MethodType type2, Subtyping::Check) -> MethodType?
37
77
 
38
- def +: (untyped other) -> untyped
78
+ def self.try_type_params: (
79
+ MethodType type1,
80
+ MethodType type2,
81
+ Subtyping::Check,
82
+ ^(MethodType, MethodType) -> MethodType?,
83
+ ^(MethodType original, MethodType generated) -> Subtyping::Relation[MethodType]
84
+ ) -> MethodType?
39
85
 
40
86
  # Returns a method type which is a super-type of both self and other.
41
87
  # self <: (self | other) && other <: (self | other)
42
88
  #
43
- # Returns nil if self and other are incompatible.
89
+ # * Returns `nil` if self and other are incompatible.
90
+ # * Ignores all type parameters.
44
91
  #
45
- def |: (untyped other) -> (nil | untyped)
92
+ def |: (MethodType other) -> MethodType?
46
93
 
47
94
  # Returns a method type which is a sub-type of both self and other.
48
95
  # (self & other) <: self && (self & other) <: other
49
96
  #
50
- # Returns nil if self and other are incompatible.
97
+ # * Returns `nil` if self and other are incompatible.
98
+ # * Ignores all type parameters.
51
99
  #
52
- def &: (untyped other) -> (nil | untyped)
100
+ def &: (MethodType other) -> MethodType?
53
101
  end
54
102
  end
55
103
  end
@@ -0,0 +1,61 @@
1
+ module Steep
2
+ module Interface
3
+ class Shape
4
+ class Entry
5
+ attr_reader method_types: Array[MethodType]
6
+
7
+ def initialize: (method_types: Array[MethodType]) -> void
8
+
9
+ def to_s: () -> String
10
+ end
11
+
12
+ class Methods
13
+ def []=: (Symbol, Entry) -> Entry
14
+
15
+ def []: (Symbol) -> Entry?
16
+
17
+ def key?: (Symbol) -> bool
18
+
19
+ def each: () { ([Symbol, Entry]) -> void } -> void
20
+ | () -> Enumerator[[Symbol, Entry], void]
21
+
22
+ def each_name: () { (Symbol) -> void } -> void
23
+ | () -> Enumerator[Symbol, void]
24
+
25
+ include Enumerable[[Symbol, Entry]]
26
+
27
+ attr_reader substs: Array[Substitution]
28
+
29
+ attr_reader methods: Hash[Symbol, Entry]
30
+ attr_reader resolved_methods: Hash[Symbol, Entry?]
31
+
32
+ def initialize: (substs: Array[Substitution], methods: Hash[Symbol, Entry]) -> void
33
+
34
+ @subst: Substitution?
35
+ def subst: () -> Substitution
36
+
37
+ def push_substitution: (Substitution) -> Methods
38
+
39
+ def merge!: (Methods other) -> void
40
+
41
+ # def +: (Methods other) -> Methods
42
+ end
43
+
44
+ attr_reader type: AST::Types::t
45
+
46
+ attr_reader methods: Methods
47
+
48
+ @private: bool
49
+
50
+ def initialize: (type: AST::Types::t, private: bool, ?methods: Methods?) -> void
51
+
52
+ def update: (?type: AST::Types::t, ?methods: Methods) -> self
53
+
54
+ def private?: () -> bool
55
+
56
+ def public?: () -> bool
57
+
58
+ def subst: (Substitution, ?type: AST::Types::t?) -> Shape
59
+ end
60
+ end
61
+ end
@@ -9,45 +9,41 @@ module Steep
9
9
  def initialize: (vars_size: untyped, types_size: untyped) -> void
10
10
  end
11
11
 
12
- attr_reader dictionary: untyped
12
+ attr_reader dictionary: Hash[Symbol, AST::Types::t]
13
13
 
14
- attr_reader instance_type: untyped
14
+ attr_reader instance_type: AST::Types::t
15
15
 
16
- attr_reader module_type: untyped
16
+ attr_reader module_type: AST::Types::t
17
17
 
18
- attr_reader self_type: untyped
18
+ attr_reader self_type: AST::Types::t
19
19
 
20
- def initialize: (dictionary: untyped, instance_type: untyped, module_type: untyped, self_type: untyped) -> void
20
+ def initialize: (dictionary: Hash[Symbol, AST::Types::t], instance_type: AST::Types::t, module_type: AST::Types::t, self_type: AST::Types::t) -> void
21
21
 
22
- def self.empty: () -> untyped
22
+ def self.empty: () -> instance
23
23
 
24
- def empty?: () -> untyped
24
+ def empty?: () -> bool
25
25
 
26
- INSTANCE_TYPE: untyped
27
-
28
- CLASS_TYPE: untyped
29
-
30
- SELF_TYPE: untyped
31
-
32
- def domain: () -> untyped
26
+ def domain: () -> Set[AST::Types::t | Symbol]
33
27
 
34
28
  def to_s: () -> ::String
35
29
 
36
- def []: (untyped key) -> untyped
30
+ def []: (Symbol key) -> AST::Types::t
31
+
32
+ def key?: (Symbol var) -> bool
37
33
 
38
- def key?: (untyped var) -> untyped
34
+ def self.build: (Array[Symbol] vars, ?Array[AST::Types::t]? types, ?instance_type: AST::Types::t, ?module_type: AST::Types::t, ?self_type: AST::Types::t) -> Substitution
39
35
 
40
- def self.build: (untyped vars, ?untyped? types, ?instance_type: untyped, ?module_type: untyped, ?self_type: untyped) -> Substitution
36
+ def except: (Array[Symbol] vars) -> Substitution
41
37
 
42
- def except: (untyped vars) -> untyped
38
+ def except!: (Array[Symbol] vars) -> self
43
39
 
44
- def except!: (untyped vars) -> self
40
+ def merge!: (Substitution s, ?overwrite: bool) -> self
45
41
 
46
- def merge!: (untyped s, ?overwrite: bool) -> self
42
+ def merge: (Substitution s) -> Substitution
47
43
 
48
- def merge: (untyped s) -> untyped
44
+ def apply?: (AST::Types::t) -> bool
49
45
 
50
- def add!: (untyped v, untyped ty) -> untyped
46
+ def add!: (Symbol v, AST::Types::t ty) -> self
51
47
  end
52
48
  end
53
49
  end
@@ -23,7 +23,15 @@ module Steep
23
23
 
24
24
  def hash: () -> Integer
25
25
 
26
- def self.rename: (Array[TypeParam] params, ?Array[Symbol] conflicting_names) -> [Array[TypeParam], Substitution]
26
+ # Rename the type parameters to fresh names
27
+ #
28
+ # Returns a pair of renamed type parameters and substitution.
29
+ #
30
+ # ```rb
31
+ # TypeParam.rename([`X`, `Y`], [:X, :Y]) # [[`X(0)`, `Y(1)`], `{ X => X(0), Y => Y(1) }`]
32
+ # ```
33
+ #
34
+ def self.rename: (Array[TypeParam] params, ?Array[Symbol] conflicting_names, ?Array[Symbol] new_names) -> [Array[TypeParam], Substitution]
27
35
 
28
36
  def to_s: () -> String
29
37
 
@@ -0,0 +1,7 @@
1
+ module Steep
2
+ module PathHelper
3
+ def self?.to_pathname: (String uri, ?dosish: bool) -> Pathname?
4
+
5
+ def self?.to_uri: (Pathname path, ?dosish: bool) -> URI::File
6
+ end
7
+ end