steep 1.7.0.dev.2 → 1.7.0.dev.4

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 (64) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +17 -19
  3. data/doc/narrowing.md +1 -1
  4. data/doc/shape.md +176 -0
  5. data/gemfile_steep/Gemfile.lock +10 -12
  6. data/lib/steep/ast/types/factory.rb +27 -18
  7. data/lib/steep/ast/types/helper.rb +4 -0
  8. data/lib/steep/ast/types/intersection.rb +7 -0
  9. data/lib/steep/ast/types/proc.rb +14 -9
  10. data/lib/steep/ast/types/record.rb +7 -0
  11. data/lib/steep/ast/types/tuple.rb +7 -0
  12. data/lib/steep/ast/types/union.rb +7 -0
  13. data/lib/steep/drivers/stats.rb +2 -2
  14. data/lib/steep/drivers/validate.rb +4 -2
  15. data/lib/steep/expectations.rb +2 -2
  16. data/lib/steep/interface/block.rb +1 -1
  17. data/lib/steep/interface/builder.rb +337 -360
  18. data/lib/steep/interface/function.rb +82 -11
  19. data/lib/steep/interface/method_type.rb +18 -10
  20. data/lib/steep/interface/shape.rb +69 -18
  21. data/lib/steep/interface/substitution.rb +4 -0
  22. data/lib/steep/node_helper.rb +18 -1
  23. data/lib/steep/project/pattern.rb +1 -2
  24. data/lib/steep/server/interaction_worker.rb +6 -0
  25. data/lib/steep/server/lsp_formatter.rb +2 -0
  26. data/lib/steep/services/completion_provider.rb +20 -18
  27. data/lib/steep/services/file_loader.rb +15 -20
  28. data/lib/steep/services/signature_help_provider.rb +17 -18
  29. data/lib/steep/signature/validator.rb +1 -1
  30. data/lib/steep/subtyping/check.rb +19 -22
  31. data/lib/steep/subtyping/variable_variance.rb +3 -3
  32. data/lib/steep/test.rb +9 -0
  33. data/lib/steep/type_construction.rb +198 -158
  34. data/lib/steep/type_inference/block_params.rb +12 -4
  35. data/lib/steep/type_inference/context.rb +1 -1
  36. data/lib/steep/type_inference/logic_type_interpreter.rb +3 -2
  37. data/lib/steep/type_inference/method_params.rb +16 -0
  38. data/lib/steep/type_inference/send_args.rb +5 -2
  39. data/lib/steep/version.rb +1 -1
  40. data/lib/steep.rb +11 -7
  41. data/sig/steep/ast/types/factory.rbs +2 -2
  42. data/sig/steep/ast/types/helper.rbs +2 -0
  43. data/sig/steep/ast/types/intersection.rbs +2 -0
  44. data/sig/steep/ast/types/name.rbs +4 -0
  45. data/sig/steep/ast/types/record.rbs +2 -0
  46. data/sig/steep/ast/types/tuple.rbs +2 -0
  47. data/sig/steep/ast/types/union.rbs +2 -0
  48. data/sig/steep/expectations.rbs +1 -1
  49. data/sig/steep/interface/block.rbs +2 -2
  50. data/sig/steep/interface/builder.rbs +54 -109
  51. data/sig/steep/interface/function.rbs +38 -32
  52. data/sig/steep/interface/shape.rbs +23 -4
  53. data/sig/steep/interface/substitution.rbs +2 -0
  54. data/sig/steep/node_helper.rbs +11 -0
  55. data/sig/steep/services/signature_help_provider.rbs +3 -1
  56. data/sig/steep/subtyping/constraints.rbs +2 -2
  57. data/sig/steep/subtyping/variable_variance.rbs +1 -1
  58. data/sig/steep/type_construction.rbs +1 -1
  59. data/sig/steep/type_inference/block_params.rbs +3 -3
  60. data/sig/steep/type_inference/context.rbs +2 -0
  61. data/sig/steep/type_inference/method_params.rbs +3 -3
  62. data/sig/steep.rbs +1 -1
  63. data/steep.gemspec +1 -1
  64. metadata +6 -4
@@ -12,30 +12,25 @@ module Steep
12
12
  pats = commandline_patterns.empty? ? pattern.patterns : commandline_patterns
13
13
 
14
14
  pats.each do |path|
