steep 0.37.0 → 0.42.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +1 -1
  3. data/CHANGELOG.md +34 -0
  4. data/Rakefile +5 -2
  5. data/bin/output_rebaseline.rb +34 -0
  6. data/bin/output_test.rb +53 -0
  7. data/lib/steep.rb +95 -14
  8. data/lib/steep/ast/types/bot.rb +1 -1
  9. data/lib/steep/ast/types/class.rb +4 -0
  10. data/lib/steep/ast/types/factory.rb +10 -0
  11. data/lib/steep/ast/types/logic.rb +16 -3
  12. data/lib/steep/ast/types/top.rb +1 -1
  13. data/lib/steep/cli.rb +31 -7
  14. data/lib/steep/diagnostic/helper.rb +17 -0
  15. data/lib/steep/diagnostic/lsp_formatter.rb +16 -0
  16. data/lib/steep/diagnostic/ruby.rb +619 -0
  17. data/lib/steep/diagnostic/signature.rb +357 -0
  18. data/lib/steep/drivers/annotations.rb +19 -28
  19. data/lib/steep/drivers/check.rb +182 -60
  20. data/lib/steep/drivers/diagnostic_printer.rb +99 -0
  21. data/lib/steep/drivers/langserver.rb +3 -8
  22. data/lib/steep/drivers/print_project.rb +10 -9
  23. data/lib/steep/drivers/stats.rb +124 -32
  24. data/lib/steep/drivers/trace_printer.rb +5 -1
  25. data/lib/steep/drivers/utils/jobs_count.rb +9 -0
  26. data/lib/steep/drivers/validate.rb +31 -13
  27. data/lib/steep/drivers/watch.rb +69 -48
  28. data/lib/steep/drivers/worker.rb +16 -8
  29. data/lib/steep/expectations.rb +159 -0
  30. data/lib/steep/index/rbs_index.rb +334 -0
  31. data/lib/steep/index/signature_symbol_provider.rb +162 -0
  32. data/lib/steep/index/source_index.rb +100 -0
  33. data/lib/steep/project.rb +0 -30
  34. data/lib/steep/project/dsl.rb +5 -3
  35. data/lib/steep/project/options.rb +4 -4
  36. data/lib/steep/project/pattern.rb +56 -0
  37. data/lib/steep/project/target.rb +9 -214
  38. data/lib/steep/range_extension.rb +29 -0
  39. data/lib/steep/server/base_worker.rb +43 -7
  40. data/lib/steep/server/change_buffer.rb +63 -0
  41. data/lib/steep/server/interaction_worker.rb +73 -56
  42. data/lib/steep/server/master.rb +245 -109
  43. data/lib/steep/server/type_check_worker.rb +122 -0
  44. data/lib/steep/server/worker_process.rb +17 -15
  45. data/lib/steep/{project → services}/completion_provider.rb +3 -3
  46. data/lib/steep/services/content_change.rb +61 -0
  47. data/lib/steep/services/file_loader.rb +48 -0
  48. data/lib/steep/{project → services}/hover_content.rb +14 -16
  49. data/lib/steep/services/path_assignment.rb +29 -0
  50. data/lib/steep/services/signature_service.rb +369 -0
  51. data/lib/steep/services/stats_calculator.rb +69 -0
  52. data/lib/steep/services/type_check_service.rb +342 -0
  53. data/lib/steep/signature/validator.rb +174 -32
  54. data/lib/steep/subtyping/check.rb +248 -47
  55. data/lib/steep/subtyping/constraints.rb +2 -2
  56. data/lib/steep/type_construction.rb +565 -295
  57. data/lib/steep/type_inference/constant_env.rb +5 -1
  58. data/lib/steep/type_inference/local_variable_type_env.rb +26 -12
  59. data/lib/steep/type_inference/logic_type_interpreter.rb +99 -26
  60. data/lib/steep/type_inference/type_env.rb +43 -17
  61. data/lib/steep/typing.rb +8 -2
  62. data/lib/steep/version.rb +1 -1
  63. data/smoke/alias/a.rb +0 -3
  64. data/smoke/alias/b.rb +0 -1
  65. data/smoke/alias/c.rb +0 -2
  66. data/smoke/alias/test_expectations.yml +96 -0
  67. data/smoke/and/a.rb +0 -3
  68. data/smoke/and/test_expectations.yml +31 -0
  69. data/smoke/array/a.rb +0 -3
  70. data/smoke/array/b.rb +0 -2
  71. data/smoke/array/c.rb +0 -1
  72. data/smoke/array/test_expectations.yml +103 -0
  73. data/smoke/block/a.rb +0 -2
  74. data/smoke/block/b.rb +0 -2
  75. data/smoke/block/d.rb +0 -4
  76. data/smoke/block/test_expectations.yml +125 -0
  77. data/smoke/case/a.rb +0 -3
  78. data/smoke/case/test_expectations.yml +47 -0
  79. data/smoke/class/a.rb +0 -3
  80. data/smoke/class/c.rb +0 -1
  81. data/smoke/class/f.rb +0 -1
  82. data/smoke/class/g.rb +0 -2
  83. data/smoke/class/i.rb +0 -2
  84. data/smoke/class/test_expectations.yml +120 -0
  85. data/smoke/const/a.rb +0 -3
  86. data/smoke/const/b.rb +7 -0
  87. data/smoke/const/b.rbs +5 -0
  88. data/smoke/const/test_expectations.yml +139 -0
  89. data/smoke/diagnostics-rbs-duplicated/Steepfile +5 -0
  90. data/smoke/diagnostics-rbs-duplicated/a.rbs +5 -0
  91. data/smoke/diagnostics-rbs-duplicated/test_expectations.yml +13 -0
  92. data/smoke/diagnostics-rbs/Steepfile +8 -0
  93. data/smoke/diagnostics-rbs/duplicated-method-definition.rbs +20 -0
  94. data/smoke/diagnostics-rbs/generic-parameter-mismatch.rbs +7 -0
  95. data/smoke/diagnostics-rbs/invalid-method-overload.rbs +3 -0
  96. data/smoke/diagnostics-rbs/invalid-type-application.rbs +7 -0
  97. data/smoke/diagnostics-rbs/invalid_variance_annotation.rbs +3 -0
  98. data/smoke/diagnostics-rbs/recursive-alias.rbs +5 -0
  99. data/smoke/diagnostics-rbs/recursive-class.rbs +8 -0
  100. data/smoke/diagnostics-rbs/superclass-mismatch.rbs +7 -0
  101. data/smoke/diagnostics-rbs/test_expectations.yml +231 -0
  102. data/smoke/diagnostics-rbs/unknown-method-alias.rbs +3 -0
  103. data/smoke/diagnostics-rbs/unknown-type-name-2.rbs +5 -0
  104. data/smoke/diagnostics-rbs/unknown-type-name.rbs +13 -0
  105. data/smoke/diagnostics/Steepfile +5 -0
  106. data/smoke/diagnostics/a.rbs +26 -0
  107. data/smoke/diagnostics/argument_type_mismatch.rb +1 -0
  108. data/smoke/diagnostics/block_body_type_mismatch.rb +1 -0
  109. data/smoke/diagnostics/block_type_mismatch.rb +3 -0
  110. data/smoke/diagnostics/break_type_mismatch.rb +1 -0
  111. data/smoke/diagnostics/else_on_exhaustive_case.rb +12 -0
  112. data/smoke/diagnostics/incompatible_annotation.rb +6 -0
  113. data/smoke/diagnostics/incompatible_argument.rb +1 -0
  114. data/smoke/diagnostics/incompatible_assignment.rb +8 -0
  115. data/smoke/diagnostics/method_arity_mismatch.rb +11 -0
  116. data/smoke/diagnostics/method_body_type_mismatch.rb +6 -0
  117. data/smoke/diagnostics/method_definition_missing.rb +2 -0
  118. data/smoke/diagnostics/method_return_type_annotation_mismatch.rb +7 -0
  119. data/smoke/diagnostics/missing_keyword.rb +1 -0
  120. data/smoke/diagnostics/no_method.rb +1 -0
  121. data/smoke/diagnostics/required_block_missing.rb +1 -0
  122. data/smoke/diagnostics/return_type_mismatch.rb +6 -0
  123. data/smoke/diagnostics/test_expectations.yml +477 -0
  124. data/smoke/diagnostics/unexpected_block_given.rb +1 -0
  125. data/smoke/diagnostics/unexpected_dynamic_method.rb +3 -0
  126. data/smoke/diagnostics/unexpected_jump.rb +4 -0
  127. data/smoke/diagnostics/unexpected_jump_value.rb +3 -0
  128. data/smoke/diagnostics/unexpected_keyword.rb +1 -0
  129. data/smoke/diagnostics/unexpected_splat.rb +1 -0
  130. data/smoke/diagnostics/unexpected_yield.rb +6 -0
  131. data/smoke/diagnostics/unknown_constant_assigned.rb +7 -0
  132. data/smoke/diagnostics/unresolved_overloading.rb +1 -0
  133. data/smoke/diagnostics/unsatisfiable_constraint.rb +7 -0
  134. data/smoke/diagnostics/unsupported_syntax.rb +2 -0
  135. data/smoke/dstr/a.rb +0 -1
  136. data/smoke/dstr/test_expectations.yml +13 -0
  137. data/smoke/ensure/a.rb +0 -4
  138. data/smoke/ensure/test_expectations.yml +62 -0
  139. data/smoke/enumerator/a.rb +0 -6
  140. data/smoke/enumerator/b.rb +0 -3
  141. data/smoke/enumerator/test_expectations.yml +135 -0
  142. data/smoke/extension/a.rb +0 -1
  143. data/smoke/extension/b.rb +0 -2
  144. data/smoke/extension/c.rb +0 -1
  145. data/smoke/extension/f.rb +2 -0
  146. data/smoke/extension/f.rbs +3 -0
  147. data/smoke/extension/test_expectations.yml +73 -0
  148. data/smoke/hash/b.rb +0 -1
  149. data/smoke/hash/c.rb +0 -3
  150. data/smoke/hash/d.rb +0 -1
  151. data/smoke/hash/e.rb +0 -1
  152. data/smoke/hash/test_expectations.yml +81 -0
  153. data/smoke/hello/hello.rb +0 -2
  154. data/smoke/hello/test_expectations.yml +25 -0
  155. data/smoke/if/a.rb +0 -2
  156. data/smoke/if/test_expectations.yml +34 -0
  157. data/smoke/implements/a.rb +0 -2
  158. data/smoke/implements/test_expectations.yml +23 -0
  159. data/smoke/initialize/test_expectations.yml +1 -0
  160. data/smoke/integer/a.rb +0 -7
  161. data/smoke/integer/test_expectations.yml +101 -0
  162. data/smoke/interface/a.rb +0 -2
  163. data/smoke/interface/test_expectations.yml +23 -0
  164. data/smoke/kwbegin/a.rb +0 -1
  165. data/smoke/kwbegin/test_expectations.yml +17 -0
  166. data/smoke/lambda/a.rb +1 -4
  167. data/smoke/lambda/test_expectations.yml +39 -0
  168. data/smoke/literal/a.rb +0 -5
  169. data/smoke/literal/b.rb +0 -2
  170. data/smoke/literal/test_expectations.yml +106 -0
  171. data/smoke/map/test_expectations.yml +1 -0
  172. data/smoke/method/a.rb +0 -5
  173. data/smoke/method/b.rb +0 -1
  174. data/smoke/method/test_expectations.yml +90 -0
  175. data/smoke/module/a.rb +0 -2
  176. data/smoke/module/b.rb +0 -2
  177. data/smoke/module/c.rb +0 -1
  178. data/smoke/module/d.rb +0 -1
  179. data/smoke/module/f.rb +0 -2
  180. data/smoke/module/test_expectations.yml +75 -0
  181. data/smoke/regexp/a.rb +0 -38
  182. data/smoke/regexp/b.rb +0 -26
  183. data/smoke/regexp/test_expectations.yml +615 -0
  184. data/smoke/regression/set_divide.rb +0 -4
  185. data/smoke/regression/test_expectations.yml +43 -0
  186. data/smoke/rescue/a.rb +0 -5
  187. data/smoke/rescue/test_expectations.yml +79 -0
  188. data/smoke/self/a.rb +0 -2
  189. data/smoke/self/test_expectations.yml +23 -0
  190. data/smoke/skip/skip.rb +0 -2
  191. data/smoke/skip/test_expectations.yml +23 -0
  192. data/smoke/stdout/test_expectations.yml +1 -0
  193. data/smoke/super/a.rb +0 -4
  194. data/smoke/super/test_expectations.yml +79 -0
  195. data/smoke/toplevel/a.rb +0 -1
  196. data/smoke/toplevel/test_expectations.yml +15 -0
  197. data/smoke/tsort/Steepfile +2 -0
  198. data/smoke/tsort/a.rb +0 -3
  199. data/smoke/tsort/test_expectations.yml +63 -0
  200. data/smoke/type_case/a.rb +0 -4
  201. data/smoke/type_case/test_expectations.yml +48 -0
  202. data/smoke/unexpected/Steepfile +5 -0
  203. data/smoke/unexpected/test_expectations.yml +25 -0
  204. data/smoke/unexpected/unexpected.rb +1 -0
  205. data/smoke/unexpected/unexpected.rbs +3 -0
  206. data/smoke/yield/a.rb +0 -3
  207. data/smoke/yield/b.rb +6 -0
  208. data/smoke/yield/test_expectations.yml +68 -0
  209. data/steep.gemspec +4 -3
  210. metadata +144 -29
  211. data/bin/smoke_runner.rb +0 -139
  212. data/lib/steep/drivers/signature_error_printer.rb +0 -25
  213. data/lib/steep/errors.rb +0 -565
  214. data/lib/steep/project/file_loader.rb +0 -68
  215. data/lib/steep/project/signature_file.rb +0 -33
  216. data/lib/steep/project/source_file.rb +0 -129
  217. data/lib/steep/server/code_worker.rb +0 -137
  218. data/lib/steep/server/signature_worker.rb +0 -152
  219. data/lib/steep/server/utils.rb +0 -69
  220. data/lib/steep/signature/errors.rb +0 -82
  221. data/lib/steep/type_assignability.rb +0 -367
