steep 0.40.0 → 0.44.0

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 (169) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +38 -0
  3. data/Gemfile +1 -0
  4. data/bin/output_rebaseline.rb +15 -30
  5. data/bin/output_test.rb +23 -57
  6. data/lib/steep.rb +89 -15
  7. data/lib/steep/annotation_parser.rb +10 -2
  8. data/lib/steep/ast/types/class.rb +4 -0
  9. data/lib/steep/cli.rb +31 -6
  10. data/lib/steep/diagnostic/ruby.rb +13 -8
  11. data/lib/steep/diagnostic/signature.rb +152 -2
  12. data/lib/steep/drivers/annotations.rb +18 -36
  13. data/lib/steep/drivers/check.rb +140 -31
  14. data/lib/steep/drivers/diagnostic_printer.rb +20 -11
  15. data/lib/steep/drivers/langserver.rb +4 -8
  16. data/lib/steep/drivers/print_project.rb +10 -9
  17. data/lib/steep/drivers/stats.rb +135 -119
  18. data/lib/steep/drivers/utils/driver_helper.rb +35 -0
  19. data/lib/steep/drivers/utils/jobs_count.rb +9 -0
  20. data/lib/steep/drivers/validate.rb +29 -18
  21. data/lib/steep/drivers/watch.rb +55 -49
  22. data/lib/steep/drivers/worker.rb +11 -8
  23. data/lib/steep/expectations.rb +159 -0
  24. data/lib/steep/index/signature_symbol_provider.rb +23 -1
  25. data/lib/steep/index/source_index.rb +55 -5
  26. data/lib/steep/interface/block.rb +4 -0
  27. data/lib/steep/project.rb +0 -30
  28. data/lib/steep/project/dsl.rb +5 -3
  29. data/lib/steep/project/pattern.rb +56 -0
  30. data/lib/steep/project/target.rb +11 -227
  31. data/lib/steep/server/base_worker.rb +1 -3
  32. data/lib/steep/server/change_buffer.rb +63 -0
  33. data/lib/steep/server/interaction_worker.rb +72 -57
  34. data/lib/steep/server/master.rb +652 -234
  35. data/lib/steep/server/type_check_worker.rb +304 -0
  36. data/lib/steep/server/worker_process.rb +16 -11
  37. data/lib/steep/{project → services}/completion_provider.rb +5 -5
  38. data/lib/steep/services/content_change.rb +61 -0
  39. data/lib/steep/services/file_loader.rb +48 -0
  40. data/lib/steep/services/goto_service.rb +321 -0
  41. data/lib/steep/{project → services}/hover_content.rb +19 -20
  42. data/lib/steep/services/path_assignment.rb +27 -0
  43. data/lib/steep/services/signature_service.rb +403 -0
  44. data/lib/steep/services/stats_calculator.rb +69 -0
  45. data/lib/steep/services/type_check_service.rb +413 -0
  46. data/lib/steep/signature/validator.rb +187 -85
  47. data/lib/steep/source.rb +21 -18
  48. data/lib/steep/subtyping/check.rb +246 -45
  49. data/lib/steep/subtyping/constraints.rb +4 -4
  50. data/lib/steep/type_construction.rb +428 -193
  51. data/lib/steep/type_inference/block_params.rb +1 -1
  52. data/lib/steep/type_inference/context.rb +22 -0
  53. data/lib/steep/type_inference/local_variable_type_env.rb +26 -12
  54. data/lib/steep/type_inference/logic.rb +1 -1
  55. data/lib/steep/type_inference/logic_type_interpreter.rb +4 -4
  56. data/lib/steep/type_inference/type_env.rb +43 -17
  57. data/lib/steep/version.rb +1 -1
  58. data/smoke/alias/test_expectations.yml +96 -0
  59. data/smoke/and/test_expectations.yml +31 -0
  60. data/smoke/array/test_expectations.yml +103 -0
  61. data/smoke/block/test_expectations.yml +125 -0
  62. data/smoke/case/test_expectations.yml +47 -0
  63. data/smoke/class/test_expectations.yml +120 -0
  64. data/smoke/const/test_expectations.yml +129 -0
  65. data/smoke/diagnostics-rbs-duplicated/test_expectations.yml +13 -0
  66. data/smoke/diagnostics-rbs/Steepfile +7 -4
  67. data/smoke/diagnostics-rbs/test_expectations.yml +231 -0
  68. data/smoke/diagnostics-rbs/unknown-type-name-2.rbs +5 -0
  69. data/smoke/{broken → diagnostics-ruby-unsat}/Steepfile +0 -0
  70. data/smoke/diagnostics-ruby-unsat/a.rbs +3 -0
  71. data/smoke/diagnostics-ruby-unsat/test_expectations.yml +27 -0
  72. data/smoke/{diagnostics → diagnostics-ruby-unsat}/unsatisfiable_constraint.rb +0 -1
  73. data/smoke/diagnostics/a.rbs +0 -4
  74. data/smoke/diagnostics/test_expectations.yml +451 -0
  75. data/smoke/dstr/test_expectations.yml +13 -0
  76. data/smoke/ensure/test_expectations.yml +62 -0
  77. data/smoke/enumerator/test_expectations.yml +135 -0
  78. data/smoke/extension/f.rb +2 -0
  79. data/smoke/extension/f.rbs +3 -0
  80. data/smoke/extension/test_expectations.yml +73 -0
  81. data/smoke/hash/test_expectations.yml +81 -0
  82. data/smoke/hello/test_expectations.yml +25 -0
  83. data/smoke/if/test_expectations.yml +34 -0
  84. data/smoke/implements/b.rb +13 -0
  85. data/smoke/implements/b.rbs +12 -0
  86. data/smoke/implements/test_expectations.yml +23 -0
  87. data/smoke/initialize/test_expectations.yml +1 -0
  88. data/smoke/integer/test_expectations.yml +101 -0
  89. data/smoke/interface/test_expectations.yml +23 -0
  90. data/smoke/kwbegin/test_expectations.yml +17 -0
  91. data/smoke/lambda/test_expectations.yml +39 -0
  92. data/smoke/literal/test_expectations.yml +106 -0
  93. data/smoke/map/test_expectations.yml +1 -0
  94. data/smoke/method/test_expectations.yml +90 -0
  95. data/smoke/module/test_expectations.yml +75 -0
  96. data/smoke/regexp/test_expectations.yml +615 -0
  97. data/smoke/regression/issue_328.rb +1 -0
  98. data/smoke/regression/issue_328.rbs +0 -0
  99. data/smoke/regression/issue_332.rb +11 -0
  100. data/smoke/regression/issue_332.rbs +19 -0
  101. data/smoke/regression/issue_372.rb +8 -0
  102. data/smoke/regression/issue_372.rbs +4 -0
  103. data/smoke/regression/masgn.rb +4 -0
  104. data/smoke/regression/test_expectations.yml +60 -0
  105. data/smoke/regression/thread.rb +7 -0
  106. data/smoke/rescue/test_expectations.yml +79 -0
  107. data/smoke/self/test_expectations.yml +23 -0
  108. data/smoke/skip/test_expectations.yml +23 -0
  109. data/smoke/stdout/test_expectations.yml +1 -0
  110. data/smoke/super/test_expectations.yml +69 -0
  111. data/smoke/toplevel/test_expectations.yml +15 -0
  112. data/smoke/tsort/Steepfile +2 -0
  113. data/smoke/tsort/test_expectations.yml +63 -0
  114. data/smoke/type_case/test_expectations.yml +48 -0
  115. data/smoke/unexpected/Steepfile +5 -0
  116. data/smoke/unexpected/test_expectations.yml +25 -0
  117. data/smoke/unexpected/unexpected.rb +1 -0
  118. data/smoke/unexpected/unexpected.rbs +3 -0
  119. data/smoke/yield/test_expectations.yml +68 -0
  120. data/steep.gemspec +4 -3
  121. metadata +127 -80
  122. data/lib/steep/project/file_loader.rb +0 -68
  123. data/lib/steep/project/signature_file.rb +0 -39
  124. data/lib/steep/project/source_file.rb +0 -129
  125. data/lib/steep/project/stats_calculator.rb +0 -80
  126. data/lib/steep/server/code_worker.rb +0 -150
  127. data/lib/steep/server/signature_worker.rb +0 -157
  128. data/lib/steep/server/utils.rb +0 -69
  129. data/smoke/alias/test.yaml +0 -73
  130. data/smoke/and/test.yaml +0 -24
  131. data/smoke/array/test.yaml +0 -80
  132. data/smoke/block/test.yaml +0 -96
  133. data/smoke/broken/broken.rb +0 -0
  134. data/smoke/broken/broken.rbs +0 -0
  135. data/smoke/broken/test.yaml +0 -6
  136. data/smoke/case/test.yaml +0 -36
  137. data/smoke/class/test.yaml +0 -89
  138. data/smoke/const/test.yaml +0 -96
  139. data/smoke/diagnostics-rbs-duplicated/test.yaml +0 -10
  140. data/smoke/diagnostics-rbs/test.yaml +0 -142
  141. data/smoke/diagnostics/test.yaml +0 -333
  142. data/smoke/dstr/test.yaml +0 -10
  143. data/smoke/ensure/test.yaml +0 -47
  144. data/smoke/enumerator/test.yaml +0 -100
  145. data/smoke/extension/test.yaml +0 -50
  146. data/smoke/hash/test.yaml +0 -62
  147. data/smoke/hello/test.yaml +0 -18
  148. data/smoke/if/test.yaml +0 -27
  149. data/smoke/implements/test.yaml +0 -16
  150. data/smoke/initialize/test.yaml +0 -4
  151. data/smoke/integer/test.yaml +0 -66
  152. data/smoke/interface/test.yaml +0 -16
  153. data/smoke/kwbegin/test.yaml +0 -14
  154. data/smoke/lambda/test.yaml +0 -28
  155. data/smoke/literal/test.yaml +0 -79
  156. data/smoke/map/test.yaml +0 -4
  157. data/smoke/method/test.yaml +0 -71
  158. data/smoke/module/test.yaml +0 -51
  159. data/smoke/regexp/test.yaml +0 -372
  160. data/smoke/regression/test.yaml +0 -38
  161. data/smoke/rescue/test.yaml +0 -60
  162. data/smoke/self/test.yaml +0 -16
  163. data/smoke/skip/test.yaml +0 -16
  164. data/smoke/stdout/test.yaml +0 -4
  165. data/smoke/super/test.yaml +0 -52
  166. data/smoke/toplevel/test.yaml +0 -12
  167. data/smoke/tsort/test.yaml +0 -32
  168. data/smoke/type_case/test.yaml +0 -33
  169. data/smoke/yield/test.yaml +0 -49