15
- absolute_path = base_dir + path
16
-
17
- if absolute_path.file?
18
- relative_path = absolute_path.relative_path_from(base_dir)
19
- if pattern =~ relative_path
20
- yield relative_path
21
- end
22
- else
23
- files = if absolute_path.directory?
24
- Pathname.glob("#{absolute_path}/**/*#{pattern.ext}")
25
- else
26
- Pathname.glob(absolute_path.to_s)
27
- end
28
-
29
- files.sort.each do |source_path|
30
- if source_path.file?
31
- relative_path = source_path.relative_path_from(base_dir)
32
- unless pattern.ignore?(relative_path)
33
- yield relative_path
15
+ Pathname.glob((base_dir + path).to_s).each do |absolute_path|
16
+ if absolute_path.file?
17
+ relative_path = absolute_path.relative_path_from(base_dir)
18
+ if pattern =~ relative_path
19
+ yield relative_path
20
+ end
21
+ else
22
+ files = Pathname.glob("#{absolute_path}/**/*#{pattern.ext}")
23
+
24
+ files.sort.each do |source_path|
25
+ if source_path.file?
26
+ relative_path = source_path.relative_path_from(base_dir)
27
+ unless pattern.ignore?(relative_path)
28
+ yield relative_path
29
+ end
34
30
  end
35
31
  end
36
32
  end
37
33
  end
38
-
39
34
  end
40
35
  else
41
36
  enum_for :each_path_in_patterns, pattern, commandline_patterns
@@ -7,18 +7,22 @@ module Steep
7
7
  # @implements Item
8
8
 
9
9
  def parameters
10
- arguments = [] #: Array[String]
11
- arguments.push(*method_type.type.required_positionals.map(&:to_s))
12
- arguments.push(*method_type.type.optional_positionals.map {|p| "?#{p}"})
13
- arguments.push("*#{self.method_type.type.rest_positionals}") if method_type.type.rest_positionals
14
- arguments.push(*method_type.type.trailing_positionals.map(&:to_s))
15
- arguments.push(*method_type.type.required_keywords.map {|name, param| "#{name}: #{param}" })
16
- arguments.push(*method_type.type.optional_keywords.map {|name, param| "?#{name}: #{param}" })
17
- arguments.push("**#{method_type.type.rest_keywords}") if method_type.type.rest_keywords
18
- arguments
10
+ if method_type.type.is_a?(RBS::Types::Function)
11
+ arguments = [] #: Array[String]
12
+ arguments.push(*method_type.type.required_positionals.map(&:to_s))
13
+ arguments.push(*method_type.type.optional_positionals.map {|p| "?#{p}"})
14
+ arguments.push("*#{self.method_type.type.rest_positionals}") if method_type.type.rest_positionals
15
+ arguments.push(*method_type.type.trailing_positionals.map(&:to_s))
16
+ arguments.push(*method_type.type.required_keywords.map {|name, param| "#{name}: #{param}" })
17
+ arguments.push(*method_type.type.optional_keywords.map {|name, param| "?#{name}: #{param}" })
18
+ arguments.push("**#{method_type.type.rest_keywords}") if method_type.type.rest_keywords
19
+ arguments
20
+ end
19
21
  end
20
22
  end
21
23
 
24
+ include NodeHelper
25
+
22
26
  attr_reader :source, :path, :subtyping, :typing, :buffer
23
27
 
24
28
  def env
@@ -103,16 +107,11 @@ module Steep
103
107
  case call
104
108
  when MethodCall::Typed, MethodCall::Error
105
109
  type = call.receiver_type
106
- if type.is_a?(AST::Types::Self)
107
- type = context.self_type
108
- end
110
+ config = Interface::Builder::Config.new(self_type: context.self_type, variable_bounds: context.variable_context.upper_bounds)
111
+
112
+ if shape = subtyping.builder.shape(type, config)
113
+ shape = shape.public_shape if private_send?(node)
109
114
 
110
- shape = subtyping.builder.shape(
111
- type,
112
- public_only: !node.children[0].nil?,
113
- config: Interface::Builder::Config.new(self_type: type, class_type: nil, instance_type: nil, variable_bounds: {})
114
- )
115
- if shape
116
115
  if method = shape.methods[call.method_name]
117
116
  method.method_types.each.with_index do |method_type, i|
118
117
  defn = method_type.method_decls.to_a[0]&.method_def
@@ -134,7 +134,7 @@ module Steep
134
134
  end
135
135
 
136
136
  def validate_type(type)
137
- Steep.logger.debug "#{Location.to_string type.location}: Validating #{type}..."
137
+ Steep.logger.debug { "#{Location.to_string type.location}: Validating #{type}..." }
138
138
 
139
139
  validator.validate_type(type, context: nil)
140
140
  validate_type_application(type)
