steep 1.8.0.dev.1 → 1.8.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 (74) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +33 -0
  3. data/README.md +3 -2
  4. data/bin/mem_graph.rb +67 -0
  5. data/bin/mem_prof.rb +102 -0
  6. data/bin/stackprof_test.rb +19 -0
  7. data/bin/steep-check.rb +251 -0
  8. data/guides/src/gem-rbs-collection/gem-rbs-collection.md +1 -1
  9. data/lib/steep/annotation_parser.rb +1 -1
  10. data/lib/steep/ast/builtin.rb +5 -5
  11. data/lib/steep/ast/node/type_application.rb +7 -6
  12. data/lib/steep/ast/types/any.rb +1 -9
  13. data/lib/steep/ast/types/boolean.rb +8 -16
  14. data/lib/steep/ast/types/bot.rb +2 -10
  15. data/lib/steep/ast/types/class.rb +1 -13
  16. data/lib/steep/ast/types/factory.rb +101 -85
  17. data/lib/steep/ast/types/instance.rb +1 -13
  18. data/lib/steep/ast/types/intersection.rb +8 -15
  19. data/lib/steep/ast/types/literal.rb +2 -8
  20. data/lib/steep/ast/types/logic.rb +3 -24
  21. data/lib/steep/ast/types/name.rb +5 -16
  22. data/lib/steep/ast/types/nil.rb +3 -12
  23. data/lib/steep/ast/types/proc.rb +4 -13
  24. data/lib/steep/ast/types/record.rb +21 -12
  25. data/lib/steep/ast/types/self.rb +1 -13
  26. data/lib/steep/ast/types/shared_instance.rb +11 -0
  27. data/lib/steep/ast/types/top.rb +1 -9
  28. data/lib/steep/ast/types/tuple.rb +4 -10
  29. data/lib/steep/ast/types/union.rb +10 -15
  30. data/lib/steep/ast/types/var.rb +4 -13
  31. data/lib/steep/ast/types/void.rb +2 -10
  32. data/lib/steep/diagnostic/ruby.rb +10 -10
  33. data/lib/steep/drivers/check.rb +11 -14
  34. data/lib/steep/drivers/checkfile.rb +8 -10
  35. data/lib/steep/drivers/stats.rb +17 -13
  36. data/lib/steep/drivers/utils/driver_helper.rb +24 -3
  37. data/lib/steep/drivers/watch.rb +3 -3
  38. data/lib/steep/interface/builder.rb +162 -138
  39. data/lib/steep/interface/method_type.rb +12 -20
  40. data/lib/steep/interface/shape.rb +66 -10
  41. data/lib/steep/interface/substitution.rb +2 -0
  42. data/lib/steep/interface/type_param.rb +20 -7
  43. data/lib/steep/located_value.rb +20 -0
  44. data/lib/steep/server/change_buffer.rb +5 -7
  45. data/lib/steep/server/custom_methods.rb +61 -0
  46. data/lib/steep/server/delay_queue.rb +8 -1
  47. data/lib/steep/server/interaction_worker.rb +13 -6
  48. data/lib/steep/server/lsp_formatter.rb +8 -6
  49. data/lib/steep/server/master.rb +195 -142
  50. data/lib/steep/server/type_check_worker.rb +25 -22
  51. data/lib/steep/server/work_done_progress.rb +64 -0
  52. data/lib/steep/server/worker_process.rb +1 -1
  53. data/lib/steep/services/completion_provider.rb +32 -24
  54. data/lib/steep/services/goto_service.rb +3 -2
  55. data/lib/steep/services/hover_provider/ruby.rb +30 -17
  56. data/lib/steep/services/signature_help_provider.rb +9 -7
  57. data/lib/steep/services/signature_service.rb +1 -1
  58. data/lib/steep/services/type_check_service.rb +19 -9
  59. data/lib/steep/signature/validator.rb +17 -20
  60. data/lib/steep/source.rb +47 -1
  61. data/lib/steep/subtyping/check.rb +105 -55
  62. data/lib/steep/subtyping/constraints.rb +13 -17
  63. data/lib/steep/type_construction.rb +106 -100
  64. data/lib/steep/type_inference/block_params.rb +8 -5
  65. data/lib/steep/type_inference/logic_type_interpreter.rb +11 -7
  66. data/lib/steep/type_inference/method_call.rb +3 -3
  67. data/lib/steep/type_inference/method_params.rb +1 -1
  68. data/lib/steep/type_inference/send_args.rb +1 -1
  69. data/lib/steep/typing.rb +164 -106
  70. data/lib/steep/version.rb +1 -1
  71. data/lib/steep.rb +29 -4
  72. data/steep.gemspec +2 -2
  73. metadata +16 -9
  74. data/lib/steep/type_inference/context_array.rb +0 -112