@@ -9,15 +9,30 @@ module Steep
9
9
  @cache = {}
10
10
  end
11
11
 
12
+ def each_ancestor(ancestors, &block)
13
+ if block_given?
14
+ if ancestors.super_class
15
+ yield ancestors.super_class
16
+ end
17
+ ancestors.each_included_module(&block)
18
+ ancestors.each_included_interface(&block)
19
+ ancestors.each_prepended_module(&block)
20
+ ancestors.each_extended_module(&block)
21
+ ancestors.each_extended_interface(&block)
22
+ else
23
+ enum_for :each_ancestor, ancestors
24
+ end
25
+ end
26
+
12
27
  def instance_super_types(type_name, args:)
13
- ancestors = factory.definition_builder.one_instance_ancestors(type_name)
28
+ ancestors = factory.definition_builder.ancestor_builder.one_instance_ancestors(type_name)
14
29
 
15
30
  subst = unless args.empty?
16
31
  args_ = args.map {|type| factory.type_1(type) }
17
32
  RBS::Substitution.build(ancestors.params, args_)
18
33
  end
19
34
 
20
- ancestors.each_ancestor.map do |ancestor|
35
+ each_ancestor(ancestors).map do |ancestor|
21
36
  name = ancestor.name
22
37
 
23
38
  case ancestor
