steep-activesupport-4 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.gitmodules +0 -0
- data/CHANGELOG.md +1032 -0
- data/LICENSE +21 -0
- data/README.md +260 -0
- data/Rakefile +227 -0
- data/Steepfile +68 -0
- data/bin/console +14 -0
- data/bin/generate-diagnostics-docs.rb +112 -0
- data/bin/mem_graph.rb +67 -0
- data/bin/mem_prof.rb +102 -0
- data/bin/output_rebaseline.rb +34 -0
- data/bin/output_test.rb +60 -0
- data/bin/rbs +20 -0
- data/bin/rbs-inline +19 -0
- data/bin/setup +9 -0
- data/bin/stackprof_test.rb +19 -0
- data/bin/steep +19 -0
- data/bin/steep-check.rb +251 -0
- data/bin/steep-prof +16 -0
- data/doc/narrowing.md +195 -0
- data/doc/shape.md +194 -0
- data/exe/steep +18 -0
- data/guides/README.md +5 -0
- data/guides/src/gem-rbs-collection/gem-rbs-collection.md +126 -0
- data/guides/src/getting-started/getting-started.md +163 -0
- data/guides/src/nil-optional/nil-optional.md +195 -0
- data/lib/steep/annotation_parser.rb +199 -0
- data/lib/steep/ast/annotation/collection.rb +172 -0
- data/lib/steep/ast/annotation.rb +137 -0
- data/lib/steep/ast/builtin.rb +104 -0
- data/lib/steep/ast/ignore.rb +148 -0
- data/lib/steep/ast/node/type_application.rb +88 -0
- data/lib/steep/ast/node/type_assertion.rb +81 -0
- data/lib/steep/ast/types/any.rb +35 -0
- data/lib/steep/ast/types/boolean.rb +45 -0
- data/lib/steep/ast/types/bot.rb +35 -0
- data/lib/steep/ast/types/class.rb +43 -0
- data/lib/steep/ast/types/factory.rb +557 -0
- data/lib/steep/ast/types/helper.rb +40 -0
- data/lib/steep/ast/types/instance.rb +42 -0
- data/lib/steep/ast/types/intersection.rb +93 -0
- data/lib/steep/ast/types/literal.rb +59 -0
- data/lib/steep/ast/types/logic.rb +84 -0
- data/lib/steep/ast/types/name.rb +128 -0
- data/lib/steep/ast/types/nil.rb +41 -0
- data/lib/steep/ast/types/proc.rb +117 -0
- data/lib/steep/ast/types/record.rb +79 -0
- data/lib/steep/ast/types/self.rb +43 -0
- data/lib/steep/ast/types/shared_instance.rb +11 -0
- data/lib/steep/ast/types/top.rb +35 -0
- data/lib/steep/ast/types/tuple.rb +60 -0
- data/lib/steep/ast/types/union.rb +97 -0
- data/lib/steep/ast/types/var.rb +65 -0
- data/lib/steep/ast/types/void.rb +35 -0
- data/lib/steep/cli.rb +401 -0
- data/lib/steep/diagnostic/deprecated/else_on_exhaustive_case.rb +20 -0
- data/lib/steep/diagnostic/deprecated/unknown_constant_assigned.rb +28 -0
- data/lib/steep/diagnostic/helper.rb +18 -0
- data/lib/steep/diagnostic/lsp_formatter.rb +78 -0
- data/lib/steep/diagnostic/result_printer2.rb +48 -0
- data/lib/steep/diagnostic/ruby.rb +1221 -0
- data/lib/steep/diagnostic/signature.rb +570 -0
- data/lib/steep/drivers/annotations.rb +52 -0
- data/lib/steep/drivers/check.rb +339 -0
- data/lib/steep/drivers/checkfile.rb +210 -0
- data/lib/steep/drivers/diagnostic_printer.rb +105 -0
- data/lib/steep/drivers/init.rb +66 -0
- data/lib/steep/drivers/langserver.rb +56 -0
- data/lib/steep/drivers/print_project.rb +113 -0
- data/lib/steep/drivers/stats.rb +203 -0
- data/lib/steep/drivers/utils/driver_helper.rb +143 -0
- data/lib/steep/drivers/utils/jobs_option.rb +26 -0
- data/lib/steep/drivers/vendor.rb +27 -0
- data/lib/steep/drivers/watch.rb +194 -0
- data/lib/steep/drivers/worker.rb +58 -0
- data/lib/steep/equatable.rb +23 -0
- data/lib/steep/expectations.rb +228 -0
- data/lib/steep/index/rbs_index.rb +350 -0
- data/lib/steep/index/signature_symbol_provider.rb +185 -0
- data/lib/steep/index/source_index.rb +167 -0
- data/lib/steep/interface/block.rb +103 -0
- data/lib/steep/interface/builder.rb +843 -0
- data/lib/steep/interface/function.rb +1090 -0
- data/lib/steep/interface/method_type.rb +330 -0
- data/lib/steep/interface/shape.rb +239 -0
- data/lib/steep/interface/substitution.rb +159 -0
- data/lib/steep/interface/type_param.rb +115 -0
- data/lib/steep/located_value.rb +20 -0
- data/lib/steep/method_name.rb +42 -0
- data/lib/steep/module_helper.rb +24 -0
- data/lib/steep/node_helper.rb +273 -0
- data/lib/steep/path_helper.rb +30 -0
- data/lib/steep/project/dsl.rb +268 -0
- data/lib/steep/project/group.rb +31 -0
- data/lib/steep/project/options.rb +63 -0
- data/lib/steep/project/pattern.rb +59 -0
- data/lib/steep/project/target.rb +92 -0
- data/lib/steep/project.rb +78 -0
- data/lib/steep/rake_task.rb +132 -0
- data/lib/steep/range_extension.rb +29 -0
- data/lib/steep/server/base_worker.rb +97 -0
- data/lib/steep/server/change_buffer.rb +73 -0
- data/lib/steep/server/custom_methods.rb +77 -0
- data/lib/steep/server/delay_queue.rb +45 -0
- data/lib/steep/server/interaction_worker.rb +492 -0
- data/lib/steep/server/lsp_formatter.rb +455 -0
- data/lib/steep/server/master.rb +912 -0
- data/lib/steep/server/target_group_files.rb +205 -0
- data/lib/steep/server/type_check_controller.rb +366 -0
- data/lib/steep/server/type_check_worker.rb +303 -0
- data/lib/steep/server/work_done_progress.rb +64 -0
- data/lib/steep/server/worker_process.rb +176 -0
- data/lib/steep/services/completion_provider.rb +802 -0
- data/lib/steep/services/content_change.rb +61 -0
- data/lib/steep/services/file_loader.rb +74 -0
- data/lib/steep/services/goto_service.rb +441 -0
- data/lib/steep/services/hover_provider/rbs.rb +88 -0
- data/lib/steep/services/hover_provider/ruby.rb +221 -0
- data/lib/steep/services/hover_provider/singleton_methods.rb +20 -0
- data/lib/steep/services/path_assignment.rb +46 -0
- data/lib/steep/services/signature_help_provider.rb +202 -0
- data/lib/steep/services/signature_service.rb +428 -0
- data/lib/steep/services/stats_calculator.rb +68 -0
- data/lib/steep/services/type_check_service.rb +394 -0
- data/lib/steep/services/type_name_completion.rb +236 -0
- data/lib/steep/signature/validator.rb +651 -0
- data/lib/steep/source/ignore_ranges.rb +69 -0
- data/lib/steep/source.rb +691 -0
- data/lib/steep/subtyping/cache.rb +30 -0
- data/lib/steep/subtyping/check.rb +1113 -0
- data/lib/steep/subtyping/constraints.rb +341 -0
- data/lib/steep/subtyping/relation.rb +101 -0
- data/lib/steep/subtyping/result.rb +324 -0
- data/lib/steep/subtyping/variable_variance.rb +89 -0
- data/lib/steep/test.rb +9 -0
- data/lib/steep/thread_waiter.rb +43 -0
- data/lib/steep/type_construction.rb +5183 -0
- data/lib/steep/type_inference/block_params.rb +416 -0
- data/lib/steep/type_inference/case_when.rb +303 -0
- data/lib/steep/type_inference/constant_env.rb +56 -0
- data/lib/steep/type_inference/context.rb +195 -0
- data/lib/steep/type_inference/logic_type_interpreter.rb +613 -0
- data/lib/steep/type_inference/method_call.rb +193 -0
- data/lib/steep/type_inference/method_params.rb +531 -0
- data/lib/steep/type_inference/multiple_assignment.rb +194 -0
- data/lib/steep/type_inference/send_args.rb +712 -0
- data/lib/steep/type_inference/type_env.rb +341 -0
- data/lib/steep/type_inference/type_env_builder.rb +138 -0
- data/lib/steep/typing.rb +321 -0
- data/lib/steep/version.rb +3 -0
- data/lib/steep.rb +369 -0
- data/manual/annotations.md +181 -0
- data/manual/ignore.md +20 -0
- data/manual/ruby-diagnostics.md +1879 -0
- data/sample/Steepfile +22 -0
- data/sample/lib/conference.rb +49 -0
- data/sample/lib/length.rb +35 -0
- data/sample/sig/conference.rbs +42 -0
- data/sample/sig/generics.rbs +15 -0
- data/sample/sig/length.rbs +34 -0
- data/steep-activesupport-4.gemspec +55 -0
- metadata +437 -0
@@ -0,0 +1,570 @@
|
|
1
|
+
module Steep
|
2
|
+
module Diagnostic
|
3
|
+
module Signature
|
4
|
+
class Base
|
5
|
+
include Helper
|
6
|
+
|
7
|
+
attr_reader :location
|
8
|
+
|
9
|
+
def initialize(location:)
|
10
|
+
@location = location
|
11
|
+
end
|
12
|
+
|
13
|
+
def header_line
|
14
|
+
raise
|
15
|
+
end
|
16
|
+
|
17
|
+
def detail_lines
|
18
|
+
nil
|
19
|
+
end
|
20
|
+
|
21
|
+
def diagnostic_code
|
22
|
+
"RBS::#{error_name}"
|
23
|
+
end
|
24
|
+
|
25
|
+
def path
|
26
|
+
if location
|
27
|
+
Pathname(location.buffer.name)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class SyntaxError < Base
|
33
|
+
attr_reader :exception
|
34
|
+
|
35
|
+
def initialize(exception, location:)
|
36
|
+
super(location: location)
|
37
|
+
@exception = exception
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.parser_syntax_error_message(exception)
|
41
|
+
string = exception.location.source.to_s
|
42
|
+
unless string.empty?
|
43
|
+
string = " (#{string})"
|
44
|
+
end
|
45
|
+
|
46
|
+
"Syntax error caused by token `#{exception.token_type}`#{string}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def header_line
|
50
|
+
exception.message
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
class DuplicatedDeclaration < Base
|
55
|
+
attr_reader :type_name
|
56
|
+
|
57
|
+
def initialize(type_name:, location:)
|
58
|
+
super(location: location)
|
59
|
+
@type_name = type_name
|
60
|
+
end
|
61
|
+
|
62
|
+
def header_line
|
63
|
+
"Declaration of `#{type_name}` is duplicated"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class UnknownTypeName < Base
|
68
|
+
attr_reader :name
|
69
|
+
|
70
|
+
def initialize(name:, location:)
|
71
|
+
super(location: location)
|
72
|
+
@name = name
|
73
|
+
end
|
74
|
+
|
75
|
+
def header_line
|
76
|
+
"Cannot find type `#{name}`"
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class InvalidTypeApplication < Base
|
81
|
+
attr_reader :name
|
82
|
+
attr_reader :args
|
83
|
+
attr_reader :params
|
84
|
+
|
85
|
+
def initialize(name:, args:, params:, location:)
|
86
|
+
super(location: location)
|
87
|
+
@name = name
|
88
|
+
@args = args
|
89
|
+
@params = params
|
90
|
+
end
|
91
|
+
|
92
|
+
def header_line
|
93
|
+
case
|
94
|
+
when params.empty?
|
95
|
+
"Type `#{name}` is not generic but used as a generic type with #{args.size} arguments"
|
96
|
+
when args.empty?
|
97
|
+
"Type `#{name}` is generic but used as a non generic type"
|
98
|
+
else
|
99
|
+
"Type `#{name}` expects #{params.size} arguments, but #{args.size} arguments are given"
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
class UnsatisfiableTypeApplication < Base
|
105
|
+
attr_reader :type_name
|
106
|
+
attr_reader :type_arg
|
107
|
+
attr_reader :type_param
|
108
|
+
attr_reader :result
|
109
|
+
|
110
|
+
include ResultPrinter2
|
111
|
+
|
112
|
+
def initialize(type_name:, type_arg:, type_param:, result:, location:)
|
113
|
+
super(location: location)
|
114
|
+
@type_name = type_name
|
115
|
+
@type_arg = type_arg
|
116
|
+
@type_param = type_param
|
117
|
+
@result = result
|
118
|
+
end
|
119
|
+
|
120
|
+
def header_line
|
121
|
+
"Type application of `#{type_name}` doesn't satisfy the constraints: #{type_arg} <: #{type_param.upper_bound}"
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class InvalidMethodOverload < Base
|
126
|
+
attr_reader :class_name
|
127
|
+
attr_reader :method_name
|
128
|
+
|
129
|
+
def initialize(class_name:, method_name:, location:)
|
130
|
+
super(location: location)
|
131
|
+
@class_name = class_name
|
132
|
+
@method_name = method_name
|
133
|
+
end
|
134
|
+
|
135
|
+
def header_line
|
136
|
+
"Cannot find a non-overloading definition of `#{method_name}` in `#{class_name}`"
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
class UnknownMethodAlias < Base
|
141
|
+
attr_reader :class_name
|
142
|
+
attr_reader :method_name
|
143
|
+
|
144
|
+
def initialize(class_name:, method_name:, location:)
|
145
|
+
super(location: location)
|
146
|
+
@class_name = class_name
|
147
|
+
@method_name = method_name
|
148
|
+
end
|
149
|
+
|
150
|
+
def header_line
|
151
|
+
"Cannot find the original method `#{method_name}` in `#{class_name}`"
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
class DuplicatedMethodDefinition < Base
|
156
|
+
attr_reader :class_name
|
157
|
+
attr_reader :method_name
|
158
|
+
|
159
|
+
def initialize(class_name:, method_name:, location:)
|
160
|
+
super(location: location)
|
161
|
+
@class_name = class_name
|
162
|
+
@method_name = method_name
|
163
|
+
end
|
164
|
+
|
165
|
+
def header_line
|
166
|
+
"Non-overloading method definition of `#{method_name}` in `#{class_name}` cannot be duplicated"
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
class RecursiveAlias < Base
|
171
|
+
attr_reader :class_name
|
172
|
+
attr_reader :names
|
173
|
+
|
174
|
+
def initialize(class_name:, names:, location:)
|
175
|
+
super(location: location)
|
176
|
+
@class_name = class_name
|
177
|
+
@names = names
|
178
|
+
end
|
179
|
+
|
180
|
+
def header_line
|
181
|
+
"Circular method alias is detected in `#{class_name}`: #{names.join(" -> ")}"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
class RecursiveAncestor < Base
|
186
|
+
attr_reader :ancestors
|
187
|
+
|
188
|
+
def initialize(ancestors:, location:)
|
189
|
+
super(location: location)
|
190
|
+
@ancestors = ancestors
|
191
|
+
end
|
192
|
+
|
193
|
+
def header_line
|
194
|
+
names = ancestors.map do |ancestor|
|
195
|
+
case ancestor
|
196
|
+
when RBS::Definition::Ancestor::Singleton
|
197
|
+
"singleton(#{ancestor.name})"
|
198
|
+
when RBS::Definition::Ancestor::Instance
|
199
|
+
if ancestor.args.empty?
|
200
|
+
ancestor.name.to_s
|
201
|
+
else
|
202
|
+
"#{ancestor.name}[#{ancestor.args.join(", ")}]"
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
"Circular inheritance/mix-in is detected: #{names.join(" <: ")}"
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
class SuperclassMismatch < Base
|
212
|
+
attr_reader :name
|
213
|
+
|
214
|
+
def initialize(name:, location:)
|
215
|
+
super(location: location)
|
216
|
+
@name = name
|
217
|
+
end
|
218
|
+
|
219
|
+
def header_line
|
220
|
+
"Different superclasses are specified for `#{name}`"
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
class GenericParameterMismatch < Base
|
225
|
+
attr_reader :name
|
226
|
+
|
227
|
+
def initialize(name:, location:)
|
228
|
+
super(location: location)
|
229
|
+
@name = name
|
230
|
+
end
|
231
|
+
|
232
|
+
def header_line
|
233
|
+
"Different generic parameters are specified across definitions of `#{name}`"
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
class InvalidVarianceAnnotation < Base
|
238
|
+
attr_reader :name
|
239
|
+
attr_reader :param
|
240
|
+
|
241
|
+
def initialize(name:, param:, location:)
|
242
|
+
super(location: location)
|
243
|
+
@name = name
|
244
|
+
@param = param
|
245
|
+
end
|
246
|
+
|
247
|
+
def header_line
|
248
|
+
"The variance of type parameter `#{param.name}` is #{param.variance}, but used in incompatible position here"
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
class ModuleSelfTypeError < Base
|
253
|
+
attr_reader :name
|
254
|
+
attr_reader :ancestor
|
255
|
+
attr_reader :result
|
256
|
+
|
257
|
+
include ResultPrinter2
|
258
|
+
|
259
|
+
def initialize(name:, ancestor:, result:, location:)
|
260
|
+
super(location: location)
|
261
|
+
|
262
|
+
@name = name
|
263
|
+
@ancestor = ancestor
|
264
|
+
@result = result
|
265
|
+
end
|
266
|
+
|
267
|
+
def relation
|
268
|
+
result.relation
|
269
|
+
end
|
270
|
+
|
271
|
+
def header_line
|
272
|
+
"Module self type constraint in type `#{name}` doesn't satisfy: `#{relation}`"
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
class ClassVariableDuplicationError < Base
|
277
|
+
attr_reader :class_name
|
278
|
+
attr_reader :other_class_name
|
279
|
+
attr_reader :variable_name
|
280
|
+
|
281
|
+
def initialize(class_name:, other_class_name:, variable_name:, location:)
|
282
|
+
super(location: location)
|
283
|
+
|
284
|
+
@class_name = class_name
|
285
|
+
@other_class_name = other_class_name
|
286
|
+
@variable_name = variable_name
|
287
|
+
end
|
288
|
+
|
289
|
+
def header_line
|
290
|
+
"Class variable definition `#{variable_name}` in `#{class_name}` may be overtaken by `#{other_class_name}`"
|
291
|
+
end
|
292
|
+
end
|
293
|
+
|
294
|
+
class InstanceVariableTypeError < Base
|
295
|
+
attr_reader :name
|
296
|
+
attr_reader :var_type
|
297
|
+
attr_reader :parent_type
|
298
|
+
|
299
|
+
def initialize(name:, location:, var_type:, parent_type:)
|
300
|
+
super(location: location)
|
301
|
+
|
302
|
+
@name = name
|
303
|
+
@var_type = var_type
|
304
|
+
@parent_type = parent_type
|
305
|
+
end
|
306
|
+
|
307
|
+
def header_line
|
308
|
+
"Instance variable cannot have different type with parents: #{var_type} <=> #{parent_type}"
|
309
|
+
end
|
310
|
+
end
|
311
|
+
|
312
|
+
class MixinClassError < Base
|
313
|
+
attr_reader :member
|
314
|
+
attr_reader :type_name
|
315
|
+
|
316
|
+
def initialize(location:, member:, type_name:)
|
317
|
+
super(location: location)
|
318
|
+
@member = member
|
319
|
+
@type_name = type_name
|
320
|
+
end
|
321
|
+
|
322
|
+
def header_line
|
323
|
+
"Cannot #{mixin_name} a class `#{member.name}` in the definition of `#{type_name}`"
|
324
|
+
end
|
325
|
+
|
326
|
+
private
|
327
|
+
|
328
|
+
def mixin_name
|
329
|
+
case mem = member
|
330
|
+
when RBS::AST::Members::Prepend
|
331
|
+
"prepend"
|
332
|
+
when RBS::AST::Members::Include
|
333
|
+
"include"
|
334
|
+
when RBS::AST::Members::Extend
|
335
|
+
"extend"
|
336
|
+
end
|
337
|
+
end
|
338
|
+
end
|
339
|
+
|
340
|
+
class InheritModuleError < Base
|
341
|
+
attr_reader :super_class
|
342
|
+
|
343
|
+
def initialize(super_class)
|
344
|
+
super(location: super_class.location)
|
345
|
+
@super_class = super_class
|
346
|
+
end
|
347
|
+
|
348
|
+
def header_line
|
349
|
+
"Cannot inherit from a module `#{super_class.name}`"
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
class UnexpectedError < Base
|
354
|
+
attr_reader :message
|
355
|
+
|
356
|
+
def initialize(message:, location:)
|
357
|
+
@message = message
|
358
|
+
@location = location
|
359
|
+
end
|
360
|
+
|
361
|
+
def header_line
|
362
|
+
"Unexpected error: #{message}"
|
363
|
+
end
|
364
|
+
end
|
365
|
+
|
366
|
+
class RecursiveTypeAlias < Base
|
367
|
+
attr_reader :alias_names
|
368
|
+
|
369
|
+
def initialize(alias_names:, location:)
|
370
|
+
@alias_names = alias_names
|
371
|
+
super(location: location)
|
372
|
+
end
|
373
|
+
|
374
|
+
def header_line
|
375
|
+
"Type aliases cannot be *directly recursive*: #{alias_names.join(", ")}"
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
class NonregularTypeAlias < Base
|
380
|
+
attr_reader :type_name
|
381
|
+
attr_reader :nonregular_type
|
382
|
+
|
383
|
+
def initialize(type_name:, nonregular_type:, location:)
|
384
|
+
@type_name = type_name
|
385
|
+
@nonregular_type = nonregular_type
|
386
|
+
@location = location
|
387
|
+
end
|
388
|
+
|
389
|
+
def header_line
|
390
|
+
"Type alias #{type_name} is defined *non-regular*: #{nonregular_type}"
|
391
|
+
end
|
392
|
+
end
|
393
|
+
|
394
|
+
class InconsistentClassModuleAliasError < Base
|
395
|
+
attr_reader :decl
|
396
|
+
|
397
|
+
def initialize(decl:)
|
398
|
+
@decl = decl
|
399
|
+
super(location: decl.location&.[](:old_name))
|
400
|
+
end
|
401
|
+
|
402
|
+
def header_line
|
403
|
+
expected_kind =
|
404
|
+
case decl
|
405
|
+
when RBS::AST::Declarations::ModuleAlias
|
406
|
+
"module"
|
407
|
+
when RBS::AST::Declarations::ClassAlias
|
408
|
+
"class"
|
409
|
+
else
|
410
|
+
raise
|
411
|
+
end
|
412
|
+
|
413
|
+
"A #{expected_kind} `#{decl.new_name}` cannot be an alias of `#{decl.old_name}`"
|
414
|
+
end
|
415
|
+
end
|
416
|
+
|
417
|
+
class CyclicClassAliasDefinitionError < Base
|
418
|
+
attr_reader :decl
|
419
|
+
|
420
|
+
def initialize(decl:)
|
421
|
+
@decl = decl
|
422
|
+
super(location: decl.location&.[](:new_name))
|
423
|
+
end
|
424
|
+
|
425
|
+
def header_line
|
426
|
+
"#{decl.new_name} is a cyclic definition"
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
class TypeParamDefaultReferenceError < Base
|
431
|
+
attr_reader :type_param
|
432
|
+
|
433
|
+
def initialize(type_param, location:)
|
434
|
+
super(location: location)
|
435
|
+
@type_param = type_param
|
436
|
+
end
|
437
|
+
|
438
|
+
def header_line
|
439
|
+
"The default type of `#{type_param.name}` cannot depend on optional type parameters"
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
class UnsatisfiableGenericsDefaultType < Base
|
444
|
+
attr_reader :param_name, :result
|
445
|
+
|
446
|
+
include ResultPrinter2
|
447
|
+
|
448
|
+
def initialize(param_name, result, location:)
|
449
|
+
super(location: location)
|
450
|
+
@param_name = param_name
|
451
|
+
@result = result
|
452
|
+
end
|
453
|
+
|
454
|
+
def relation
|
455
|
+
result.relation
|
456
|
+
end
|
457
|
+
|
458
|
+
def header_line
|
459
|
+
"The default type of `#{param_name}` doesn't satisfy upper bound constraint: #{relation}"
|
460
|
+
end
|
461
|
+
end
|
462
|
+
|
463
|
+
|
464
|
+
def self.from_rbs_error(error, factory:)
|
465
|
+
case error
|
466
|
+
when RBS::ParsingError
|
467
|
+
Diagnostic::Signature::SyntaxError.new(error, location: error.location)
|
468
|
+
when RBS::DuplicatedDeclarationError
|
469
|
+
Diagnostic::Signature::DuplicatedDeclaration.new(
|
470
|
+
type_name: error.name,
|
471
|
+
location: error.decls.fetch(0).location
|
472
|
+
)
|
473
|
+
when RBS::GenericParameterMismatchError
|
474
|
+
Diagnostic::Signature::GenericParameterMismatch.new(
|
475
|
+
name: error.name,
|
476
|
+
location: error.decl.location
|
477
|
+
)
|
478
|
+
when RBS::InvalidTypeApplicationError
|
479
|
+
Diagnostic::Signature::InvalidTypeApplication.new(
|
480
|
+
name: error.type_name,
|
481
|
+
args: error.args.map {|ty| factory.type(ty) },
|
482
|
+
params: error.params,
|
483
|
+
location: error.location
|
484
|
+
)
|
485
|
+
when RBS::NoTypeFoundError,
|
486
|
+
RBS::NoSuperclassFoundError,
|
487
|
+
RBS::NoMixinFoundError,
|
488
|
+
RBS::NoSelfTypeFoundError
|
489
|
+
Diagnostic::Signature::UnknownTypeName.new(
|
490
|
+
name: error.type_name,
|
491
|
+
location: error.location
|
492
|
+
)
|
493
|
+
when RBS::InvalidOverloadMethodError
|
494
|
+
Diagnostic::Signature::InvalidMethodOverload.new(
|
495
|
+
class_name: error.type_name,
|
496
|
+
method_name: error.method_name,
|
497
|
+
location: error.members.fetch(0).location
|
498
|
+
)
|
499
|
+
when RBS::DuplicatedMethodDefinitionError
|
500
|
+
Diagnostic::Signature::DuplicatedMethodDefinition.new(
|
501
|
+
class_name: error.type_name,
|
502
|
+
method_name: error.method_name,
|
503
|
+
location: error.location
|
504
|
+
)
|
505
|
+
when RBS::DuplicatedInterfaceMethodDefinitionError
|
506
|
+
Diagnostic::Signature::DuplicatedMethodDefinition.new(
|
507
|
+
class_name: error.type_name,
|
508
|
+
method_name: error.method_name,
|
509
|
+
location: error.member.location
|
510
|
+
)
|
511
|
+
when RBS::UnknownMethodAliasError
|
512
|
+
Diagnostic::Signature::UnknownMethodAlias.new(
|
513
|
+
class_name: error.type_name,
|
514
|
+
method_name: error.original_name,
|
515
|
+
location: error.location
|
516
|
+
)
|
517
|
+
when RBS::RecursiveAliasDefinitionError
|
518
|
+
Diagnostic::Signature::RecursiveAlias.new(
|
519
|
+
class_name: error.type.name,
|
520
|
+
names: error.defs.map(&:name),
|
521
|
+
location: error.defs.fetch(0).original&.location
|
522
|
+
)
|
523
|
+
when RBS::RecursiveAncestorError
|
524
|
+
Diagnostic::Signature::RecursiveAncestor.new(
|
525
|
+
ancestors: error.ancestors,
|
526
|
+
location: error.location
|
527
|
+
)
|
528
|
+
when RBS::SuperclassMismatchError
|
529
|
+
Diagnostic::Signature::SuperclassMismatch.new(
|
530
|
+
name: error.name,
|
531
|
+
location: error.entry.primary.decl.location
|
532
|
+
)
|
533
|
+
when RBS::InvalidVarianceAnnotationError
|
534
|
+
Diagnostic::Signature::InvalidVarianceAnnotation.new(
|
535
|
+
name: error.type_name,
|
536
|
+
param: error.param,
|
537
|
+
location: error.location
|
538
|
+
)
|
539
|
+
when RBS::MixinClassError
|
540
|
+
Diagnostic::Signature::MixinClassError.new(
|
541
|
+
location: error.location,
|
542
|
+
type_name: error.type_name,
|
543
|
+
member: error.member,
|
544
|
+
)
|
545
|
+
when RBS::RecursiveTypeAliasError
|
546
|
+
Diagnostic::Signature::RecursiveTypeAlias.new(
|
547
|
+
alias_names: error.alias_names,
|
548
|
+
location: error.location
|
549
|
+
)
|
550
|
+
when RBS::NonregularTypeAliasError
|
551
|
+
Diagnostic::Signature::NonregularTypeAlias.new(
|
552
|
+
type_name: error.diagnostic.type_name,
|
553
|
+
nonregular_type: factory.type(error.diagnostic.nonregular_type),
|
554
|
+
location: error.location
|
555
|
+
)
|
556
|
+
when RBS::InheritModuleError
|
557
|
+
Diagnostic::Signature::InheritModuleError.new(error.super_decl)
|
558
|
+
when RBS::InconsistentClassModuleAliasError
|
559
|
+
Diagnostic::Signature::InconsistentClassModuleAliasError.new(decl: error.alias_entry.decl)
|
560
|
+
when RBS::CyclicClassAliasDefinitionError
|
561
|
+
Diagnostic::Signature::CyclicClassAliasDefinitionError.new(decl: error.alias_entry.decl)
|
562
|
+
when RBS::TypeParamDefaultReferenceError
|
563
|
+
Diagnostic::Signature::TypeParamDefaultReferenceError.new(error.type_param, location: error.location)
|
564
|
+
else
|
565
|
+
raise error
|
566
|
+
end
|
567
|
+
end
|
568
|
+
end
|
569
|
+
end
|
570
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Steep
|
2
|
+
module Drivers
|
3
|
+
class Annotations
|
4
|
+
attr_reader :command_line_patterns
|
5
|
+
attr_reader :stdout
|
6
|
+
attr_reader :stderr
|
7
|
+
|
8
|
+
include Utils::DriverHelper
|
9
|
+
|
10
|
+
def initialize(stdout:, stderr:)
|
11
|
+
@stdout = stdout
|
12
|
+
@stderr = stderr
|
13
|
+
|
14
|
+
@command_line_patterns = []
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
project = load_config()
|
19
|
+
|
20
|
+
loader = Services::FileLoader.new(base_dir: project.base_dir)
|
21
|
+
|
22
|
+
project.targets.each do |target|
|
23
|
+
Steep.logger.tagged "target=#{target.name}" do
|
24
|
+
service = Services::SignatureService.load_from(target.new_env_loader(), implicitly_returns_nil: target.implicitly_returns_nil)
|
25
|
+
|
26
|
+
sigs = loader.load_changes(target.signature_pattern, changes: {})
|
27
|
+
service.update(sigs)
|
28
|
+
|
29
|
+
factory = AST::Types::Factory.new(builder: service.latest_builder)
|
30
|
+
|
31
|
+
srcs = loader.load_changes(target.source_pattern, command_line_patterns, changes: {})
|
32
|
+
srcs.each do |path, changes|
|
33
|
+
text = changes.inject("") {|text, change| change.apply_to(text) }
|
34
|
+
source = Source.parse(text, path: path, factory: factory)
|
35
|
+
|
36
|
+
source.each_annotation.sort_by {|node, _| [node.loc.expression.begin_pos, node.loc.expression.end_pos] }.each do |node, annotations|
|
37
|
+
loc = node.loc
|
38
|
+
stdout.puts "#{path}:#{loc.line}:#{loc.column}:#{node.type}:\t#{node.loc.expression.source.lines.first}"
|
39
|
+
annotations.each do |annotation|
|
40
|
+
annotation.location or raise
|
41
|
+
stdout.puts " #{annotation.location.source}"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
0
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|