@@ -79,8 +79,8 @@ module Steep
79
79
  type_params.zip(type_args).each do |param, arg|
80
80
  arg or raise
81
81
 
82
- if param.upper_bound
83
- upper_bound_type = factory.type(param.upper_bound).subst(subst)
82
+ if param.upper_bound_type
83
+ upper_bound_type = factory.type(param.upper_bound_type).subst(subst)
84
84
  arg_type = factory.type(arg)
85
85
 
86
86
  constraints = Subtyping::Constraints.empty
@@ -101,7 +101,8 @@ module Steep
101
101
  name: param.name,
102
102
  upper_bound: upper_bound_type,
103
103
  variance: param.variance,
104
- unchecked: param.unchecked?
104
+ unchecked: param.unchecked?,
105
+ default_type: factory.type_opt(param.default_type)
105
106
  ),
106
107
  location: location
107
108
  )
@@ -162,9 +163,9 @@ module Steep
162
163
 
163
164
  case
164
165
  when ancestor.name.interface?
165
- AST::Types::Name::Interface.new(name: ancestor.name, args: args, location: nil)
166
+ AST::Types::Name::Interface.new(name: ancestor.name, args: args)
166
167
  when ancestor.name.class?
167
- AST::Types::Name::Instance.new(name: ancestor.name, args: args, location: nil)
168
+ AST::Types::Name::Instance.new(name: ancestor.name, args: args)
168
169
  else
169
170
  raise "#{ancestor.name}"
170
171
  end
@@ -181,7 +182,7 @@ module Steep
181
182
  if immediate_self_types && !immediate_self_types.empty?
182
183
  # @type var sts: Array[AST::Types::t]
183
184
  sts = immediate_self_types.map {|st| ancestor_to_type(st) }
184
- self_type = AST::Types::Intersection.build(types: sts.push(self_type), location: nil)
185
+ self_type = AST::Types::Intersection.build(types: sts.push(self_type))
185
186
  end
186
187
 
187
188
  mixin_ancestors.each do |ancestor|
@@ -236,7 +237,7 @@ module Steep
236
237
  def validate_definition_type(definition)
237
238
  each_method_type(definition) do |method_type|
238
239
  upper_bounds = method_type.type_params.each.with_object({}) do |param, hash|
239
- hash[param.name] = factory.type_opt(param.upper_bound)
240
+ hash[param.name] = factory.type_opt(param.upper_bound_type)
240
241
  end
241
242
 
242
243
  checker.push_variable_bounds(upper_bounds) do
@@ -255,23 +256,21 @@ module Steep
255
256
  rescue_validation_errors(name) do
256
257
  Steep.logger.debug { "Validating class definition `#{name}`..." }
257
258
 
258
- class_type = AST::Types::Name::Singleton.new(name: name, location: nil)
259
+ class_type = AST::Types::Name::Singleton.new(name: name)
259
260
  instance_type = AST::Types::Name::Instance.new(
260
261
  name: name,
261
- args: entry.type_params.map { AST::Types::Any.new(location: nil) },
262
- location: nil
262
+ args: entry.type_params.map { AST::Types::Any.instance() }
263
263
  )
264
264
 
265
265
  Steep.logger.tagged "#{name}" do
266
266
  builder.build_instance(name).tap do |definition|
267
267
  upper_bounds = definition.type_params_decl.each.with_object({}) do |param, bounds|
268
- bounds[param.name] = factory.type_opt(param.upper_bound)
268
+ bounds[param.name] = factory.type_opt(param.upper_bound_type)
269
269
  end