@@ -50,7 +65,7 @@ module Steep
50
65
  end
51
66
 
52
67
  def singleton_super_types(type_name)
53
- ancestors = factory.definition_builder.one_singleton_ancestors(type_name)
68
+ ancestors = factory.definition_builder.ancestor_builder.one_singleton_ancestors(type_name)
54
69
 
55
70
  ancestors.each_ancestor.map do |ancestor|
56
71
  name = ancestor.name
@@ -83,10 +98,10 @@ module Steep
83
98
  end
84
99
  end
85
100
 
86
- def check(relation, constraints:, self_type:, assumption: Set.new, trace: Trace.new)
101
+ def check(relation, constraints:, self_type:, instance_type:, class_type:, assumption: Set.new, trace: Trace.new)
87
102
  Steep.logger.tagged "#{relation.sub_type} <: #{relation.super_type}" do
88
103
  prefix = trace.size
89
- cached = cache[[relation, self_type]]
104
+ cached = cache[[relation, self_type, instance_type, class_type]]
90
105
  if cached && constraints.empty?
91
106
  if cached.success?
92
107
  cached
@@ -98,7 +113,15 @@ module Steep
98
113
  success(constraints: constraints)
99
114
  else
100
115
  assumption = assumption + Set[relation]
101
- check0(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints).tap do |result|
116
+ check0(
117
+ relation,
118
+ self_type: self_type,
119
+ instance_type: instance_type,
120
+ class_type: class_type,
121
+ assumption: assumption,
122
+ trace: trace,
123
+ constraints: constraints
124
+ ).tap do |result|
102
125
  result = result.else do |failure|