@@ -410,14 +410,8 @@ module Steep
410
410
  relation.map {|type|
411
411
  builder.shape(
412
412
  type,
413
- public_only: true,
414
- config: Interface::Builder::Config.new(
415
- self_type: type,
416
- instance_type: instance_type,
417
- class_type: class_type,
418
- variable_bounds: variable_upper_bounds
419
- )
420
- ) or return Failure(relation, Result::Failure::UnknownPairError.new(relation: relation))
413
+ Interface::Builder::Config.new(self_type: type, variable_bounds: variable_upper_bounds)
414
+ )&.public_shape() or return Failure(relation, Result::Failure::UnknownPairError.new(relation: relation))
421
415
  }
422
416
  )
423
417
  end
@@ -530,14 +524,8 @@ module Steep
530
524
  relation.map {|type|
531
525
  builder.shape(
532
526
  type,
533
- public_only: true,
534
- config: Interface::Builder::Config.new(
535
- self_type: type,
536
- instance_type: instance_type,
537
- class_type: class_type,
538
- variable_bounds: variable_upper_bounds
539
- )
540
- ) or raise
527
+ Interface::Builder::Config.new(self_type: type, variable_bounds: variable_upper_bounds)
528
+ )&.public_shape or raise
541
529
  }
542
530
  )
543
531
  end
@@ -862,8 +850,10 @@ module Steep
862
850
  relation.function!
863
851
 
864
852
  All(relation) do |result|
865
- result.add(relation.map {|fun| fun.params }) do |rel|
866
- check_method_params(name, rel)
853
+ if relation.sub_type.params && relation.super_type.params
854
+ result.add(relation.map {|fun| _ = fun.params }) do |rel|
855
+ check_method_params(name, rel)
856
+ end
867
857
  end
868
858
 
869
859
  result.add(relation.map {|fun| fun.return_type }) do |rel|
@@ -918,16 +908,23 @@ module Steep
918
908
  end
919
909
 
920
910
  def match_method_type_fails?(name, type1, type2)
921
- match_params(name, Relation(type1.type.params, type2.type.params)).tap do |param_pairs|
922
- return param_pairs unless param_pairs.is_a?(Array)
911
+ if type1.type.params && type2.type.params
912
+ match_params(name, Relation(type1.type.params, type2.type.params)).tap do |param_pairs|
913
+ return param_pairs unless param_pairs.is_a?(Array)
914
+ end
923
915
  end
924
916
 
925
917
  case result = expand_block_given(name, Relation(type1.block, type2.block))
926
918
  when Result::Base
927
919
  return result
928
920
  when Relation
929
- match_params(name, result.map {|m| m.type.params }).tap do |param_pairs|
930
- return param_pairs unless param_pairs.is_a?(Array)
921
+ type1.block or raise
922
+ type2.block or raise
923
+
924
+ if type1.block.type.params && type2.block.type.params
925
+ match_params(name, result.map {|m| _ = m.type.params }).tap do |param_pairs|
926
+ return param_pairs unless param_pairs.is_a?(Array)
927
+ end
931
928
  end
932
929
  end
933
930
 
@@ -46,7 +46,7 @@ module Steep
46
46
  end
47
47
 
48
48
  def self.add_params(params, block:, covariants:, contravariants:)
49
- params.each_type do |type|
49
+ params&.each_type do |type|
50
50
  add_type(type, variance: block ? :contravariant : :covariant, covariants: covariants, contravariants: contravariants)
51
51
  end
52
52
  end
@@ -64,12 +64,12 @@ module Steep
64
64
  contravariants << type.name
65
65
  end
66
66
  when AST::Types::Proc
67
- type.type.params.each_type do |type|
67
+ type.type.params&.each_type do |type|
68
68
  add_type(type, variance: variance, covariants: contravariants, contravariants: covariants)
69
69
  end
70
70
  add_type(type.type.return_type, variance: variance, covariants: covariants, contravariants: contravariants)
71
71
  if type.block
72
- type.block.type.params.each_type do |type|
72
+ type.block.type.params&.each_type do |type|
73
73
  add_type(type, variance: variance, covariants: covariants, contravariants: contravariants)
74
74
  end
75
75
  add_type(type.type.return_type, variance: variance, covariants: contravariants, contravariants: covariants)
data/lib/steep/test.rb ADDED
@@ -0,0 +1,9 @@
1
+ Steep.logger.warn(true)
2
+
3
+ # class Steep::Subtyping::Result::All
4
+ # def add(*relations)
5
+ # rel = relations[0] # Relation[T] < Relation::_Subject
6
+ # yield rel # Relation[T] < Relation[_Subject]
7
+ # true
8
+ # end
9
+ # end