270
270
 
271
271
  self_type = AST::Types::Name::Instance.new(
272
272
  name: name,
273
- args: entry.type_params.map { AST::Types::Var.new(name: _1.name) },
274
- location: nil
273
+ args: entry.type_params.map { AST::Types::Var.new(name: _1.name) }
275
274
  )
276
275
 
277
276
  push_context(self_type: self_type, class_type: class_type, instance_type: instance_type) do
@@ -482,13 +481,12 @@ module Steep
482
481
  definition = builder.build_interface(name)
483
482
 
484
483
  upper_bounds = definition.type_params_decl.each.with_object({}) do |param, bounds|
485
- bounds[param.name] = factory.type_opt(param.upper_bound)
484
+ bounds[param.name] = factory.type_opt(param.upper_bound_type)
486
485
  end
487
486
 
488
487
  self_type = AST::Types::Name::Interface.new(
489
488
  name: name,
490
- args: definition.type_params.map { AST::Types::Var.new(name: _1) },
491
- location: nil
489
+ args: definition.type_params.map { AST::Types::Var.new(name: _1) }
492
490
  )
493
491
 
494
492
  push_context(self_type: self_type, class_type: nil, instance_type: nil) do
@@ -561,11 +559,10 @@ module Steep
561
559
  def validate_one_alias(name, entry = env.type_alias_decls[name])
562
560
  *, inner_most_outer_module = entry.outer
563
561
  if inner_most_outer_module
564
- class_type = AST::Types::Name::Singleton.new(name: inner_most_outer_module.name, location: nil)
562
+ class_type = AST::Types::Name::Singleton.new(name: inner_most_outer_module.name)
565
563
  instance_type = AST::Types::Name::Instance.new(
566
564
  name: inner_most_outer_module.name,
567
- args: inner_most_outer_module.type_params.map { AST::Types::Any.new(location: nil) },
568
- location: nil
565
+ args: inner_most_outer_module.type_params.map { AST::Types::Any.instance() },
569
566
  )
570
567
  end
571
568
 
@@ -579,7 +576,7 @@ module Steep
579
576
  end
580
577
 
581
578
  upper_bounds = entry.decl.type_params.each.with_object({}) do |param, bounds|
582
- bounds[param.name] = factory.type_opt(param.upper_bound)
579
+ bounds[param.name] = factory.type_opt(param.upper_bound_type)
583
580
  end
584
581
 
585
582
  validator.validate_type_alias(entry: entry) do |type|
data/lib/steep/source.rb CHANGED
@@ -8,6 +8,7 @@ module Steep
8
8
  attr_reader :ignores
9
9
 
10
10
  extend NodeHelper
11
+ extend ModuleHelper
11
12
 
12
13
  def initialize(buffer:, path:, node:, mapping:, comments:, ignores:)
13
14
  @buffer = buffer
@@ -295,8 +296,14 @@ module Steep
295
296
  end
296
297
 
297
298
  def annotations(block:, factory:, context:)
299
+ annotations =
300
+ if block
301
+ mapping.fetch(block, [])
302
+ else
303
+ []
304
+ end #: Array[AST::Annotation::t]
298
305
  AST::Annotation::Collection.new(
299
- annotations: (mapping[block] || []),
306
+ annotations: annotations,
300
307
  factory: factory,
301
308
  context: context
302
309
  )
@@ -444,6 +451,32 @@ module Steep
444
451
  end
445
452
  end
446
453
 
454
+ def self.skip_arg_assertions(node)
455
+ send_node, _ = deconstruct_sendish_and_block_nodes(node)
456
+ return false unless send_node
457
+
458
+ if send_node.type == :send
459
+ receiver, method, args = deconstruct_send_node!(send_node)
460
+
461
+ return false unless receiver
462
+
463
+ if receiver.type == :const
464
+ if type_name = module_name_from_node(receiver.children[0], receiver.children[1])
465
+ if type_name.namespace.empty?
466
+ if type_name.name == :Data && method == :define
467
+ return true
468
+ end
469
+ if type_name.name == :Struct && method == :new
470
+ return true
471
+ end
472
+ end
473
+ end
474
+ end
475
+ end
476
+
477
+ false
478
+ end
479
+
447
480
  def self.insert_type_node(node, comments)