103
126
  failure.drop(prefix)
104
127
  end
@@ -145,7 +168,7 @@ module Steep
145
168
  end
146
169
  end
147
170
 
148
- def check0(relation, self_type:, assumption:, trace:, constraints:)
171
+ def check0(relation, self_type:, class_type:, instance_type:, assumption:, trace:, constraints:)
149
172
  # puts relation
150
173
  trace.type(relation.sub_type, relation.super_type) do
151
174
  case
@@ -171,6 +194,8 @@ module Steep
171
194
  check(
172
195
  Relation.new(sub_type: relation.sub_type, super_type: AST::Types::Union.build(types: [AST::Builtin.true_type, AST::Builtin.false_type])),
173
196
  self_type: self_type,
197
+ instance_type: instance_type,
198
+ class_type: class_type,
174
199
  assumption: assumption,
175
200
  trace: trace,
176
201
  constraints: constraints
@@ -181,6 +206,8 @@ module Steep
181
206
  Relation.new(sub_type: AST::Types::Union.build(types: [AST::Builtin.true_type, AST::Builtin.false_type]),
182
207
  super_type: relation.super_type),
183
208
  self_type: self_type,
209
+ instance_type: instance_type,
210
+ class_type: class_type,
184
211
  assumption: assumption,
185
212
  trace: trace,
186
213
  constraints: constraints
@@ -190,15 +217,77 @@ module Steep
190
217
  check(
191
218
  Relation.new(sub_type: self_type, super_type: relation.super_type),
192
219
  self_type: self_type,
220
+ instance_type: instance_type,
221
+ class_type: class_type,
222
+ assumption: assumption,
223
+ trace: trace,
224
+ constraints: constraints
225
+ )
226
+
227
+ when relation.sub_type.is_a?(AST::Types::Instance) && !instance_type.is_a?(AST::Types::Instance)
228
+ check(
229
+ Relation.new(sub_type: instance_type, super_type: relation.super_type),
230
+ self_type: self_type,
231
+ instance_type: instance_type,
232
+ class_type: class_type,
193
233
  assumption: assumption,
194
234
  trace: trace,
195
235
  constraints: constraints
196
236
  )
197
237
 
238
+ when relation.super_type.is_a?(AST::Types::Instance) && !instance_type.is_a?(AST::Types::Instance)
239
+ rel = Relation.new(sub_type: relation.sub_type, super_type: instance_type)
240
+
241
+ success_all?([rel, rel.flip]) do |r|
242
+ check(
243
+ r,
244
+ self_type: self_type,
245
+ instance_type: instance_type,
246
+ class_type: class_type,
247
+ assumption: assumption,
248
+ trace: trace,
249
+ constraints: constraints
250
+ )
251
+ end.then do |result|
252
+ Steep.logger.error { "`T <: instance` doesn't hold generally, but testing it with `#{relation} && #{relation.flip}` for compatibility"}
253
+ result
254
+ end
255
+
256
+ when relation.sub_type.is_a?(AST::Types::Class) && !instance_type.is_a?(AST::Types::Class)
257
+ check(
258
+ Relation.new(sub_type: class_type, super_type: relation.super_type),
259
+ self_type: self_type,
260
+ instance_type: instance_type,
261
+ class_type: class_type,
262
+ assumption: assumption,
263
+ trace: trace,
264
+ constraints: constraints
265
+ )
266
+
267
+ when relation.super_type.is_a?(AST::Types::Class) && !instance_type.is_a?(AST::Types::Class)
268
+ rel = Relation.new(sub_type: relation.sub_type, super_type: class_type)
269
+
270
+ success_all?([rel, rel.flip]) do |r|
271
+ check(
272
+ r,
273
+ self_type: self_type,
274
+ instance_type: instance_type,
275
+ class_type: class_type,
276
+ assumption: assumption,
277
+ trace: trace,
278
+ constraints: constraints
279
+ )
280
+ end.then do |result|
281
+ Steep.logger.error { "`T <: class` doesn't hold generally, but testing with `#{relation} && |- #{relation.flip}` for compatibility"}
282
+ result
283
+ end
284
+
198
285
  when alias?(relation.sub_type)
199
286
  check(
200
287
  Relation.new(sub_type: expand_alias(relation.sub_type), super_type: relation.super_type),
201
288
  self_type: self_type,
289
+ instance_type: instance_type,
290
+ class_type: class_type,
202
291
  assumption: assumption,
203
292
  trace: trace,
204
293
  constraints: constraints
@@ -208,6 +297,8 @@ module Steep
208
297
  check(
209
298
  Relation.new(super_type: expand_alias(relation.super_type), sub_type: relation.sub_type),
210
299
  self_type: self_type,
300
+ instance_type: instance_type,
301
+ class_type: class_type,
211
302
  assumption: assumption,
212
303
  trace: trace,
213
304
  constraints: constraints
@@ -224,10 +315,12 @@ module Steep
224
315
  when relation.sub_type.is_a?(AST::Types::Union)
225
316
  results = relation.sub_type.types.map do |sub_type|
226
317
  check(Relation.new(sub_type: sub_type, super_type: relation.super_type),
227
- self_type: self_type,
228
- assumption: assumption,
229
- trace: trace,
230
- constraints: constraints)
318
+ self_type: self_type,
319
+ instance_type: instance_type,
320
+ class_type: class_type,
321
+ assumption: assumption,
322
+ trace: trace,
323
+ constraints: constraints)
231
324
  end
232
325
 
233
326
  if results.all?(&:success?)
@@ -239,10 +332,12 @@ module Steep
239
332
  when relation.super_type.is_a?(AST::Types::Union)
240
333
  results = relation.super_type.types.map do |super_type|
241
334
  check(Relation.new(sub_type: relation.sub_type, super_type: super_type),
242
- self_type: self_type,
243
- assumption: assumption,
244
- trace: trace,
245
- constraints: constraints)
335
+ self_type: self_type,
336
+ instance_type: instance_type,
337
+ class_type: class_type,
338
+ assumption: assumption,
339
+ trace: trace,
340
+ constraints: constraints)
246
341
  end
247
342
 
248
343
  results.find(&:success?) || results.first
@@ -250,10 +345,12 @@ module Steep
250
345
  when relation.sub_type.is_a?(AST::Types::Intersection)
251
346
  results = relation.sub_type.types.map do |sub_type|
252
347
  check(Relation.new(sub_type: sub_type, super_type: relation.super_type),
253
- self_type: self_type,
254
- assumption: assumption,
255
- trace: trace,
256
- constraints: constraints)
348
+ self_type: self_type,
349
+ instance_type: instance_type,
350
+ class_type: class_type,
351
+ assumption: assumption,
352
+ trace: trace,
353
+ constraints: constraints)
257
354
  end
