steep 0.44.0 → 0.47.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +8 -0
- data/.github/workflows/ruby.yml +3 -2
- data/.gitignore +0 -1
- data/CHANGELOG.md +42 -0
- data/Gemfile +0 -3
- data/Gemfile.lock +75 -0
- data/README.md +2 -1
- data/lib/steep/annotation_parser.rb +1 -1
- data/lib/steep/ast/builtin.rb +7 -1
- data/lib/steep/ast/types/factory.rb +19 -25
- data/lib/steep/cli.rb +7 -1
- data/lib/steep/diagnostic/lsp_formatter.rb +59 -6
- data/lib/steep/diagnostic/ruby.rb +188 -60
- data/lib/steep/diagnostic/signature.rb +38 -15
- data/lib/steep/drivers/check.rb +3 -0
- data/lib/steep/drivers/init.rb +10 -3
- data/lib/steep/drivers/utils/driver_helper.rb +15 -0
- data/lib/steep/drivers/validate.rb +1 -1
- data/lib/steep/drivers/watch.rb +3 -0
- data/lib/steep/equatable.rb +21 -0
- data/lib/steep/interface/function.rb +798 -579
- data/lib/steep/project/dsl.rb +135 -36
- data/lib/steep/project/options.rb +13 -53
- data/lib/steep/project/target.rb +22 -8
- data/lib/steep/server/interaction_worker.rb +245 -26
- data/lib/steep/server/master.rb +2 -2
- data/lib/steep/server/type_check_worker.rb +6 -9
- data/lib/steep/services/file_loader.rb +26 -19
- data/lib/steep/services/goto_service.rb +1 -0
- data/lib/steep/services/hover_content.rb +135 -80
- data/lib/steep/source.rb +12 -11
- data/lib/steep/type_construction.rb +435 -502
- data/lib/steep/type_inference/block_params.rb +3 -6
- data/lib/steep/type_inference/method_params.rb +483 -0
- data/lib/steep/type_inference/send_args.rb +599 -128
- data/lib/steep/typing.rb +46 -21
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +4 -2
- data/sample/Steepfile +10 -3
- data/smoke/alias/Steepfile +2 -1
- data/smoke/and/Steepfile +2 -1
- data/smoke/array/Steepfile +2 -1
- data/smoke/array/test_expectations.yml +3 -3
- data/smoke/block/Steepfile +2 -2
- data/smoke/block/c.rb +0 -1
- data/smoke/case/Steepfile +2 -1
- data/smoke/class/Steepfile +2 -1
- data/smoke/class/test_expectations.yml +12 -15
- data/smoke/const/Steepfile +2 -1
- data/smoke/diagnostics/Steepfile +2 -1
- data/smoke/diagnostics/different_method_parameter_kind.rb +9 -0
- data/smoke/diagnostics/method_arity_mismatch.rb +2 -2
- data/smoke/diagnostics/method_parameter_mismatch.rb +10 -0
- data/smoke/diagnostics/test_expectations.yml +108 -31
- data/smoke/diagnostics-rbs/Steepfile +1 -1
- data/smoke/diagnostics-rbs/mixin-class-error.rbs +6 -0
- data/smoke/diagnostics-rbs/test_expectations.yml +12 -0
- data/smoke/diagnostics-rbs-duplicated/Steepfile +2 -1
- data/smoke/diagnostics-ruby-unsat/Steepfile +2 -1
- data/smoke/dstr/Steepfile +2 -1
- data/smoke/ensure/Steepfile +2 -1
- data/smoke/ensure/test_expectations.yml +3 -3
- data/smoke/enumerator/Steepfile +2 -1
- data/smoke/enumerator/test_expectations.yml +1 -1
- data/smoke/extension/Steepfile +2 -1
- data/smoke/extension/e.rbs +1 -1
- data/smoke/hash/Steepfile +2 -1
- data/smoke/hello/Steepfile +2 -1
- data/smoke/if/Steepfile +2 -1
- data/smoke/implements/Steepfile +2 -1
- data/smoke/initialize/Steepfile +2 -1
- data/smoke/integer/Steepfile +2 -1
- data/smoke/interface/Steepfile +2 -1
- data/smoke/kwbegin/Steepfile +2 -1
- data/smoke/lambda/Steepfile +2 -1
- data/smoke/literal/Steepfile +2 -1
- data/smoke/literal/test_expectations.yml +2 -2
- data/smoke/map/Steepfile +2 -1
- data/smoke/method/Steepfile +2 -1
- data/smoke/method/test_expectations.yml +11 -10
- data/smoke/module/Steepfile +2 -1
- data/smoke/regexp/Steepfile +2 -1
- data/smoke/regression/Steepfile +2 -1
- data/smoke/rescue/Steepfile +2 -1
- data/smoke/rescue/test_expectations.yml +3 -3
- data/smoke/self/Steepfile +2 -1
- data/smoke/skip/Steepfile +2 -1
- data/smoke/stdout/Steepfile +2 -1
- data/smoke/super/Steepfile +2 -1
- data/smoke/toplevel/Steepfile +2 -1
- data/smoke/toplevel/test_expectations.yml +3 -3
- data/smoke/tsort/Steepfile +4 -5
- data/smoke/tsort/test_expectations.yml +2 -2
- data/smoke/type_case/Steepfile +2 -1
- data/smoke/unexpected/Steepfile +2 -1
- data/smoke/yield/Steepfile +2 -1
- data/steep.gemspec +2 -2
- metadata +16 -10
- data/sig/project.rbi +0 -109
data/lib/steep/typing.rb
CHANGED
@@ -102,13 +102,20 @@ module Steep
|
|
102
102
|
end
|
103
103
|
|
104
104
|
def block_range(node)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
105
|
+
case node.type
|
106
|
+
when :block
|
107
|
+
send_node, args_node, _ = node.children
|
108
|
+
begin_pos = if send_node.type != :lambda && args_node.loc.expression
|
109
|
+
args_node.loc.expression.end_pos
|
110
|
+
else
|
111
|
+
node.loc.begin.end_pos
|
112
|
+
end
|
113
|
+
end_pos = node.loc.end.begin_pos
|
114
|
+
when :numblock
|
115
|
+
send_node, _ = node.children
|
116
|
+
begin_pos = node.loc.begin.end_pos
|
117
|
+
end_pos = node.loc.end.begin_pos
|
118
|
+
end
|
112
119
|
|
113
120
|
begin_pos..end_pos
|
114
121
|
end
|
@@ -139,21 +146,39 @@ module Steep
|
|
139
146
|
add_context(begin_pos..end_pos, context: context)
|
140
147
|
|
141
148
|
when :def, :defs
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
149
|
+
if node.children.last
|
150
|
+
args_node =
|
151
|
+
case node.type
|
152
|
+
when :def
|
153
|
+
node.children[1]
|
154
|
+
when :defs
|
155
|
+
node.children[2]
|
156
|
+
end
|
157
|
+
|
158
|
+
body_begin_pos =
|
159
|
+
case
|
160
|
+
when node.loc.assignment
|
161
|
+
# endless def
|
162
|
+
node.loc.assignment.end_pos
|
163
|
+
when args_node.loc.expression
|
164
|
+
# with args
|
165
|
+
args_node.loc.expression.end_pos
|
166
|
+
else
|
167
|
+
# without args
|
168
|
+
node.loc.name.end_pos
|
169
|
+
end
|
170
|
+
|
171
|
+
body_end_pos =
|
172
|
+
if node.loc.end
|
173
|
+
node.loc.end.begin_pos
|
174
|
+
else
|
175
|
+
node.loc.expression.end_pos
|
176
|
+
end
|
177
|
+
|
178
|
+
add_context(body_begin_pos..body_end_pos, context: context)
|
179
|
+
end
|
155
180
|
|
156
|
-
when :block
|
181
|
+
when :block, :numblock
|
157
182
|
range = block_range(node)
|
158
183
|
add_context(range, context: context)
|
159
184
|
|
data/lib/steep/version.rb
CHANGED
data/lib/steep.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require "steep/version"
|
2
2
|
|
3
3
|
require "pathname"
|
4
|
-
require "parser/
|
4
|
+
require "parser/ruby30"
|
5
5
|
require "active_support/core_ext/object/try"
|
6
6
|
require "active_support/core_ext/string/inflections"
|
7
7
|
require "logger"
|
@@ -21,6 +21,7 @@ require "terminal-table"
|
|
21
21
|
|
22
22
|
require "rbs"
|
23
23
|
|
24
|
+
require "steep/equatable"
|
24
25
|
require "steep/method_name"
|
25
26
|
require "steep/ast/types/helper"
|
26
27
|
require "steep/ast/types/any"
|
@@ -77,6 +78,7 @@ require "steep/type_inference/context"
|
|
77
78
|
require "steep/type_inference/context_array"
|
78
79
|
require "steep/type_inference/send_args"
|
79
80
|
require "steep/type_inference/block_params"
|
81
|
+
require "steep/type_inference/method_params"
|
80
82
|
require "steep/type_inference/constant_env"
|
81
83
|
require "steep/type_inference/type_env"
|
82
84
|
require "steep/type_inference/local_variable_type_env"
|
@@ -211,7 +213,7 @@ module Steep
|
|
211
213
|
end
|
212
214
|
|
213
215
|
def percentile(p)
|
214
|
-
slowests(count
|
216
|
+
slowests([count * p / 100r, 1].max).last&.last || 0
|
215
217
|
end
|
216
218
|
end
|
217
219
|
|
data/sample/Steepfile
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
D = Steep::Diagnostic
|
2
|
+
|
3
|
+
target :lib do
|
3
4
|
signature "sig"
|
4
5
|
|
5
|
-
|
6
|
+
check "lib" # Directory name
|
7
|
+
|
8
|
+
# configure_code_diagnostics(D::Ruby.strict) # `strict` diagnostics setting
|
9
|
+
# configure_code_diagnostics(D::Ruby.lenient) # `lenient` diagnostics setting
|
10
|
+
# configure_code_diagnostics do |hash| # You can setup everything yourself
|
11
|
+
# hash[D::Ruby::NoMethod] = :information
|
12
|
+
# end
|
6
13
|
end
|
data/smoke/alias/Steepfile
CHANGED
data/smoke/and/Steepfile
CHANGED
data/smoke/array/Steepfile
CHANGED
@@ -16,9 +16,9 @@
|
|
16
16
|
| (::int, ::int, ::Integer) -> ::Integer
|
17
17
|
| (::int, ::int, ::Array[::Integer]) -> ::Array[::Integer]
|
18
18
|
| (::int, ::int, nil) -> nil
|
19
|
-
| (::Range[::Integer], ::Integer) -> ::Integer
|
20
|
-
| (::Range[::Integer], ::Array[::Integer]) -> ::Array[::Integer]
|
21
|
-
| (::Range[::Integer], nil) -> nil
|
19
|
+
| (::Range[(::Integer | nil)], ::Integer) -> ::Integer
|
20
|
+
| (::Range[(::Integer | nil)], ::Array[::Integer]) -> ::Array[::Integer]
|
21
|
+
| (::Range[(::Integer | nil)], nil) -> nil
|
22
22
|
code: Ruby::UnresolvedOverloading
|
23
23
|
- range:
|
24
24
|
start:
|
data/smoke/block/Steepfile
CHANGED
data/smoke/block/c.rb
CHANGED
data/smoke/case/Steepfile
CHANGED
data/smoke/class/Steepfile
CHANGED
@@ -4,20 +4,20 @@
|
|
4
4
|
- range:
|
5
5
|
start:
|
6
6
|
line: 8
|
7
|
-
character:
|
7
|
+
character: 10
|
8
8
|
end:
|
9
9
|
line: 8
|
10
|
-
character:
|
10
|
+
character: 11
|
11
11
|
severity: ERROR
|
12
|
-
message:
|
13
|
-
code: Ruby::
|
12
|
+
message: The method parameter is incompatible with the declaration `() -> ::String`
|
13
|
+
code: Ruby::MethodParameterMismatch
|
14
14
|
- range:
|
15
15
|
start:
|
16
16
|
line: 13
|
17
|
-
character:
|
17
|
+
character: 6
|
18
18
|
end:
|
19
|
-
line:
|
20
|
-
character:
|
19
|
+
line: 13
|
20
|
+
character: 10
|
21
21
|
severity: ERROR
|
22
22
|
message: |-
|
23
23
|
Cannot allow method body have type `::Integer` because declared as type `::String`
|
@@ -29,10 +29,10 @@
|
|
29
29
|
- range:
|
30
30
|
start:
|
31
31
|
line: 22
|
32
|
-
character:
|
32
|
+
character: 11
|
33
33
|
end:
|
34
|
-
line:
|
35
|
-
character:
|
34
|
+
line: 22
|
35
|
+
character: 14
|
36
36
|
severity: ERROR
|
37
37
|
message: |-
|
38
38
|
Cannot allow method body have type `::String` because declared as type `::Integer`
|
@@ -113,8 +113,5 @@
|
|
113
113
|
line: 10
|
114
114
|
character: 11
|
115
115
|
severity: ERROR
|
116
|
-
message:
|
117
|
-
|
118
|
-
Method types:
|
119
|
-
def initialize: (name: ::String) -> untyped
|
120
|
-
code: Ruby::IncompatibleArguments
|
116
|
+
message: 'More keyword arguments are required: name'
|
117
|
+
code: Ruby::InsufficientKeywordArguments
|
data/smoke/const/Steepfile
CHANGED
data/smoke/diagnostics/Steepfile
CHANGED
@@ -63,6 +63,52 @@
|
|
63
63
|
::Object <: ::Integer
|
64
64
|
::BasicObject <: ::Integer
|
65
65
|
code: Ruby::BreakTypeMismatch
|
66
|
+
- file: different_method_parameter_kind.rb
|
67
|
+
diagnostics:
|
68
|
+
- range:
|
69
|
+
start:
|
70
|
+
line: 3
|
71
|
+
character: 10
|
72
|
+
end:
|
73
|
+
line: 3
|
74
|
+
character: 15
|
75
|
+
severity: ERROR
|
76
|
+
message: The method parameter has different kind from the declaration `(::Integer,
|
77
|
+
::String) -> void`
|
78
|
+
code: Ruby::DifferentMethodParameterKind
|
79
|
+
- range:
|
80
|
+
start:
|
81
|
+
line: 3
|
82
|
+
character: 17
|
83
|
+
end:
|
84
|
+
line: 3
|
85
|
+
character: 19
|
86
|
+
severity: ERROR
|
87
|
+
message: The method parameter has different kind from the declaration `(::Integer,
|
88
|
+
::String) -> void`
|
89
|
+
code: Ruby::DifferentMethodParameterKind
|
90
|
+
- range:
|
91
|
+
start:
|
92
|
+
line: 7
|
93
|
+
character: 10
|
94
|
+
end:
|
95
|
+
line: 7
|
96
|
+
character: 21
|
97
|
+
severity: ERROR
|
98
|
+
message: 'The method parameter has different kind from the declaration `(name:
|
99
|
+
::String, size: ::Integer) -> void`'
|
100
|
+
code: Ruby::DifferentMethodParameterKind
|
101
|
+
- range:
|
102
|
+
start:
|
103
|
+
line: 7
|
104
|
+
character: 23
|
105
|
+
end:
|
106
|
+
line: 7
|
107
|
+
character: 29
|
108
|
+
severity: ERROR
|
109
|
+
message: 'The method parameter has different kind from the declaration `(name:
|
110
|
+
::String, size: ::Integer) -> void`'
|
111
|
+
code: Ruby::DifferentMethodParameterKind
|
66
112
|
- file: else_on_exhaustive_case.rb
|
67
113
|
diagnostics:
|
68
114
|
- range:
|
@@ -96,16 +142,23 @@
|
|
96
142
|
- range:
|
97
143
|
start:
|
98
144
|
line: 1
|
99
|
-
character:
|
145
|
+
character: 11
|
100
146
|
end:
|
101
147
|
line: 1
|
102
|
-
character:
|
148
|
+
character: 12
|
103
149
|
severity: ERROR
|
104
|
-
message:
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
150
|
+
message: Unexpected positional argument
|
151
|
+
code: Ruby::UnexpectedPositionalArgument
|
152
|
+
- range:
|
153
|
+
start:
|
154
|
+
line: 1
|
155
|
+
character: 13
|
156
|
+
end:
|
157
|
+
line: 1
|
158
|
+
character: 14
|
159
|
+
severity: ERROR
|
160
|
+
message: Unexpected positional argument
|
161
|
+
code: Ruby::UnexpectedPositionalArgument
|
109
162
|
- file: incompatible_assignment.rb
|
110
163
|
diagnostics:
|
111
164
|
- range:
|
@@ -160,9 +213,10 @@
|
|
160
213
|
character: 9
|
161
214
|
end:
|
162
215
|
line: 3
|
163
|
-
character:
|
216
|
+
character: 11
|
164
217
|
severity: ERROR
|
165
|
-
message: Method parameters are incompatible with declaration `()
|
218
|
+
message: 'Method parameters are incompatible with declaration `(name: ::String)
|
219
|
+
-> void`'
|
166
220
|
code: Ruby::MethodArityMismatch
|
167
221
|
- range:
|
168
222
|
start:
|
@@ -179,10 +233,10 @@
|
|
179
233
|
- range:
|
180
234
|
start:
|
181
235
|
line: 3
|
182
|
-
character:
|
236
|
+
character: 6
|
183
237
|
end:
|
184
|
-
line:
|
185
|
-
character:
|
238
|
+
line: 3
|
239
|
+
character: 9
|
186
240
|
severity: ERROR
|
187
241
|
message: |-
|
188
242
|
Cannot allow method body have type `::String` because declared as type `::Integer`
|
@@ -202,6 +256,41 @@
|
|
202
256
|
severity: ERROR
|
203
257
|
message: Cannot find implementation of method `::MethodDefinitionMissing#foo`
|
204
258
|
code: Ruby::MethodDefinitionMissing
|
259
|
+
- file: method_parameter_mismatch.rb
|
260
|
+
diagnostics:
|
261
|
+
- range:
|
262
|
+
start:
|
263
|
+
line: 3
|
264
|
+
character: 10
|
265
|
+
end:
|
266
|
+
line: 3
|
267
|
+
character: 11
|
268
|
+
severity: ERROR
|
269
|
+
message: The method parameter is incompatible with the declaration `(?::String,
|
270
|
+
*::Integer) -> void`
|
271
|
+
code: Ruby::MethodParameterMismatch
|
272
|
+
- range:
|
273
|
+
start:
|
274
|
+
line: 3
|
275
|
+
character: 13
|
276
|
+
end:
|
277
|
+
line: 3
|
278
|
+
character: 14
|
279
|
+
severity: ERROR
|
280
|
+
message: The method parameter is incompatible with the declaration `(?::String,
|
281
|
+
*::Integer) -> void`
|
282
|
+
code: Ruby::MethodParameterMismatch
|
283
|
+
- range:
|
284
|
+
start:
|
285
|
+
line: 7
|
286
|
+
character: 15
|
287
|
+
end:
|
288
|
+
line: 7
|
289
|
+
character: 20
|
290
|
+
severity: ERROR
|
291
|
+
message: 'The method parameter is incompatible with the declaration `(?name: ::String)
|
292
|
+
-> void`'
|
293
|
+
code: Ruby::MethodParameterMismatch
|
205
294
|
- file: method_return_type_annotation_mismatch.rb
|
206
295
|
diagnostics:
|
207
296
|
- range:
|
@@ -224,13 +313,13 @@
|
|
224
313
|
- range:
|
225
314
|
start:
|
226
315
|
line: 1
|
227
|
-
character:
|
316
|
+
character: 19
|
228
317
|
end:
|
229
318
|
line: 1
|
230
319
|
character: 32
|
231
320
|
severity: ERROR
|
232
|
-
message: '
|
233
|
-
code: Ruby::
|
321
|
+
message: 'More keyword arguments are required: foo'
|
322
|
+
code: Ruby::InsufficientKeywordArguments
|
234
323
|
- file: no_method.rb
|
235
324
|
diagnostics:
|
236
325
|
- range:
|
@@ -335,25 +424,13 @@
|
|
335
424
|
- range:
|
336
425
|
start:
|
337
426
|
line: 1
|
338
|
-
character:
|
339
|
-
end:
|
340
|
-
line: 1
|
341
|
-
character: 45
|
342
|
-
severity: ERROR
|
343
|
-
message: 'Cannot specify unexpected keyword arguments: `bar`'
|
344
|
-
code: Ruby::UnexpectedKeyword
|
345
|
-
- file: unexpected_splat.rb
|
346
|
-
diagnostics:
|
347
|
-
- range:
|
348
|
-
start:
|
349
|
-
line: 1
|
350
|
-
character: 13
|
427
|
+
character: 36
|
351
428
|
end:
|
352
429
|
line: 1
|
353
|
-
character:
|
430
|
+
character: 39
|
354
431
|
severity: ERROR
|
355
|
-
message:
|
356
|
-
code: Ruby::
|
432
|
+
message: Unexpected keyword argument
|
433
|
+
code: Ruby::UnexpectedKeywordArgument
|
357
434
|
- file: unexpected_yield.rb
|
358
435
|
diagnostics:
|
359
436
|
- range:
|
@@ -229,3 +229,15 @@
|
|
229
229
|
severity: ERROR
|
230
230
|
message: Cannot find type `ZZZ`
|
231
231
|
code: RBS::UnknownTypeName
|
232
|
+
- file: mixin-class-error.rbs
|
233
|
+
diagnostics:
|
234
|
+
- range:
|
235
|
+
start:
|
236
|
+
line: 5
|
237
|
+
character: 2
|
238
|
+
end:
|
239
|
+
line: 5
|
240
|
+
character: 13
|
241
|
+
severity: ERROR
|
242
|
+
message: Cannot include a class `::Foo` in the definition of `::Bar`
|
243
|
+
code: RBS::MixinClassError
|
data/smoke/dstr/Steepfile
CHANGED
data/smoke/ensure/Steepfile
CHANGED
@@ -32,10 +32,10 @@
|
|
32
32
|
- range:
|
33
33
|
start:
|
34
34
|
line: 13
|
35
|
-
character:
|
35
|
+
character: 4
|
36
36
|
end:
|
37
|
-
line:
|
38
|
-
character:
|
37
|
+
line: 13
|
38
|
+
character: 7
|
39
39
|
severity: ERROR
|
40
40
|
message: |-
|
41
41
|
Cannot allow method body have type `::Integer` because declared as type `::String`
|
data/smoke/enumerator/Steepfile
CHANGED
@@ -102,7 +102,7 @@
|
|
102
102
|
Cannot find compatible overloading of method `with_object` of type `::Enumerator[::Integer, ::Array[::Integer]]`
|
103
103
|
Method types:
|
104
104
|
def with_object: [U] (U) { (::Integer, U) -> untyped } -> U
|
105
|
-
| [U] (U) -> ::Enumerator[[::Integer, U],
|
105
|
+
| [U] (U) -> ::Enumerator[[::Integer, U], U]
|
106
106
|
code: Ruby::UnresolvedOverloading
|
107
107
|
- range:
|
108
108
|
start:
|
data/smoke/extension/Steepfile
CHANGED
data/smoke/extension/e.rbs
CHANGED
data/smoke/hash/Steepfile
CHANGED
data/smoke/hello/Steepfile
CHANGED
data/smoke/if/Steepfile
CHANGED