448
481
  if node.location.expression
449
482
  first_line = node.location.expression.first_line
@@ -567,6 +600,19 @@ module Steep
567
600
  body = insert_type_node(body, comments) if body
568
601
  return adjust_location(node.updated(nil, [object, name, args, body]))
569
602
  else
603
+ if skip_arg_assertions(node)
604
+ # Data.define, Struct.new, ...??
605
+ if node.location.expression
606
+ first_line = node.location.expression.first_line
607
+ last_line = node.location.expression.last_line
608
+
609
+ child_assertions = comments.delete_if {|line, _ | first_line < line && line < last_line }
610
+ node = map_child_node(node) {|child| insert_type_node(child, child_assertions) }
611
+
612
+ return adjust_location(node)
613
+ end
614
+ end
615
+
570
616
  adjust_location(
571
617
  map_child_node(node, nil) {|child| insert_type_node(child, comments) }
572
618
  )
@@ -59,7 +59,7 @@ module Steep
59
59
  def variable_upper_bound(name)
60
60
  @bounds.reverse_each do |hash|
61
61
  if hash.key?(name)
62
- return hash[name]
62
+ return hash.fetch(name)
63
63
  end
64
64
  end
65
65
 
@@ -129,20 +129,17 @@ module Steep
129
129
  if ancestor.name.class?
130
130
  AST::Types::Name::Instance.new(
131
131
  name: name,
132
- args: args,
133
- location: nil
132
+ args: args
134
133
  )
135
134
  else
136
135
  AST::Types::Name::Interface.new(
137
136
  name: name,
138
- args: args,
139
- location: nil
137
+ args: args
140
138
  )
141
139
  end
142
140
  when RBS::Definition::Ancestor::Singleton
143
141
  AST::Types::Name::Singleton.new(
144
- name: name,
145
- location: nil
142
+ name: name
146
143
  )
147
144
  end
148
145
  end
@@ -163,20 +160,17 @@ module Steep
163
160
  if ancestor.name.class?
164
161
  AST::Types::Name::Instance.new(
165
162
  name: name,
166
- args: args,
167
- location: nil
163
+ args: args
168
164
  )
169
165
  else
170
166
  AST::Types::Name::Interface.new(
171
167
  name: name,
172
- args: args,
173
- location: nil
168
+ args: args
174
169
  )
175
170
  end
176
171
  when RBS::Definition::Ancestor::Singleton
177
172
  AST::Types::Name::Singleton.new(
178
- name: name,
179
- location: nil
173
+ name: name
180
174
  )
181
175
  end
182
176
  end
@@ -271,9 +265,6 @@ module Steep
271
265
  when relation.sub_type.is_a?(AST::Types::Bot)
272
266
  success(relation)
273
267
 
274
- when relation.sub_type.is_a?(AST::Types::Logic::Base) && (true_type?(relation.super_type) || false_type?(relation.super_type))
275
- success(relation)
276
-
277
268
  when relation.super_type.is_a?(AST::Types::Boolean)
278
269
  Expand(relation) do
279
270
  check_type(
@@ -284,7 +275,7 @@ module Steep
284
275
  )
285
276
  end
286
277
 
287
- when relation.sub_type.is_a?(AST::Types::Boolean)
278
+ when relation.sub_type.is_a?(AST::Types::Boolean) || relation.sub_type.is_a?(AST::Types::Logic::Base)
288
279
  Expand(relation) do