data/lib/steep/source.rb CHANGED
@@ -44,16 +44,10 @@ module Steep
44
44
  end
45
45
  end
46
46
 
47
- def self.parse(source_code, path:, factory:, labeling: ASTUtils::Labeling.new)
47
+ def self.parse(source_code, path:, factory:)
48
48
  buffer = ::Parser::Source::Buffer.new(path.to_s, 1)
49
49
  buffer.source = source_code
50
- node = parser.parse(buffer).yield_self do |n|
51
- if n
52
- labeling.translate(n, {})
53
- else
54
- return new(path: path, node: nil, mapping: {})
55
- end
56
- end
50
+ node = parser.parse(buffer)
57
51
 
58
52
  annotations = []
59
53
 
@@ -78,13 +72,13 @@ module Steep
78
72
  end
79
73
  end
80
74
 
81
- mapping = {}
75
+ mapping = {}.compare_by_identity
82
76
 
83
77
  construct_mapping(node: node, annotations: annotations, mapping: mapping)
84
78
 
85
79
  annotations.each do |annot|
86
- mapping[node.__id__] = [] unless mapping.key?(node.__id__)
87
- mapping[node.__id__] << annot.annotation
80
+ mapping[node] ||= []
81
+ mapping[node] << annot
88
82
  end