258
355
 
259
356
  results.find(&:success?) || results.first
@@ -261,10 +358,12 @@ module Steep
261
358
  when relation.super_type.is_a?(AST::Types::Intersection)
262
359
  results = relation.super_type.types.map do |super_type|
263
360
  check(Relation.new(sub_type: relation.sub_type, super_type: super_type),
264
- self_type: self_type,
265
- assumption: assumption,
266
- trace: trace,
267
- constraints: constraints)
361
+ self_type: self_type,
362
+ instance_type: instance_type,
363
+ class_type: class_type,
364
+ assumption: assumption,
365
+ trace: trace,
366
+ constraints: constraints)
268
367
  end
269
368
 
270
369
  if results.all?(&:success?)
@@ -284,6 +383,8 @@ module Steep
284
383
  check_interface(sub_interface,
285
384
  super_interface,
286
385
  self_type: self_type,
386
+ instance_type: instance_type,
387
+ class_type: class_type,
287
388
  assumption: assumption,
288
389
  trace: trace,
289
390
  constraints: constraints)
@@ -291,7 +392,15 @@ module Steep
291
392
  when relation.sub_type.is_a?(AST::Types::Name::Base) && relation.super_type.is_a?(AST::Types::Name::Base)
292
393
  if relation.sub_type.name == relation.super_type.name && relation.sub_type.class == relation.super_type.class