289
280
  check_type(
290
281
  Relation.new(
@@ -357,20 +348,51 @@ module Steep
357
348
  constraints.add(relation.sub_type.name, super_type: relation.super_type)
358
349
  Success(relation)
359
350
 
360
- when relation.sub_type.is_a?(AST::Types::Union)
351
+ when relation.sub_type.is_a?(AST::Types::Var) && ub = variable_upper_bound(relation.sub_type.name)
352
+ Expand(relation) do
353
+ check_type(Relation.new(sub_type: ub, super_type: relation.super_type))
354
+ end
355
+
356
+ when relation.sub_type.is_a?(AST::Types::Intersection) && relation.super_type.is_a?(AST::Types::Union)
357
+ Any(relation) do |base_result|
358
+ # Expand the super_type first
359
+ base_result.add(relation) do
360
+ Any(relation) do |result|
361
+ relation.super_type.types.sort_by {|ty| (path = hole_path(ty)) ? -path.size : -Float::INFINITY }.each do |super_type|
362
+ rel = Relation.new(sub_type: relation.sub_type, super_type: super_type)
363
+ result.add(rel) do
364
+ check_type(rel)
365
+ end
366
+ end
367
+ end
368
+ end
369
+
370
+ # Expand the sub_type if it fails
371
+ base_result.add(relation) do
372
+ Any(relation) do |result|
373
+ relation.sub_type.types.sort_by {|ty| (path = hole_path(ty)) ? -path.size : -Float::INFINITY }.each do |sub_type|
374
+ rel = Relation.new(sub_type: sub_type, super_type: relation.super_type)
375
+ result.add(rel) do
376
+ check_type(rel)
377
+ end
378
+ end
379
+ end
380
+ end
381
+ end
382
+
383
+ when relation.super_type.is_a?(AST::Types::Intersection)
361
384
  All(relation) do |result|
362
- relation.sub_type.types.each do |sub_type|
363
- rel = Relation.new(sub_type: sub_type, super_type: relation.super_type)
364
- result.add(rel) do
385
+ relation.super_type.types.each do |super_type|
386
+ result.add(Relation.new(sub_type: relation.sub_type, super_type: super_type)) do |rel|
365
387
  check_type(rel)
366
388
  end
367
389
  end
368
390
  end
369
391
 
370
- when relation.super_type.is_a?(AST::Types::Union)
371
- Any(relation) do |result|
372
- relation.super_type.types.sort_by {|ty| (path = hole_path(ty)) ? -path.size : -Float::INFINITY }.each do |super_type|
373
- rel = Relation.new(sub_type: relation.sub_type, super_type: super_type)
392
+ when relation.sub_type.is_a?(AST::Types::Union)
393
+ All(relation) do |result|
394
+ relation.sub_type.types.each do |sub_type|
395
+ rel = Relation.new(sub_type: sub_type, super_type: relation.super_type)
374
396
  result.add(rel) do
375
397
  check_type(rel)
376
398
  end
@@ -387,23 +409,16 @@ module Steep
387
409
  end
388
410
  end
389
411
 
390
- when relation.super_type.is_a?(AST::Types::Intersection)
391
- All(relation) do |result|
392
- relation.super_type.types.each do |super_type|
393
- result.add(Relation.new(sub_type: relation.sub_type, super_type: super_type)) do |rel|
412
+ when relation.super_type.is_a?(AST::Types::Union)
413
+ Any(relation) do |result|
414
+ relation.super_type.types.sort_by {|ty| (path = hole_path(ty)) ? -path.size : -Float::INFINITY }.each do |super_type|
415
+ rel = Relation.new(sub_type: relation.sub_type, super_type: super_type)
416
+ result.add(rel) do
394
417
  check_type(rel)
395
418
  end
396
419
  end
397
420
  end
398
421
 
399
- when relation.sub_type.is_a?(AST::Types::Var) && ub = variable_upper_bound(relation.sub_type.name)
400
- Expand(relation) do
401
- check_type(Relation.new(sub_type: ub, super_type: relation.super_type))
402
- end
403
-
404
- when relation.super_type.is_a?(AST::Types::Var) || relation.sub_type.is_a?(AST::Types::Var)
405
- Failure(relation, Result::Failure::UnknownPairError.new(relation: relation))
406
-
407
422
  when relation.super_type.is_a?(AST::Types::Name::Interface)
408
423
  Expand(relation) do
409
424
  check_interface(
@@ -497,37 +512,72 @@ module Steep
497
512
  Expand(relation) do
498
513
  tuple_element_type =
499
514
  AST::Types::Union.build(
500
- types: relation.sub_type.types,
501
- location: relation.sub_type.location
515
+ types: relation.sub_type.types
502
516
  )
503
517
 
504
518
  check_type(Relation.new(sub_type: tuple_element_type, super_type: super_type.args[0]))
505
519
  end
506
520
 
521
+ when relation.sub_type.is_a?(AST::Types::Tuple)
522
+ Any(relation) do |result|
523
+ # Check by converting the tuple to array
524
+ tuple_element_type = AST::Types::Union.build(types: relation.sub_type.types)
525
+ array_type = AST::Builtin::Array.instance_type(tuple_element_type)
526
+ result.add(Relation.new(sub_type: array_type, super_type: relation.super_type)) do
527
+ check_type(_1)
528
+ end
529
+
530
+ # Check by shapes
531
+ shape_relation = relation.map {|type|
532
+ # @type break: nil
533
+ builder.shape(
534
+ type, Interface::Builder::Config.new(self_type: type, variable_bounds: variable_upper_bounds)
535
+ )&.public_shape or break
536
+ }
537
+ if shape_relation
538
+ result.add(shape_relation) { check_interface(_1) }
539
+ end
540
+ end
541
+
507
542
  when relation.sub_type.is_a?(AST::Types::Record) && relation.super_type.is_a?(AST::Types::Record)
508
543
  All(relation) do |result|
509
544
  relation.super_type.elements.each_key do |key|
510
- rel = Relation.new(
511
- sub_type: relation.sub_type.elements[key] || AST::Builtin.nil_type,
512
- super_type: relation.super_type.elements[key]
513
- )
545
+ super_element_type = relation.super_type.elements[key]
514
546
 
515
- result.add(rel) do
516
- check_type(rel)
547
+ if relation.sub_type.elements.key?(key)
548
+ sub_element_type = relation.sub_type.elements[key]
549
+ else
550
+ if relation.super_type.required?(key)
551
+ sub_element_type = AST::Builtin.nil_type
552
+ end
553
+ end
554
+
555
+ if sub_element_type
556
+ rel = Relation.new(sub_type: sub_element_type, super_type: super_element_type)
557
+ result.add(rel) { check_type(rel) }
517
558
  end
518
559
  end
519
560
  end
520
561
 
521
- when relation.sub_type.is_a?(AST::Types::Record) && relation.super_type.is_a?(AST::Types::Name::Base)
522
- Expand(relation) do
523
- check_interface(
524
- relation.map {|type|
525
- builder.shape(
526
- type,
527
- Interface::Builder::Config.new(self_type: type, variable_bounds: variable_upper_bounds)
528
- )&.public_shape or raise
529
- }
530
- )
562
+ when relation.sub_type.is_a?(AST::Types::Record)
563
+ Any(relation) do |result|
564
+ # Check by converting the record to hash
565
+ key_type = AST::Types::Union.build(types: relation.sub_type.elements.each_key.map {|key| AST::Types::Literal.new(value: key) })
566
+ value_type = AST::Types::Union.build(types: relation.sub_type.elements.each_value.map {|key| key })
567
+ hash_type = AST::Builtin::Hash.instance_type(key_type, value_type)
568
+ result.add(Relation.new(sub_type: hash_type, super_type: relation.super_type)) { check_type(_1) }
569
+
570
+ # Check by the shapes
571
+ shape_relation = relation.map do |type|
572
+ # @type break: nil
573
+ builder.shape(
574
+ type,
575
+ Interface::Builder::Config.new(self_type: type, variable_bounds: variable_upper_bounds)
576
+ )&.public_shape or break
577
+ end
578
+ if shape_relation
579
+ result.add(shape_relation) { check_interface(_1) }
580
+ end
531
581
  end
532
582
 
533
583
  when relation.sub_type.is_a?(AST::Types::Proc) && AST::Builtin::Proc.instance_type?(relation.super_type)
@@ -28,7 +28,7 @@ module Steep
28
28
  attr_reader :lower_bound
29
29
  attr_reader :upper_bound
30
30
 
31
- def initialize(var: nil, lower_bound: nil, upper_bound: nil)
31
+ def initialize(var:, lower_bound:, upper_bound:)
32
32
  @var = var
33
33
  @lower_bound = lower_bound
34
34
  @upper_bound = upper_bound
@@ -96,7 +96,7 @@ module Steep
96
96
  unless Set.new(vars).disjoint?(unknowns)
97
97
  raise UnsatisfiedInvariantError.new(
98
98
  reason: UnsatisfiedInvariantError::VariablesUnknownsNotDisjoint.new(vars: vars),
99
- constraints: constraints
99
+ constraints: self
100
100
  )
101
101
  end
102
102
  end
@@ -113,13 +113,13 @@ module Steep
113
113
  end
114
114
 
115
115
  if super_type && !super_type.is_a?(AST::Types::Top)
116
- type = eliminate_variable(super_type, to: AST::Types::Top.new)
116
+ type = eliminate_variable(super_type, to: AST::Types::Top.instance)
117
117
  supers << type
118
118
  skips << type if skip
119
119
  end
120
120
 
121
121
  if sub_type && !sub_type.is_a?(AST::Types::Bot)
122
- type = eliminate_variable(sub_type, to: AST::Types::Bot.new)
122
+ type = eliminate_variable(sub_type, to: AST::Types::Bot.instance)
123
123
  subs << type
124
124
  skips << type if skip
125
125
  end
@@ -147,19 +147,19 @@ module Steep
147
147
  case type
148
148
  when AST::Types::Name::Instance, AST::Types::Name::Alias, AST::Types::Name::Interface
149
149
  type.args.map do |ty|
150
- eliminate_variable(ty, to: AST::Types::Any.new)
150
+ eliminate_variable(ty, to: AST::Types::Any.instance)
151
151
  end.yield_self do |args|
152
- type.class.new(name: type.name, args: args, location: type.location)
152
+ type.class.new(name: type.name, args: args)
153
153
  end
154
154
  when AST::Types::Union
155
155
  type.types.map do |ty|
156
- eliminate_variable(ty, to: AST::Types::Any.new)
156
+ eliminate_variable(ty, to: AST::Types::Any.instance)
157
157
  end.yield_self do |types|
158
158
  AST::Types::Union.build(types: types)
159
159
  end
160
160
  when AST::Types::Intersection
161
161
  type.types.map do |ty|
162
- eliminate_variable(ty, to: AST::Types::Any.new)
162
+ eliminate_variable(ty, to: AST::Types::Any.instance)
163
163
  end.yield_self do |types|
164
164
  AST::Types::Intersection.build(types: types)
165
165
  end
@@ -171,14 +171,10 @@ module Steep
171
171
  end
172
172
  when AST::Types::Tuple
173
173
  AST::Types::Tuple.new(
174
- types: type.types.map {|ty| eliminate_variable(ty, to: AST::Builtin.any_type) },
175
- location: type.location
174
+ types: type.types.map {|ty| eliminate_variable(ty, to: AST::Builtin.any_type) }
176
175
  )
177
176
  when AST::Types::Record
178
- AST::Types::Record.new(
179
- elements: type.elements.transform_values {|ty| eliminate_variable(ty, to: AST::Builtin.any_type) },
180
- location: type.location
181
- )
177
+ type.map_type { eliminate_variable(_1, to: AST::Builtin.any_type) }
182
178
  when AST::Types::Proc
183
179
  type.map_type {|ty| eliminate_variable(ty, to: AST::Builtin.any_type) }
184
180
  else
@@ -213,7 +209,7 @@ module Steep
213
209
 
214
210
  case upper_bound.size
215
211
  when 0
216
- AST::Types::Top.new
212
+ AST::Types::Top.instance
217
213
  when 1
218
214
  upper_bound.first || raise
219
215
  else
@@ -226,7 +222,7 @@ module Steep
226
222
 
227
223
  case lower_bound.size
228
224
  when 0
229
- AST::Types::Bot.new
225
+ AST::Types::Bot.instance
230
226
  when 1
231
227
  lower_bound.first || raise
232
228
  else
@@ -293,7 +289,7 @@ module Steep
293
289
  end
294
290
  else
295
291
  vars << var
296
- types << AST::Types::Any.new
292
+ types << AST::Types::Any.instance
297
293
  end
298
294
  end
299
295
  end