89
83
 
90
84
  new(path: path, node: node, mapping: mapping)
@@ -262,8 +256,8 @@ module Steep
262
256
  end
263
257
 
264
258
  associated_annotations.each do |annot|
265
- mapping[node.__id__] = [] unless mapping.key?(node.__id__)
266
- mapping[node.__id__] << annot.annotation
259
+ mapping[node] ||= []
260
+ mapping[node] << annot
267
261
  annotations.delete annot
268
262
  end
269
263
  end
@@ -290,17 +284,16 @@ module Steep
290
284
 
291
285
  def annotations(block:, factory:, current_module:)
292
286
  AST::Annotation::Collection.new(
293
- annotations: mapping[block.__id__] || [],
287
+ annotations: (mapping[block] || []).map(&:annotation),
294
288
  factory: factory,
295
289
  current_module: current_module
296
290
  )
297
291
  end
298
292
 
299
- def each_annotation
293
+ def each_annotation(&block)
300
294
  if block_given?
301
- mapping.each_key do |id|
302
- node = ObjectSpace._id2ref(id)
303
- yield node, mapping[id]
295
+ mapping.each do |node, annots|
296
+ yield node, annots.map(&:annotation)
304
297
  end
305
298
  else
306
299
  enum_for :each_annotation
@@ -356,6 +349,16 @@ module Steep
356
349
 
357
350
  node_ = Source.delete_defs(node, defs)
358
351
 
352
+ mapping = {}.compare_by_identity
353
+
354
+ annotations = self.mapping.values.flatten
355
+ Source.construct_mapping(node: node_, annotations: annotations, mapping: mapping)
356
+
357
+ annotations.each do |annot|
358
+ mapping[node] ||= []
359
+ mapping[node] << annot
360
+ end
361
+
359
362
  Source.new(path: path, node: node_, mapping: mapping)
360
363
  end
361
364
 
@@ -9,6 +9,21 @@ 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
28
  ancestors = factory.definition_builder.ancestor_builder.one_instance_ancestors(type_name)
14
29
 
@@ -17,7 +32,7 @@ module Steep
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
@@ -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