293
394
  if arg_type?(relation.sub_type) && arg_type?(relation.super_type)
294
- check_type_arg(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
395
+ check_type_arg(
396
+ relation,
397
+ self_type: self_type,
398
+ instance_type: instance_type,
399
+ class_type: class_type,
400
+ assumption: assumption,
401
+ trace: trace,
402
+ constraints: constraints
403
+ )
295
404
  else
296
405
  success(constraints: constraints)
297
406
  end
@@ -309,6 +418,8 @@ module Steep
309
418
  success_any?(possible_sub_types) do |sub_type|
310
419
  check(Relation.new(sub_type: sub_type, super_type: relation.super_type),
311
420
  self_type: self_type,
421
+ instance_type: instance_type,
422
+ class_type: class_type,
312
423
  assumption: assumption,
313
424
  trace: trace,
314
425
  constraints: constraints)
@@ -324,12 +435,20 @@ module Steep
324
435
  sub_type = relation.sub_type
325
436
  super_type = relation.super_type
326
437
 
327
- check_method_params(name, sub_type.type.params, super_type.type.params, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints).then do
438
+ check_method_params(name, sub_type.type.params, super_type.type.params, self_type: self_type, instance_type: instance_type, class_type: class_type, assumption: assumption, trace: trace, constraints: constraints).then do
328
439
  check_block_given(name, sub_type.block, super_type.block, trace: trace, constraints: constraints).then do
329
- check_block_params(name, sub_type.block, super_type.block, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints).then do
330
- check_block_return(sub_type.block, super_type.block, self_type: self_type, assumption: assumption, trace: trace, constraints:constraints).then do
440
+ check_block_params(name, sub_type.block, super_type.block, self_type: self_type, instance_type: instance_type, class_type: class_type, assumption: assumption, trace: trace, constraints: constraints).then do
441
+ check_block_return(sub_type.block, super_type.block, self_type: self_type, instance_type: instance_type, class_type: class_type, assumption: assumption, trace: trace, constraints:constraints).then do
331
442
  relation = Relation.new(super_type: super_type.type.return_type, sub_type: sub_type.type.return_type)
332
- check(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
443
+ check(
444
+ relation,
445
+ self_type: self_type,
446
+ instance_type: instance_type,
447
+ class_type: class_type,
448
+ assumption: assumption,
449
+ trace: trace,
450
+ constraints: constraints
451
+ )
333
452
  end
334
453
  end
335
454
  end
@@ -340,7 +459,15 @@ module Steep
340
459
  pairs = relation.sub_type.types.take(relation.super_type.types.size).zip(relation.super_type.types)
341
460
  results = pairs.map do |t1, t2|
342
461
  relation = Relation.new(sub_type: t1, super_type: t2)
343
- check(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
462
+ check(
463
+ relation,
464
+ self_type: self_type,
465
+ instance_type: instance_type,
466
+ class_type: class_type,
467
+ assumption: assumption,
468
+ trace: trace,
469
+ constraints: constraints
470
+ )
344
471
  end
345
472
 
346
473
  if results.all?(&:success?)
@@ -361,6 +488,8 @@ module Steep
361
488
 
362
489
  check(Relation.new(sub_type: tuple_element_type, super_type: relation.super_type.args[0]),
363
490
  self_type: self_type,
491
+ instance_type: instance_type,
492
+ class_type: class_type,
364
493
  assumption: assumption,
365
494
  trace: trace,
366
495
  constraints: constraints)
@@ -374,7 +503,15 @@ module Steep
374
503
  )
375
504
  }
376
505
  results = relations.map do |relation|
377
- check(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
506
+ check(
507
+ relation,
508
+ self_type: self_type,
509
+ instance_type: instance_type,
510
+ class_type: class_type,
511
+ assumption: assumption,
512
+ trace: trace,
513
+ constraints: constraints
514
+ )
378
515
  end
379
516
 
380
517
  if results.all?(&:success?)
@@ -390,6 +527,8 @@ module Steep
390
527
  check_interface(record_interface,
391
528
  type_interface,
392
529
  self_type: self_type,
530
+ instance_type: instance_type,
531
+ class_type: class_type,
393
532
  assumption: assumption,
394
533
  trace: trace,
395
534
  constraints: constraints)
@@ -415,6 +554,8 @@ module Steep
415
554
  check(
416
555
  Relation.new(sub_type: relation.sub_type.back_type, super_type: relation.super_type),
417
556
  self_type: self_type,
557
+ instance_type: instance_type,
558
+ class_type: class_type,
418
559
  assumption: assumption,
419
560
  trace: trace,
420
561
  constraints: constraints
@@ -451,7 +592,7 @@ module Steep
451
592
  end
452
593
  end
453
594
 
454
- def check_type_arg(relation, self_type:, assumption:, trace:, constraints:)
595
+ def check_type_arg(relation, self_type:, instance_type:, class_type:, assumption:, trace:, constraints:)
455
596
  sub_args = relation.sub_type.args
456
597
  sup_args = relation.super_type.args
457
598
 
@@ -461,13 +602,37 @@ module Steep
461
602
  success_all?(sub_args.zip(sup_args, sup_params.each)) do |sub_arg, sup_arg, sup_param|
462
603
  case sup_param.variance
463
604
  when :covariant
464
- check(Relation.new(sub_type: sub_arg, super_type: sup_arg), self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
605
+ check(
606
+ Relation.new(sub_type: sub_arg, super_type: sup_arg),
607
+ self_type: self_type,
608
+ instance_type: instance_type,
609
+ class_type: class_type,
610
+ assumption: assumption,
611
+ trace: trace,
612
+ constraints: constraints
613
+ )
465
614
  when :contravariant
466
- check(Relation.new(sub_type: sup_arg, super_type: sub_arg), self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
615
+ check(
616
+ Relation.new(sub_type: sup_arg, super_type: sub_arg),
617
+ self_type: self_type,
618
+ instance_type: instance_type,
619
+ class_type: class_type,
620
+ assumption: assumption,
621
+ trace: trace,
622
+ constraints: constraints
623
+ )
467
624
  when :invariant
468
625
  rel = Relation.new(sub_type: sub_arg, super_type: sup_arg)
469
626
  success_all?([rel, rel.flip]) do |r|
470
- check(r, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
627
+ check(
628
+ r,
629
+ self_type: self_type,
630
+ instance_type: instance_type,
631
+ class_type: class_type,
632
+ assumption: assumption,
633
+ trace: trace,
634
+ constraints: constraints
635
+ )
471
636
  end
472
637
  end
473
638
  end
@@ -533,7 +698,7 @@ module Steep
533
698
  relation.sub_type == relation.super_type
534
699
  end
535
700
 
536
- def check_interface(sub_interface, super_interface, self_type:, assumption:, trace:, constraints:)
701
+ def check_interface(sub_interface, super_interface, self_type:, instance_type:, class_type:, assumption:, trace:, constraints:)
537
702
  trace.interface sub_interface, super_interface do
538
703
  method_triples = []
539
704
 
@@ -553,6 +718,8 @@ module Steep
553
718
  sub_method,
554
719
  sup_method,
555
720
  self_type: self_type,
721
+ instance_type: instance_type,
722
+ class_type: class_type,
556
723
  assumption: assumption,
557
724
  trace: trace,
558
725
  constraints: constraints)
@@ -563,7 +730,7 @@ module Steep
563
730
  end
564
731
  end
565
732
 
566
- def check_method(name, sub_method, super_method, self_type:, assumption:, trace:, constraints:)
733
+ def check_method(name, sub_method, super_method, self_type:, instance_type:, class_type:, assumption:, trace:, constraints:)
567
734
  trace.method name, sub_method, super_method do
568
735
  super_method.method_types.map do |super_type|
569
736
  sub_method.method_types.map do |sub_type|
@@ -571,6 +738,8 @@ module Steep
571
738
  sub_type,
572
739
  super_type,
573
740
  self_type: self_type,
741
+ instance_type: instance_type,
742
+ class_type: class_type,
574
743
  assumption: assumption,
575
744
  trace: trace,
576
745
  constraints: constraints
@@ -587,7 +756,7 @@ module Steep
587
756
  end
588
757
  end
589
758
 
590
- def check_generic_method_type(name, sub_type, super_type, self_type:, assumption:, trace:, constraints:)
759
+ def check_generic_method_type(name, sub_type, super_type, self_type:, instance_type:, class_type:, assumption:, trace:, constraints:)
591
760
  trace.method_type name, sub_type, super_type do
592
761
  case
593
762
  when sub_type.type_params.empty? && super_type.type_params.empty?
@@ -595,6 +764,8 @@ module Steep
595
764
  sub_type,
596
765
  super_type,
597
766
  self_type: self_type,
767
+ instance_type: instance_type,
768
+ class_type: class_type,
598
769
  assumption: assumption,
599
770
  trace: trace,
600
771
  constraints: constraints
@@ -633,6 +804,8 @@ module Steep
633
804
  sub_type.subst(subst),
634
805
  super_type,
635
806
  self_type: self_type,
807
+ instance_type: instance_type,
808
+ class_type: class_type,
636
809
  assumption: assumption,
637
810
  trace: trace,
638
811
  constraints: constraints)
@@ -657,6 +830,8 @@ module Steep
657
830
  sub_type,
658
831
  super_type,
659
832
  self_type: self_type,
833
+ instance_type: instance_type,
834
+ class_type: class_type,
660
835
  assumption: assumption,
661
836
  trace: trace,
662
837
  constraints: constraints)
@@ -688,6 +863,8 @@ module Steep
688
863
  sub_type_,
689
864
  super_type_,
690
865
  self_type: self_type,
866
+ instance_type: instance_type,
867
+ class_type: class_type,
691
868
  assumption: assumption,
692
869
  trace: trace,
693
870
  constraints: constraints)
@@ -701,15 +878,23 @@ module Steep
701
878
  end
702
879
  end
703
880
 
704
- def check_method_type(name, sub_type, super_type, self_type:, assumption:, trace:, constraints:)
881
+ def check_method_type(name, sub_type, super_type, self_type:, instance_type:, class_type:, assumption:, trace:, constraints:)
705
882
  Steep.logger.tagged("#{name}: #{sub_type} <: #{super_type}") do
706
- check_method_params(name, sub_type.type.params, super_type.type.params, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints).then do
883
+ check_method_params(name, sub_type.type.params, super_type.type.params, self_type: self_type, instance_type: instance_type, class_type: class_type, assumption: assumption, trace: trace, constraints: constraints).then do
707
884
  check_block_given(name, sub_type.block, super_type.block, trace: trace, constraints: constraints).then do
708
- check_block_params(name, sub_type.block, super_type.block, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints).then do
709
- check_block_return(sub_type.block, super_type.block, self_type: self_type, assumption: assumption, trace: trace, constraints:constraints).then do
885
+ check_block_params(name, sub_type.block, super_type.block, self_type: self_type, instance_type: instance_type, class_type: class_type, assumption: assumption, trace: trace, constraints: constraints).then do
886
+ check_block_return(sub_type.block, super_type.block, self_type: self_type, instance_type: instance_type, class_type: class_type, assumption: assumption, trace: trace, constraints:constraints).then do
710
887
  relation = Relation.new(super_type: super_type.type.return_type,
711
888
  sub_type: sub_type.type.return_type)
712
- check(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
889
+ check(
890
+ relation,
891
+ self_type: self_type,
892
+ instance_type: instance_type,
893
+ class_type: class_type,
894
+ assumption: assumption,
895
+ trace: trace,
896
+ constraints: constraints
897
+ )
713
898
  end
714
899
  end
715
900
  end
@@ -733,14 +918,20 @@ module Steep
733
918
  end
734
919
  end
735
920
 
736
- def check_method_params(name, sub_params, super_params, self_type:, assumption:, trace:, constraints:)
921
+ def check_method_params(name, sub_params, super_params, self_type:, instance_type:, class_type:, assumption:, trace:, constraints:)
737
922
  match_params(name, sub_params, super_params, trace: trace).yield_self do |pairs|
738
923
  case pairs
739
924
  when Array
740
925
  pairs.each do |(sub_type, super_type)|
741
926
  relation = Relation.new(super_type: sub_type, sub_type: super_type)
742
927
 
743
- result = check(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
928
+ result = check(relation,
929
+ self_type: self_type,
930
+ instance_type: instance_type,
931
+ class_type: class_type,
932
+ assumption: assumption,
933
+ trace: trace,
934
+ constraints: constraints)
744
935
  return result if result.failure?
745
936
  end
746
937
 
@@ -869,12 +1060,14 @@ module Steep
869
1060
  pairs
870
1061
  end
871
1062
 
872
- def check_block_params(name, sub_block, super_block, self_type:, assumption:, trace:, constraints:)
1063
+ def check_block_params(name, sub_block, super_block, self_type:, instance_type:, class_type:, assumption:, trace:, constraints:)
873
1064
  if sub_block && super_block
874
1065
  check_method_params(name,
875
1066
  super_block.type.params,
876
1067
  sub_block.type.params,
877
1068
  self_type: self_type,
1069
+ instance_type: instance_type,
1070
+ class_type: class_type,
878
1071
  assumption: assumption,
879
1072
  trace: trace,
880
1073
  constraints: constraints)
@@ -883,11 +1076,19 @@ module Steep
883
1076
  end
884
1077
  end
885
1078
 
886
- def check_block_return(sub_block, super_block, self_type:, assumption:, trace:, constraints:)
1079
+ def check_block_return(sub_block, super_block, self_type:, instance_type:, class_type:, assumption:, trace:, constraints:)
887
1080
  if sub_block && super_block
888
1081
  relation = Relation.new(sub_type: super_block.type.return_type,
889
1082
  super_type: sub_block.type.return_type)
890
- check(relation, self_type: self_type, assumption: assumption, trace: trace, constraints: constraints)
1083
+ check(
1084
+ relation,
1085
+ self_type: self_type,
1086
+ instance_type: instance_type,
1087
+ class_type: class_type,
1088
+ assumption: assumption,
1089
+ trace: trace,
1090
+ constraints: constraints
1091
+ )
891
1092
  else
892
1093
  success(constraints: constraints)
893
1094
  end