steep 1.0.2 → 1.1.0.pre.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (121) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +5 -0
  3. data/.gitignore +1 -0
  4. data/CHANGELOG.md +22 -3
  5. data/Gemfile +6 -3
  6. data/Gemfile.lock +12 -16
  7. data/Gemfile.steep +3 -0
  8. data/Gemfile.steep.lock +49 -0
  9. data/Rakefile +5 -0
  10. data/Steepfile +6 -1
  11. data/bin/setup +2 -0
  12. data/bin/steep +19 -0
  13. data/lib/steep/ast/types/factory.rb +1 -1
  14. data/lib/steep/diagnostic/ruby.rb +49 -3
  15. data/lib/steep/diagnostic/signature.rb +18 -0
  16. data/lib/steep/drivers/watch.rb +3 -1
  17. data/lib/steep/method_name.rb +9 -3
  18. data/lib/steep/node_helper.rb +49 -0
  19. data/lib/steep/services/completion_provider.rb +22 -15
  20. data/lib/steep/services/hover_provider/ruby.rb +30 -12
  21. data/lib/steep/services/type_check_service.rb +12 -12
  22. data/lib/steep/shims/symbol_start_with.rb +18 -0
  23. data/lib/steep/signature/validator.rb +19 -0
  24. data/lib/steep/subtyping/constraints.rb +43 -14
  25. data/lib/steep/type_construction.rb +666 -746
  26. data/lib/steep/type_inference/constant_env.rb +0 -2
  27. data/lib/steep/type_inference/context.rb +23 -17
  28. data/lib/steep/type_inference/logic_type_interpreter.rb +210 -119
  29. data/lib/steep/type_inference/method_call.rb +80 -6
  30. data/lib/steep/type_inference/multiple_assignment.rb +189 -0
  31. data/lib/steep/type_inference/type_env.rb +271 -120
  32. data/lib/steep/type_inference/type_env_builder.rb +138 -0
  33. data/lib/steep/typing.rb +2 -0
  34. data/lib/steep/version.rb +1 -1
  35. data/lib/steep.rb +4 -3
  36. data/rbs_collection.steep.lock.yaml +112 -0
  37. data/rbs_collection.steep.yaml +19 -0
  38. data/sample/sig/conference.rbs +8 -0
  39. data/sig/shims/parser/source/map.rbs +146 -0
  40. data/sig/shims/parser/source/range.rbs +237 -0
  41. data/sig/shims/parser.rbs +17 -0
  42. data/sig/steep/ast/annotation/collection.rbs +75 -0
  43. data/sig/steep/ast/annotation.rbs +126 -0
  44. data/sig/steep/ast/builtin.rbs +69 -0
  45. data/sig/steep/ast/type_params.rbs +11 -0
  46. data/sig/steep/ast/types/any.rbs +29 -0
  47. data/sig/steep/ast/types/boolean.rbs +31 -0
  48. data/sig/steep/ast/types/bot.rbs +29 -0
  49. data/sig/steep/ast/types/class.rbs +29 -0
  50. data/sig/steep/ast/types/factory.rbs +76 -0
  51. data/sig/steep/ast/types/helper.rbs +19 -0
  52. data/sig/steep/ast/types/instance.rbs +29 -0
  53. data/sig/steep/ast/types/intersection.rbs +35 -0
  54. data/sig/steep/ast/types/literal.rbs +33 -0
  55. data/sig/steep/ast/types/logic.rbs +78 -0
  56. data/sig/steep/ast/types/name.rbs +71 -0
  57. data/sig/steep/ast/types/nil.rbs +31 -0
  58. data/sig/steep/ast/types/proc.rbs +46 -0
  59. data/sig/steep/ast/types/record.rbs +38 -0
  60. data/sig/steep/ast/types/self.rbs +29 -0
  61. data/sig/steep/ast/types/top.rbs +29 -0
  62. data/sig/steep/ast/types/tuple.rbs +34 -0
  63. data/sig/steep/ast/types/union.rbs +38 -0
  64. data/sig/steep/ast/types/var.rbs +37 -0
  65. data/sig/steep/ast/types/void.rbs +29 -0
  66. data/sig/steep/ast/types.rbs +37 -0
  67. data/sig/steep/diagnostic/deprecated/unknown_constant_assigned.rbs +15 -0
  68. data/sig/steep/diagnostic/helper.rbs +9 -0
  69. data/sig/steep/diagnostic/lsp_formatter.rbs +29 -0
  70. data/sig/steep/diagnostic/ruby.rbs +494 -0
  71. data/sig/steep/diagnostic/signature.rbs +215 -0
  72. data/sig/steep/interface/block.rbs +35 -0
  73. data/sig/steep/interface/function.rbs +253 -0
  74. data/sig/steep/interface/interface.rbs +23 -0
  75. data/sig/steep/interface/method_type.rbs +55 -0
  76. data/sig/steep/interface/substitution.rbs +53 -0
  77. data/sig/steep/interface/type_param.rbs +35 -0
  78. data/sig/steep/method_name.rbs +26 -0
  79. data/sig/steep/module_helper.rbs +7 -0
  80. data/sig/steep/node_helper.rbs +11 -0
  81. data/sig/steep/project/dsl.rbs +94 -0
  82. data/sig/steep/project/options.rbs +15 -0
  83. data/sig/steep/project/pattern.rbs +25 -0
  84. data/sig/steep/project/target.rbs +25 -0
  85. data/sig/steep/project.rbs +19 -0
  86. data/sig/steep/services/completion_provider.rbs +123 -0
  87. data/sig/steep/services/content_change.rbs +35 -0
  88. data/sig/steep/services/file_loader.rbs +13 -0
  89. data/sig/steep/services/goto_service.rbs +45 -0
  90. data/sig/steep/services/hover_provider/rbs.rbs +21 -0
  91. data/sig/steep/services/hover_provider/ruby.rbs +109 -0
  92. data/sig/steep/services/hover_provider/singleton_methods.rbs +11 -0
  93. data/sig/steep/services/path_assignment.rbs +21 -0
  94. data/sig/steep/services/signature_service.rbs +91 -0
  95. data/sig/steep/services/stats_calculator.rbs +17 -0
  96. data/sig/steep/services/type_check_service.rbs +93 -0
  97. data/sig/steep/source.rbs +55 -0
  98. data/sig/steep/subtyping/cache.rbs +17 -0
  99. data/sig/steep/subtyping/check.rbs +93 -0
  100. data/sig/steep/subtyping/constraints.rbs +111 -0
  101. data/sig/steep/subtyping/relation.rbs +51 -0
  102. data/sig/steep/subtyping/result.rbs +157 -0
  103. data/sig/steep/subtyping/variable_variance.rbs +23 -0
  104. data/sig/steep/type_construction.rbs +285 -0
  105. data/sig/steep/type_inference/block_params.rbs +52 -0
  106. data/sig/steep/type_inference/constant_env.rbs +27 -0
  107. data/sig/steep/type_inference/context.rbs +137 -0
  108. data/sig/steep/type_inference/logic_type_interpreter.rbs +72 -0
  109. data/sig/steep/type_inference/method_call.rbs +124 -0
  110. data/sig/steep/type_inference/method_params.rbs +104 -0
  111. data/sig/steep/type_inference/multiple_assignment.rbs +76 -0
  112. data/sig/steep/type_inference/type_env.rbs +158 -0
  113. data/sig/steep/type_inference/type_env_builder.rbs +77 -0
  114. data/sig/steep/typing.rbs +68 -0
  115. data/sig/steep.rbs +31 -0
  116. data/smoke/class/f.rb +1 -0
  117. data/smoke/class/test_expectations.yml +2 -2
  118. data/smoke/diagnostics/test_expectations.yml +4 -2
  119. metadata +90 -6
  120. data/lib/steep/type_inference/local_variable_type_env.rb +0 -249
  121. data/lib/steep/type_inference/logic.rb +0 -161
@@ -0,0 +1,93 @@
1
+ module Steep
2
+ module Subtyping
3
+ class Check
4
+ attr_reader factory: AST::Types::Factory
5
+
6
+ attr_reader cache: untyped
7
+
8
+ attr_reader assumptions: untyped
9
+
10
+ def initialize: (factory: untyped) -> void
11
+
12
+ def with_context: (self_type: untyped, instance_type: untyped, class_type: untyped, constraints: untyped) { () -> untyped } -> untyped
13
+
14
+ def push_assumption: (untyped relation) { () -> untyped } -> untyped
15
+
16
+ def push_variable_bounds: (untyped params) { () -> untyped } -> untyped
17
+
18
+ def variable_upper_bound: (untyped name) -> (untyped | nil)
19
+
20
+ def self_type: () -> untyped
21
+
22
+ def instance_type: () -> untyped
23
+
24
+ def class_type: () -> untyped
25
+
26
+ def constraints: () -> untyped
27
+
28
+ def each_ancestor: (untyped ancestors) { (untyped) -> untyped } -> untyped
29
+
30
+ def instance_super_types: (untyped type_name, args: untyped) -> untyped
31
+
32
+ def singleton_super_types: (untyped type_name) -> untyped
33
+
34
+ def check: (untyped relation, constraints: untyped, self_type: untyped, instance_type: untyped, class_type: untyped) -> untyped
35
+
36
+ def check_type: (untyped relation) -> untyped
37
+
38
+ def cache_bounds: (untyped relation) -> untyped
39
+
40
+ def alias?: (untyped `type`) -> untyped
41
+
42
+ def cacheable?: (untyped relation) -> untyped
43
+
44
+ def true_type?: (untyped `type`) -> untyped
45
+
46
+ def false_type?: (untyped `type`) -> untyped
47
+
48
+ include Result::Helper
49
+
50
+ def check_type0: (untyped relation) -> untyped
51
+
52
+ def definition_for_type: (untyped `type`) -> untyped
53
+
54
+ def arg_type?: (untyped `type`) -> untyped
55
+
56
+ def check_type_arg: (untyped relation) -> untyped
57
+
58
+ def same_type?: (untyped relation) -> (true | untyped)
59
+
60
+ def check_interface: (untyped relation) -> untyped
61
+
62
+ def check_method: (untyped name, untyped relation) -> untyped
63
+
64
+ def check_type_application: (untyped result, untyped type_params, untyped type_args) { () -> untyped } -> untyped
65
+
66
+ def check_generic_method_type: (untyped name, untyped relation) -> untyped
67
+
68
+ def check_constraints: (untyped relation, variables: untyped, variance: untyped) -> untyped
69
+
70
+ def check_method_type: (untyped name, untyped relation) -> untyped
71
+
72
+ def check_block_given: (untyped name, untyped relation) { () -> untyped } -> untyped
73
+
74
+ def check_function: (untyped name, untyped relation) -> untyped
75
+
76
+ def check_method_params: (untyped name, untyped relation) -> untyped
77
+
78
+ # ```rbs
79
+ # (Symbol, Relation[MethodType]) -> (Array[[Symbol, Symbol]] | Result::t)
80
+ # [A] (Symbol, Relation[MethodType]) { (Array[[Symbol, Symbol]]) -> A } -> (A | Result::t)
81
+ # ````
82
+ def match_method_type: (untyped name, untyped relation) { (untyped) -> untyped } -> untyped
83
+
84
+ def match_params: (untyped name, untyped relation) -> untyped
85
+
86
+ def expand_alias: (untyped `type`) { () -> untyped } -> untyped
87
+
88
+ # Returns the shortest type paths for one of the _unknown_ type variables.
89
+ # Returns nil if there is no path.
90
+ def hole_path: (untyped `type`, ?untyped path) -> untyped
91
+ end
92
+ end
93
+ end
@@ -0,0 +1,111 @@
1
+ module Steep
2
+ module Subtyping
3
+ class Constraints
4
+ class UnsatisfiedInvariantError < StandardError
5
+ attr_reader constraints: untyped
6
+
7
+ attr_reader reason: untyped
8
+
9
+ def initialize: (reason: untyped, constraints: untyped) -> void
10
+
11
+ class VariablesUnknownsNotDisjoint
12
+ attr_reader vars: untyped
13
+
14
+ def initialize: (vars: untyped) -> void
15
+
16
+ def message: () -> ::String
17
+ end
18
+
19
+ class VariablesFreeVariablesNotDisjoint
20
+ attr_reader var: untyped
21
+
22
+ attr_reader lower_bound: untyped
23
+
24
+ attr_reader upper_bound: untyped
25
+
26
+ def initialize: (?var: untyped?, ?lower_bound: untyped?, ?upper_bound: untyped?) -> void
27
+
28
+ def message: () -> ::String
29
+ end
30
+
31
+ class UnknownsFreeVariableNotDisjoint
32
+ attr_reader var: untyped
33
+
34
+ attr_reader upper_bound: untyped
35
+
36
+ attr_reader lower_bound: untyped
37
+
38
+ def initialize: (var: untyped, lower_bound: untyped, upper_bound: untyped) -> void
39
+
40
+ def message: () -> ::String
41
+ end
42
+ end
43
+
44
+ class UnsatisfiableConstraint < StandardError
45
+ attr_reader var: untyped
46
+
47
+ attr_reader sub_type: untyped
48
+
49
+ attr_reader super_type: untyped
50
+
51
+ attr_reader result: untyped
52
+
53
+ def initialize: (var: untyped, sub_type: untyped, super_type: untyped, result: untyped) -> void
54
+ end
55
+
56
+ class Context
57
+ attr_reader variance: untyped
58
+
59
+ attr_reader self_type: AST::Types::t
60
+
61
+ attr_reader instance_type: AST::Types::t
62
+
63
+ attr_reader class_type: AST::Types::t
64
+
65
+ def initialize: (variance: untyped, self_type: AST::Types::t, instance_type: AST::Types::t, class_type: AST::Types::t) -> void
66
+ end
67
+
68
+ attr_reader dictionary: Hash[Symbol, [Set[AST::Types::t], Set[AST::Types::t], Set[AST::Types::t]]]
69
+
70
+ attr_reader vars: Set[Symbol]
71
+
72
+ def initialize: (unknowns: _Each[Symbol]) -> void
73
+
74
+ def self.empty: () -> Constraints
75
+
76
+ def add_var: (*Symbol vars) -> void
77
+
78
+ def add: (Symbol var, ?sub_type: untyped?, ?super_type: untyped?, ?skip: bool) -> untyped
79
+
80
+ def eliminate_variable: (AST::Types::t `type`, to: AST::Types::t) -> AST::Types::t
81
+
82
+ def unknown?: (Symbol var) -> bool
83
+
84
+ def unknowns: () -> Set[Symbol]
85
+
86
+ def unknown!: (Symbol var) -> void
87
+
88
+ def empty?: () -> bool
89
+
90
+ def upper_bound: (Symbol var, ?skip: bool) -> AST::Types::t
91
+
92
+ def lower_bound: (Symbol var, ?skip: bool) -> AST::Types::t
93
+
94
+ def solution: (Check checker, variables: Enumerable[Symbol], variance: VariableVariance, self_type: AST::Types::t, instance_type: AST::Types::t, class_type: AST::Types::t) -> Interface::Substitution
95
+ | (Check checker, variables: Enumerable[Symbol], context: Context) -> Interface::Substitution
96
+
97
+ def has_constraint?: (Symbol var) -> bool
98
+
99
+ def each: () { ([Symbol, AST::Types::t, AST::Types::t]) -> void } -> void
100
+ | () -> Enumerator[[Symbol, AST::Types::t, AST::Types::t], void]
101
+
102
+ def to_s: () -> ::String
103
+
104
+ private
105
+
106
+ def lower_bound_types: (Symbol var_name) -> Set[AST::Types::t]
107
+
108
+ def upper_bound_types: (Symbol var_name) -> Set[AST::Types::t]
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,51 @@
1
+ module Steep
2
+ module Subtyping
3
+ class Relation
4
+ attr_reader sub_type: untyped
5
+
6
+ attr_reader super_type: untyped
7
+
8
+ def initialize: (sub_type: untyped, super_type: untyped) -> void
9
+
10
+ def hash: () -> untyped
11
+
12
+ def ==: (untyped other) -> untyped
13
+
14
+ alias eql? ==
15
+
16
+ def to_s: () -> ::String
17
+
18
+ def to_ary: () -> ::Array[untyped]
19
+
20
+ def type?: () -> untyped
21
+
22
+ def interface?: () -> untyped
23
+
24
+ def method?: () -> untyped
25
+
26
+ def function?: () -> untyped
27
+
28
+ def params?: () -> untyped
29
+
30
+ def block?: () -> untyped
31
+
32
+ def assert_type: (untyped `type`) -> (untyped | nil)
33
+
34
+ def type!: () -> untyped
35
+
36
+ def interface!: () -> untyped
37
+
38
+ def method!: () -> untyped
39
+
40
+ def function!: () -> untyped
41
+
42
+ def params!: () -> untyped
43
+
44
+ def block!: () -> untyped
45
+
46
+ def map: () { (untyped) -> untyped } -> untyped
47
+
48
+ def flip: () -> untyped
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,157 @@
1
+ module Steep
2
+ module Subtyping
3
+ module Result
4
+ type t = Skip | Expand | All | Any | Success | Failure
5
+
6
+ class Base
7
+ attr_reader relation: Relation
8
+
9
+ def initialize: (Relation relation) -> void
10
+
11
+ def failure?: () -> bool
12
+
13
+ def success?: () -> bool
14
+
15
+ def then: [A] () { (self) -> A } -> A
16
+
17
+ def else: [A] () { (self) -> A } -> A
18
+
19
+ def failure_path: (?untyped path) -> untyped
20
+ end
21
+
22
+ class Skip < Base
23
+ def success?: () -> false
24
+
25
+ def failure?: () -> false
26
+
27
+ def failure_path: (?untyped path) -> untyped
28
+ end
29
+
30
+ class Expand < Base
31
+ attr_reader child: untyped
32
+
33
+ def initialize: (untyped relation) { (untyped) -> untyped } -> void
34
+
35
+ def success?: () -> untyped
36
+
37
+ def failure_path: (?untyped path) -> (untyped | nil)
38
+ end
39
+
40
+ class All < Base
41
+ attr_reader branches: untyped
42
+
43
+ def initialize: (untyped relation) -> void
44
+
45
+ # Returns `false` if no future `#add` changes the result.
46
+ def add: (*untyped relations) { (untyped) -> untyped } -> untyped
47
+
48
+ def success?: () -> untyped
49
+
50
+ def failure?: () -> untyped
51
+
52
+ def failure_path: (?untyped path) -> (untyped | nil)
53
+ end
54
+
55
+ class Any < Base
56
+ attr_reader branches: untyped
57
+
58
+ def initialize: (untyped relation) -> void
59
+
60
+ # Returns `false` if no future `#add` changes the result.
61
+ def add: (*untyped relations) { (untyped) -> untyped } -> untyped
62
+
63
+ def success?: () -> untyped
64
+
65
+ def failure_path: (?untyped path) -> (untyped | nil)
66
+ end
67
+
68
+ class Success < Base
69
+ def success?: () -> true
70
+
71
+ def failure_path: (?untyped path) -> nil
72
+ end
73
+
74
+ class Failure < Base
75
+ class MethodMissingError
76
+ attr_reader name: untyped
77
+
78
+ def initialize: (name: untyped) -> void
79
+
80
+ def message: () -> ::String
81
+ end
82
+
83
+ class BlockMismatchError
84
+ attr_reader name: untyped
85
+
86
+ def initialize: (name: untyped) -> void
87
+
88
+ def message: () -> ::String
89
+ end
90
+
91
+ class ParameterMismatchError
92
+ attr_reader name: untyped
93
+
94
+ def initialize: (name: untyped) -> void
95
+
96
+ def message: () -> ::String
97
+ end
98
+
99
+ class UnknownPairError
100
+ attr_reader relation: untyped
101
+
102
+ def initialize: (relation: untyped) -> void
103
+
104
+ def message: () -> ::String
105
+ end
106
+
107
+ class PolyMethodSubtyping
108
+ attr_reader name: untyped
109
+
110
+ def initialize: (name: untyped) -> void
111
+
112
+ def message: () -> ::String
113
+ end
114
+
115
+ class UnsatisfiedConstraints
116
+ attr_reader error: untyped
117
+
118
+ def initialize: (untyped error) -> void
119
+
120
+ def var: () -> untyped
121
+
122
+ def sub_type: () -> untyped
123
+
124
+ def super_type: () -> untyped
125
+
126
+ def result: () -> untyped
127
+
128
+ def message: () -> ::String
129
+ end
130
+
131
+ attr_reader error: untyped
132
+
133
+ def initialize: (untyped relation, untyped error) -> void
134
+
135
+ def success?: () -> false
136
+
137
+ def failure_path: (?untyped path) -> untyped
138
+ end
139
+
140
+ module Helper
141
+ def Skip: (untyped relation) -> untyped
142
+
143
+ def Expand: (untyped relation) { () -> untyped } -> untyped
144
+
145
+ def All: (untyped relation) { () -> untyped } -> untyped
146
+
147
+ def Any: (untyped relation) { () -> untyped } -> untyped
148
+
149
+ def Success: (untyped relation) -> untyped
150
+
151
+ alias success Success
152
+
153
+ def Failure: (untyped relation, ?untyped? error) { () -> untyped } -> untyped
154
+ end
155
+ end
156
+ end
157
+ end
@@ -0,0 +1,23 @@
1
+ module Steep
2
+ module Subtyping
3
+ class VariableVariance
4
+ attr_reader covariants: untyped
5
+
6
+ attr_reader contravariants: untyped
7
+
8
+ def initialize: (covariants: untyped, contravariants: untyped) -> void
9
+
10
+ def covariant?: (untyped var) -> untyped
11
+
12
+ def contravariant?: (untyped var) -> untyped
13
+
14
+ def invariant?: (untyped var) -> untyped
15
+
16
+ def self.from_method_type: (untyped method_type) -> untyped
17
+
18
+ def self.add_params: (untyped params, block: untyped, covariants: untyped, contravariants: untyped) -> untyped
19
+
20
+ def self.add_type: (untyped `type`, variance: untyped, covariants: untyped, contravariants: untyped) -> untyped
21
+ end
22
+ end
23
+ end