steep 0.40.0 → 0.44.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +38 -0
- data/Gemfile +1 -0
- data/bin/output_rebaseline.rb +15 -30
- data/bin/output_test.rb +23 -57
- data/lib/steep.rb +89 -15
- data/lib/steep/annotation_parser.rb +10 -2
- data/lib/steep/ast/types/class.rb +4 -0
- data/lib/steep/cli.rb +31 -6
- data/lib/steep/diagnostic/ruby.rb +13 -8
- data/lib/steep/diagnostic/signature.rb +152 -2
- data/lib/steep/drivers/annotations.rb +18 -36
- data/lib/steep/drivers/check.rb +140 -31
- data/lib/steep/drivers/diagnostic_printer.rb +20 -11
- data/lib/steep/drivers/langserver.rb +4 -8
- data/lib/steep/drivers/print_project.rb +10 -9
- data/lib/steep/drivers/stats.rb +135 -119
- data/lib/steep/drivers/utils/driver_helper.rb +35 -0
- data/lib/steep/drivers/utils/jobs_count.rb +9 -0
- data/lib/steep/drivers/validate.rb +29 -18
- data/lib/steep/drivers/watch.rb +55 -49
- data/lib/steep/drivers/worker.rb +11 -8
- data/lib/steep/expectations.rb +159 -0
- data/lib/steep/index/signature_symbol_provider.rb +23 -1
- data/lib/steep/index/source_index.rb +55 -5
- data/lib/steep/interface/block.rb +4 -0
- data/lib/steep/project.rb +0 -30
- data/lib/steep/project/dsl.rb +5 -3
- data/lib/steep/project/pattern.rb +56 -0
- data/lib/steep/project/target.rb +11 -227
- data/lib/steep/server/base_worker.rb +1 -3
- data/lib/steep/server/change_buffer.rb +63 -0
- data/lib/steep/server/interaction_worker.rb +72 -57
- data/lib/steep/server/master.rb +652 -234
- data/lib/steep/server/type_check_worker.rb +304 -0
- data/lib/steep/server/worker_process.rb +16 -11
- data/lib/steep/{project → services}/completion_provider.rb +5 -5
- data/lib/steep/services/content_change.rb +61 -0
- data/lib/steep/services/file_loader.rb +48 -0
- data/lib/steep/services/goto_service.rb +321 -0
- data/lib/steep/{project → services}/hover_content.rb +19 -20
- data/lib/steep/services/path_assignment.rb +27 -0
- data/lib/steep/services/signature_service.rb +403 -0
- data/lib/steep/services/stats_calculator.rb +69 -0
- data/lib/steep/services/type_check_service.rb +413 -0
- data/lib/steep/signature/validator.rb +187 -85
- data/lib/steep/source.rb +21 -18
- data/lib/steep/subtyping/check.rb +246 -45
- data/lib/steep/subtyping/constraints.rb +4 -4
- data/lib/steep/type_construction.rb +428 -193
- data/lib/steep/type_inference/block_params.rb +1 -1
- data/lib/steep/type_inference/context.rb +22 -0
- data/lib/steep/type_inference/local_variable_type_env.rb +26 -12
- data/lib/steep/type_inference/logic.rb +1 -1
- data/lib/steep/type_inference/logic_type_interpreter.rb +4 -4
- data/lib/steep/type_inference/type_env.rb +43 -17
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/test_expectations.yml +96 -0
- data/smoke/and/test_expectations.yml +31 -0
- data/smoke/array/test_expectations.yml +103 -0
- data/smoke/block/test_expectations.yml +125 -0
- data/smoke/case/test_expectations.yml +47 -0
- data/smoke/class/test_expectations.yml +120 -0
- data/smoke/const/test_expectations.yml +129 -0
- data/smoke/diagnostics-rbs-duplicated/test_expectations.yml +13 -0
- data/smoke/diagnostics-rbs/Steepfile +7 -4
- data/smoke/diagnostics-rbs/test_expectations.yml +231 -0
- data/smoke/diagnostics-rbs/unknown-type-name-2.rbs +5 -0
- data/smoke/{broken → diagnostics-ruby-unsat}/Steepfile +0 -0
- data/smoke/diagnostics-ruby-unsat/a.rbs +3 -0
- data/smoke/diagnostics-ruby-unsat/test_expectations.yml +27 -0
- data/smoke/{diagnostics → diagnostics-ruby-unsat}/unsatisfiable_constraint.rb +0 -1
- data/smoke/diagnostics/a.rbs +0 -4
- data/smoke/diagnostics/test_expectations.yml +451 -0
- data/smoke/dstr/test_expectations.yml +13 -0
- data/smoke/ensure/test_expectations.yml +62 -0
- data/smoke/enumerator/test_expectations.yml +135 -0
- data/smoke/extension/f.rb +2 -0
- data/smoke/extension/f.rbs +3 -0
- data/smoke/extension/test_expectations.yml +73 -0
- data/smoke/hash/test_expectations.yml +81 -0
- data/smoke/hello/test_expectations.yml +25 -0
- data/smoke/if/test_expectations.yml +34 -0
- data/smoke/implements/b.rb +13 -0
- data/smoke/implements/b.rbs +12 -0
- data/smoke/implements/test_expectations.yml +23 -0
- data/smoke/initialize/test_expectations.yml +1 -0
- data/smoke/integer/test_expectations.yml +101 -0
- data/smoke/interface/test_expectations.yml +23 -0
- data/smoke/kwbegin/test_expectations.yml +17 -0
- data/smoke/lambda/test_expectations.yml +39 -0
- data/smoke/literal/test_expectations.yml +106 -0
- data/smoke/map/test_expectations.yml +1 -0
- data/smoke/method/test_expectations.yml +90 -0
- data/smoke/module/test_expectations.yml +75 -0
- data/smoke/regexp/test_expectations.yml +615 -0
- data/smoke/regression/issue_328.rb +1 -0
- data/smoke/regression/issue_328.rbs +0 -0
- data/smoke/regression/issue_332.rb +11 -0
- data/smoke/regression/issue_332.rbs +19 -0
- data/smoke/regression/issue_372.rb +8 -0
- data/smoke/regression/issue_372.rbs +4 -0
- data/smoke/regression/masgn.rb +4 -0
- data/smoke/regression/test_expectations.yml +60 -0
- data/smoke/regression/thread.rb +7 -0
- data/smoke/rescue/test_expectations.yml +79 -0
- data/smoke/self/test_expectations.yml +23 -0
- data/smoke/skip/test_expectations.yml +23 -0
- data/smoke/stdout/test_expectations.yml +1 -0
- data/smoke/super/test_expectations.yml +69 -0
- data/smoke/toplevel/test_expectations.yml +15 -0
- data/smoke/tsort/Steepfile +2 -0
- data/smoke/tsort/test_expectations.yml +63 -0
- data/smoke/type_case/test_expectations.yml +48 -0
- data/smoke/unexpected/Steepfile +5 -0
- data/smoke/unexpected/test_expectations.yml +25 -0
- data/smoke/unexpected/unexpected.rb +1 -0
- data/smoke/unexpected/unexpected.rbs +3 -0
- data/smoke/yield/test_expectations.yml +68 -0
- data/steep.gemspec +4 -3
- metadata +127 -80
- data/lib/steep/project/file_loader.rb +0 -68
- data/lib/steep/project/signature_file.rb +0 -39
- data/lib/steep/project/source_file.rb +0 -129
- data/lib/steep/project/stats_calculator.rb +0 -80
- data/lib/steep/server/code_worker.rb +0 -150
- data/lib/steep/server/signature_worker.rb +0 -157
- data/lib/steep/server/utils.rb +0 -69
- data/smoke/alias/test.yaml +0 -73
- data/smoke/and/test.yaml +0 -24
- data/smoke/array/test.yaml +0 -80
- data/smoke/block/test.yaml +0 -96
- data/smoke/broken/broken.rb +0 -0
- data/smoke/broken/broken.rbs +0 -0
- data/smoke/broken/test.yaml +0 -6
- data/smoke/case/test.yaml +0 -36
- data/smoke/class/test.yaml +0 -89
- data/smoke/const/test.yaml +0 -96
- data/smoke/diagnostics-rbs-duplicated/test.yaml +0 -10
- data/smoke/diagnostics-rbs/test.yaml +0 -142
- data/smoke/diagnostics/test.yaml +0 -333
- data/smoke/dstr/test.yaml +0 -10
- data/smoke/ensure/test.yaml +0 -47
- data/smoke/enumerator/test.yaml +0 -100
- data/smoke/extension/test.yaml +0 -50
- data/smoke/hash/test.yaml +0 -62
- data/smoke/hello/test.yaml +0 -18
- data/smoke/if/test.yaml +0 -27
- data/smoke/implements/test.yaml +0 -16
- data/smoke/initialize/test.yaml +0 -4
- data/smoke/integer/test.yaml +0 -66
- data/smoke/interface/test.yaml +0 -16
- data/smoke/kwbegin/test.yaml +0 -14
- data/smoke/lambda/test.yaml +0 -28
- data/smoke/literal/test.yaml +0 -79
- data/smoke/map/test.yaml +0 -4
- data/smoke/method/test.yaml +0 -71
- data/smoke/module/test.yaml +0 -51
- data/smoke/regexp/test.yaml +0 -372
- data/smoke/regression/test.yaml +0 -38
- data/smoke/rescue/test.yaml +0 -60
- data/smoke/self/test.yaml +0 -16
- data/smoke/skip/test.yaml +0 -16
- data/smoke/stdout/test.yaml +0 -4
- data/smoke/super/test.yaml +0 -52
- data/smoke/toplevel/test.yaml +0 -12
- data/smoke/tsort/test.yaml +0 -32
- data/smoke/type_case/test.yaml +0 -33
- data/smoke/yield/test.yaml +0 -49
|
@@ -190,7 +190,7 @@ module Steep
|
|
|
190
190
|
when 1
|
|
191
191
|
upper_bound.first
|
|
192
192
|
else
|
|
193
|
-
AST::Types::
|
|
193
|
+
AST::Types::Intersection.build(types: upper_bound.to_a)
|
|
194
194
|
end
|
|
195
195
|
end
|
|
196
196
|
|
|
@@ -203,11 +203,11 @@ module Steep
|
|
|
203
203
|
when 1
|
|
204
204
|
lower_bound.first
|
|
205
205
|
else
|
|
206
|
-
AST::Types::
|
|
206
|
+
AST::Types::Union.build(types: lower_bound.to_a)
|
|
207
207
|
end
|
|
208
208
|
end
|
|
209
209
|
|
|
210
|
-
def solution(checker, variance:, variables:, self_type:)
|
|
210
|
+
def solution(checker, variance:, variables:, self_type:, instance_type:, class_type:)
|
|
211
211
|
vars = []
|
|
212
212
|
types = []
|
|
213
213
|
|
|
@@ -218,7 +218,7 @@ module Steep
|
|
|
218
218
|
lower_bound = lower_bound(var)
|
|
219
219
|
relation = Relation.new(sub_type: lower_bound, super_type: upper_bound)
|
|
220
220
|
|
|
221
|
-
checker.check(relation, self_type: self_type, constraints: self.class.empty).yield_self do |result|
|
|
221
|
+
checker.check(relation, self_type: self_type, instance_type: instance_type, class_type: class_type, constraints: self.class.empty).yield_self do |result|
|
|
222
222
|
if result.success?
|
|
223
223
|
vars << var
|
|
224
224
|
|
|
@@ -115,8 +115,15 @@ module Steep
|
|
|
115
115
|
end
|
|
116
116
|
|
|
117
117
|
def check_relation(sub_type:, super_type:, constraints: Subtyping::Constraints.empty)
|
|
118
|
-
Steep.logger.debug { "check_relation: self:#{self_type} |- #{sub_type} <: #{super_type}" }
|
|
119
|
-
|
|
118
|
+
Steep.logger.debug { "check_relation: self:#{self_type}, instance:#{module_context.instance_type}, class:#{module_context.module_type} |- #{sub_type} <: #{super_type}" }
|
|
119
|
+
relation = Subtyping::Relation.new(sub_type: sub_type, super_type: super_type)
|
|
120
|
+
checker.check(
|
|
121
|
+
relation,
|
|
122
|
+
self_type: self_type,
|
|
123
|
+
instance_type: module_context.instance_type,
|
|
124
|
+
class_type: module_context.module_type,
|
|
125
|
+
constraints: constraints
|
|
126
|
+
)
|
|
120
127
|
end
|
|
121
128
|
|
|
122
129
|
def for_new_method(method_name, node, args:, self_type:, definition:)
|
|
@@ -200,19 +207,23 @@ module Steep
|
|
|
200
207
|
type_env = type_env.with_annotations(
|
|
201
208
|
ivar_types: annots.ivar_types,
|
|
202
209
|
const_types: annots.const_types,
|
|
203
|
-
self_type: annots.self_type || self_type
|
|
210
|
+
self_type: annots.self_type || self_type,
|
|
211
|
+
instance_type: module_context.instance_type,
|
|
212
|
+
class_type: module_context.module_type
|
|
204
213
|
)
|
|
205
214
|
|
|
206
215
|
lvar_env = TypeInference::LocalVariableTypeEnv.empty(
|
|
207
216
|
subtyping: checker,
|
|
208
|
-
self_type: annots.self_type || self_type
|
|
217
|
+
self_type: annots.self_type || self_type,
|
|
218
|
+
instance_type: module_context.instance_type,
|
|
219
|
+
class_type: module_context.module_type
|
|
209
220
|
)
|
|
210
221
|
|
|
211
222
|
if var_types
|
|
212
223
|
lvar_env = lvar_env.update(
|
|
213
224
|
assigned_types: var_types.each.with_object({}) {|(var, type), hash|
|
|
214
225
|
arg_node = args.find {|arg| arg.children[0] == var }
|
|
215
|
-
hash[var
|
|
226
|
+
hash[var] = TypeInference::LocalVariableTypeEnv::Entry.new(type: type, nodes: [arg_node].compact)
|
|
216
227
|
}
|
|
217
228
|
)
|
|
218
229
|
end
|
|
@@ -285,6 +296,41 @@ module Steep
|
|
|
285
296
|
end
|
|
286
297
|
end
|
|
287
298
|
|
|
299
|
+
def default_module_context(implement_module_name, const_env:, current_namespace:)
|
|
300
|
+
if implement_module_name
|
|
301
|
+
module_name = checker.factory.absolute_type_name(implement_module_name.name, namespace: current_namespace)
|
|
302
|
+
module_args = implement_module_name.args.map {|name| AST::Types::Var.new(name: name) }
|
|
303
|
+
|
|
304
|
+
instance_def = checker.factory.definition_builder.build_instance(module_name)
|
|
305
|
+
module_def = checker.factory.definition_builder.build_singleton(module_name)
|
|
306
|
+
|
|
307
|
+
instance_type = AST::Types::Name::Instance.new(name: module_name, args: module_args)
|
|
308
|
+
module_type = AST::Types::Name::Singleton.new(name: module_name)
|
|
309
|
+
|
|
310
|
+
TypeInference::Context::ModuleContext.new(
|
|
311
|
+
instance_type: instance_type,
|
|
312
|
+
module_type: module_type,
|
|
313
|
+
implement_name: implement_module_name,
|
|
314
|
+
current_namespace: current_namespace,
|
|
315
|
+
const_env: const_env,
|
|
316
|
+
class_name: module_name,
|
|
317
|
+
instance_definition: instance_def,
|
|
318
|
+
module_definition: module_def
|
|
319
|
+
)
|
|
320
|
+
else
|
|
321
|
+
TypeInference::Context::ModuleContext.new(
|
|
322
|
+
instance_type: nil,
|
|
323
|
+
module_type: nil,
|
|
324
|
+
implement_name: nil,
|
|
325
|
+
current_namespace: current_namespace,
|
|
326
|
+
const_env: self.module_context.const_env,
|
|
327
|
+
class_name: self.module_context.class_name,
|
|
328
|
+
module_definition: nil,
|
|
329
|
+
instance_definition: nil
|
|
330
|
+
)
|
|
331
|
+
end
|
|
332
|
+
end
|
|
333
|
+
|
|
288
334
|
def for_module(node)
|
|
289
335
|
new_module_name = module_name_from_node(node.children.first) or raise "Unexpected module name: #{node.children.first}"
|
|
290
336
|
new_namespace = nested_namespace_for_module(new_module_name)
|
|
@@ -293,64 +339,55 @@ module Steep
|
|
|
293
339
|
module_const_env = TypeInference::ConstantEnv.new(factory: checker.factory, context: const_context)
|
|
294
340
|
|
|
295
341
|
annots = source.annotations(block: node, factory: checker.factory, current_module: new_namespace)
|
|
296
|
-
module_type = AST::Builtin::Module.instance_type
|
|
297
342
|
|
|
298
343
|
implement_module_name = implement_module(module_name: new_module_name, annotations: annots)
|
|
344
|
+
module_context = default_module_context(implement_module_name, const_env: module_const_env, current_namespace: new_namespace)
|
|
345
|
+
|
|
346
|
+
unless implement_module_name
|
|
347
|
+
module_context = module_context.update(module_type: AST::Builtin::Module.instance_type)
|
|
348
|
+
end
|
|
299
349
|
|
|
300
350
|
if implement_module_name
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
checker.factory.type(type)
|
|
328
|
-
},
|
|
329
|
-
AST::Types::Name::Instance.new(name: module_name, args: module_args)
|
|
330
|
-
].compact
|
|
351
|
+
module_entry = checker.factory.definition_builder.env.class_decls[implement_module_name.name]
|
|
352
|
+
|
|
353
|
+
module_context = module_context.update(
|
|
354
|
+
instance_type: AST::Types::Intersection.build(
|
|
355
|
+
types: [
|
|
356
|
+
AST::Builtin::Object.instance_type,
|
|
357
|
+
*module_entry.self_types.map {|module_self|
|
|
358
|
+
type = case
|
|
359
|
+
when module_self.name.interface?
|
|
360
|
+
RBS::Types::Interface.new(
|
|
361
|
+
name: module_self.name,
|
|
362
|
+
args: module_self.args,
|
|
363
|
+
location: module_self.location
|
|
364
|
+
)
|
|
365
|
+
when module_self.name.class?
|
|
366
|
+
RBS::Types::ClassInstance.new(
|
|
367
|
+
name: module_self.name,
|
|
368
|
+
args: module_self.args,
|
|
369
|
+
location: module_self.location
|
|
370
|
+
)
|
|
371
|
+
end
|
|
372
|
+
checker.factory.type(type)
|
|
373
|
+
},
|
|
374
|
+
module_context.instance_type
|
|
375
|
+
].compact
|
|
376
|
+
)
|
|
331
377
|
)
|
|
332
|
-
|
|
333
|
-
module_type = AST::Types::Name::Singleton.new(name: module_name)
|
|
334
378
|
end
|
|
335
379
|
|
|
336
380
|
if annots.instance_type
|
|
337
|
-
|
|
381
|
+
module_context = module_context.update(instance_type: annots.instance_type)
|
|
338
382
|
end
|
|
339
383
|
|
|
340
384
|
if annots.module_type
|
|
341
|
-
|
|
342
|
-
end
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
implement_name: implement_module_name,
|
|
348
|
-
current_namespace: new_namespace,
|
|
349
|
-
const_env: module_const_env,
|
|
350
|
-
class_name: absolute_name(new_module_name),
|
|
351
|
-
instance_definition: instance_def,
|
|
352
|
-
module_definition: module_def
|
|
353
|
-
)
|
|
385
|
+
module_context = module_context.update(module_type: annots.module_type)
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
if annots.self_type
|
|
389
|
+
module_context = module_context.update(module_type: annots.self_type)
|
|
390
|
+
end
|
|
354
391
|
|
|
355
392
|
module_type_env = TypeInference::TypeEnv.build(annotations: annots,
|
|
356
393
|
subtyping: checker,
|
|
@@ -359,7 +396,9 @@ module Steep
|
|
|
359
396
|
|
|
360
397
|
lvar_env = TypeInference::LocalVariableTypeEnv.empty(
|
|
361
398
|
subtyping: checker,
|
|
362
|
-
self_type:
|
|
399
|
+
self_type: module_context.module_type,
|
|
400
|
+
instance_type: module_context.instance_type,
|
|
401
|
+
class_type: module_context.module_type
|
|
363
402
|
).annotate(annots)
|
|
364
403
|
|
|
365
404
|
self.class.new(
|
|
@@ -371,11 +410,11 @@ module Steep
|
|
|
371
410
|
method_context: nil,
|
|
372
411
|
block_context: nil,
|
|
373
412
|
break_context: nil,
|
|
374
|
-
module_context:
|
|
375
|
-
self_type:
|
|
413
|
+
module_context: module_context,
|
|
414
|
+
self_type: module_context.module_type,
|
|
376
415
|
type_env: module_type_env,
|
|
377
416
|
lvar_env: lvar_env,
|
|
378
|
-
call_context: TypeInference::MethodCall::ModuleContext.new(type_name:
|
|
417
|
+
call_context: TypeInference::MethodCall::ModuleContext.new(type_name: module_context.class_name)
|
|
379
418
|
)
|
|
380
419
|
)
|
|
381
420
|
end
|
|
@@ -387,48 +426,37 @@ module Steep
|
|
|
387
426
|
|
|
388
427
|
annots = source.annotations(block: node, factory: checker.factory, current_module: new_namespace)
|
|
389
428
|
|
|
390
|
-
|
|
429
|
+
const_context = [new_namespace] + self.module_context.const_env.context
|
|
430
|
+
class_const_env = TypeInference::ConstantEnv.new(factory: checker.factory, context: const_context)
|
|
391
431
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
end
|
|
432
|
+
implement_module_name = implement_module(module_name: new_class_name, super_name: super_class_name, annotations: annots)
|
|
433
|
+
module_context = default_module_context(implement_module_name, const_env: class_const_env, current_namespace: new_namespace)
|
|
395
434
|
|
|
396
435
|
if implement_module_name
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
instance_type = AST::Types::Name::Instance.new(name: class_name, args: class_args)
|
|
405
|
-
module_type = AST::Types::Name::Singleton.new(name: class_name)
|
|
436
|
+
if super_class_name && implement_module_name.name == absolute_name(super_class_name)
|
|
437
|
+
module_context = module_context.update(
|
|
438
|
+
instance_definition: nil,
|
|
439
|
+
module_definition: nil
|
|
440
|
+
)
|
|
441
|
+
end
|
|
406
442
|
else
|
|
407
|
-
|
|
408
|
-
|
|
443
|
+
module_context = module_context.update(
|
|
444
|
+
instance_type: AST::Builtin::Object.instance_type,
|
|
445
|
+
module_type: AST::Builtin::Object.module_type
|
|
446
|
+
)
|
|
409
447
|
end
|
|
410
448
|
|
|
411
449
|
if annots.instance_type
|
|
412
|
-
|
|
450
|
+
module_context = module_context.update(instance_type: annots.instance_type)
|
|
413
451
|
end
|
|
414
452
|
|
|
415
453
|
if annots.module_type
|
|
416
|
-
|
|
454
|
+
module_context = module_context.update(module_type: annots.module_type)
|
|
417
455
|
end
|
|
418
456
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
module_context = TypeInference::Context::ModuleContext.new(
|
|
423
|
-
instance_type: annots.instance_type || instance_type,
|
|
424
|
-
module_type: annots.self_type || annots.module_type || module_type,
|
|
425
|
-
implement_name: implement_module_name,
|
|
426
|
-
current_namespace: new_namespace,
|
|
427
|
-
const_env: class_const_env,
|
|
428
|
-
class_name: absolute_name(new_class_name),
|
|
429
|
-
module_definition: module_def,
|
|
430
|
-
instance_definition: instance_def
|
|
431
|
-
)
|
|
457
|
+
if annots.self_type
|
|
458
|
+
module_context = module_context.update(module_type: annots.self_type)
|
|
459
|
+
end
|
|
432
460
|
|
|
433
461
|
class_type_env = TypeInference::TypeEnv.build(annotations: annots,
|
|
434
462
|
subtyping: checker,
|
|
@@ -437,7 +465,9 @@ module Steep
|
|
|
437
465
|
|
|
438
466
|
lvar_env = TypeInference::LocalVariableTypeEnv.empty(
|
|
439
467
|
subtyping: checker,
|
|
440
|
-
self_type: module_context.module_type
|
|
468
|
+
self_type: module_context.module_type,
|
|
469
|
+
instance_type: module_context.instance_type,
|
|
470
|
+
class_type: module_context.module_type
|
|
441
471
|
).annotate(annots)
|
|
442
472
|
|
|
443
473
|
class_body_context = TypeInference::Context.new(
|
|
@@ -523,7 +553,9 @@ module Steep
|
|
|
523
553
|
|
|
524
554
|
lvar_env = TypeInference::LocalVariableTypeEnv.empty(
|
|
525
555
|
subtyping: checker,
|
|
526
|
-
self_type: module_context.module_type
|
|
556
|
+
self_type: module_context.module_type,
|
|
557
|
+
instance_type: module_context.instance_type,
|
|
558
|
+
class_type: module_context.module_type
|
|
527
559
|
).annotate(annots)
|
|
528
560
|
|
|
529
561
|
body_context = TypeInference::Context.new(
|
|
@@ -604,14 +636,20 @@ module Steep
|
|
|
604
636
|
type_env = context.type_env
|
|
605
637
|
|
|
606
638
|
if type_case_override
|
|
607
|
-
type_env = type_env.with_annotations(
|
|
639
|
+
type_env = type_env.with_annotations(
|
|
640
|
+
self_type: self_type,
|
|
641
|
+
instance_type: module_context.instance_type,
|
|
642
|
+
class_type: module_context.module_type
|
|
643
|
+
)
|
|
608
644
|
end
|
|
609
645
|
|
|
610
646
|
type_env = type_env.with_annotations(
|
|
611
647
|
ivar_types: annots.ivar_types,
|
|
612
648
|
const_types: annots.const_types,
|
|
613
649
|
gvar_types: {},
|
|
614
|
-
self_type: self_type
|
|
650
|
+
self_type: self_type,
|
|
651
|
+
instance_type: module_context.instance_type,
|
|
652
|
+
class_type: module_context.module_type
|
|
615
653
|
) do |var, relation, result|
|
|
616
654
|
typing.add_error(
|
|
617
655
|
Diagnostic::Ruby::IncompatibleAnnotation.new(
|
|
@@ -684,7 +722,7 @@ module Steep
|
|
|
684
722
|
when :lvasgn
|
|
685
723
|
yield_self do
|
|
686
724
|
var, rhs = node.children
|
|
687
|
-
name = var
|
|
725
|
+
name = var
|
|
688
726
|
|
|
689
727
|
case name
|
|
690
728
|
when :_, :__any__
|
|
@@ -720,7 +758,7 @@ module Steep
|
|
|
720
758
|
when :lvar
|
|
721
759
|
yield_self do
|
|
722
760
|
var = node.children[0]
|
|
723
|
-
if (type = context.lvar_env[var
|
|
761
|
+
if (type = context.lvar_env[var])
|
|
724
762
|
add_typing node, type: type
|
|
725
763
|
else
|
|
726
764
|
fallback_to_any(node)
|
|
@@ -861,7 +899,27 @@ module Steep
|
|
|
861
899
|
block_body: nil,
|
|
862
900
|
topdown_hint: true)
|
|
863
901
|
|
|
864
|
-
constr
|
|
902
|
+
if call && constr
|
|
903
|
+
constr.add_call(call)
|
|
904
|
+
else
|
|
905
|
+
error = Diagnostic::Ruby::UnresolvedOverloading.new(
|
|
906
|
+
node: node,
|
|
907
|
+
receiver_type: self_type,
|
|
908
|
+
method_name: method_context.name,
|
|
909
|
+
method_types: super_method.method_types
|
|
910
|
+
)
|
|
911
|
+
call = TypeInference::MethodCall::Error.new(
|
|
912
|
+
node: node,
|
|
913
|
+
context: context.method_context,
|
|
914
|
+
method_name: method_context.name,
|
|
915
|
+
receiver_type: self_type,
|
|
916
|
+
errors: [error]
|
|
917
|
+
)
|
|
918
|
+
|
|
919
|
+
constr = synthesize_children(node)
|
|
920
|
+
|
|
921
|
+
fallback_to_any(node) { error }
|
|
922
|
+
end
|
|
865
923
|
else
|
|
866
924
|
fallback_to_any node do
|
|
867
925
|
Diagnostic::Ruby::UnexpectedSuper.new(node: node, method: method_context.name)
|
|
@@ -886,14 +944,23 @@ module Steep
|
|
|
886
944
|
yield_self do
|
|
887
945
|
name, args_node, body_node = node.children
|
|
888
946
|
|
|
889
|
-
new = for_new_method(
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
947
|
+
new = for_new_method(
|
|
948
|
+
name,
|
|
949
|
+
node,
|
|
950
|
+
args: args_node.children,
|
|
951
|
+
self_type: module_context&.instance_type,
|
|
952
|
+
definition: module_context&.instance_definition
|
|
953
|
+
)
|
|
894
954
|
new.typing.add_context_for_node(node, context: new.context)
|
|
895
955
|
new.typing.add_context_for_body(node, context: new.context)
|
|
896
956
|
|
|
957
|
+
new.method_context.tap do |method_context|
|
|
958
|
+
if method_context.method
|
|
959
|
+
method_name = InstanceMethodName.new(type_name: method_context.method.implemented_in, method_name: name)
|
|
960
|
+
new.typing.source_index.add_definition(method: method_name, definition: node)
|
|
961
|
+
end
|
|
962
|
+
end
|
|
963
|
+
|
|
897
964
|
new = new.synthesize_children(args_node)
|
|
898
965
|
|
|
899
966
|
body_pair = if body_node
|
|
@@ -948,24 +1015,43 @@ module Steep
|
|
|
948
1015
|
when :defs
|
|
949
1016
|
synthesize(node.children[0]).type.tap do |self_type|
|
|
950
1017
|
self_type = expand_self(self_type)
|
|
951
|
-
definition =
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
1018
|
+
definition =
|
|
1019
|
+
case self_type
|
|
1020
|
+
when AST::Types::Name::Instance
|
|
1021
|
+
name = self_type.name
|
|
1022
|
+
checker.factory.definition_builder.build_instance(name)
|
|
1023
|
+
when AST::Types::Name::Singleton
|
|
1024
|
+
name = self_type.name
|
|
1025
|
+
checker.factory.definition_builder.build_singleton(name)
|
|
1026
|
+
end
|
|
959
1027
|
|
|
960
1028
|
args_node = node.children[2]
|
|
961
|
-
new = for_new_method(
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
1029
|
+
new = for_new_method(
|
|
1030
|
+
node.children[1],
|
|
1031
|
+
node,
|
|
1032
|
+
args: args_node.children,
|
|
1033
|
+
self_type: self_type,
|
|
1034
|
+
definition: definition
|
|
1035
|
+
)
|
|
966
1036
|
new.typing.add_context_for_node(node, context: new.context)
|
|
967
1037
|
new.typing.add_context_for_body(node, context: new.context)
|
|
968
1038
|
|
|
1039
|
+
new.method_context.tap do |method_context|
|
|
1040
|
+
if method_context.method
|
|
1041
|
+
name_ = node.children[1]
|
|
1042
|
+
|
|
1043
|
+
method_name =
|
|
1044
|
+
case self_type
|
|
1045
|
+
when AST::Types::Name::Instance
|
|
1046
|
+
InstanceMethodName.new(type_name: method_context.method.implemented_in, method_name: name_)
|
|
1047
|
+
when AST::Types::Name::Singleton
|
|
1048
|
+
SingletonMethodName.new(type_name: method_context.method.implemented_in, method_name: name_)
|
|
1049
|
+
end
|
|
1050
|
+
|
|
1051
|
+
new.typing.source_index.add_definition(method: method_name, definition: node)
|
|
1052
|
+
end
|
|
1053
|
+
end
|
|
1054
|
+
|
|
969
1055
|
new = new.synthesize_children(args_node)
|
|
970
1056
|
|
|
971
1057
|
each_child_node(node.children[2]) do |arg|
|
|
@@ -1125,15 +1211,45 @@ module Steep
|
|
|
1125
1211
|
add_typing(node, type: AST::Builtin.bottom_type)
|
|
1126
1212
|
|
|
1127
1213
|
when :retry
|
|
1128
|
-
unless break_context
|
|
1129
|
-
typing.add_error Diagnostic::Ruby::UnexpectedJump.new(node: node)
|
|
1130
|
-
end
|
|
1131
1214
|
add_typing(node, type: AST::Builtin.bottom_type)
|
|
1132
1215
|
|
|
1133
|
-
when :
|
|
1216
|
+
when :procarg0
|
|
1217
|
+
yield_self do
|
|
1218
|
+
constr = self
|
|
1219
|
+
|
|
1220
|
+
node.children.each do |arg|
|
|
1221
|
+
if arg.is_a?(Symbol)
|
|
1222
|
+
type = context.lvar_env[arg]
|
|
1223
|
+
|
|
1224
|
+
if type
|
|
1225
|
+
_, constr = add_typing(node, type: type)
|
|
1226
|
+
else
|
|
1227
|
+
type = AST::Builtin.any_type
|
|
1228
|
+
_, constr = lvasgn(node, type)
|
|
1229
|
+
end
|
|
1230
|
+
else
|
|
1231
|
+
_, constr = constr.synthesize(arg)
|
|
1232
|
+
end
|
|
1233
|
+
end
|
|
1234
|
+
|
|
1235
|
+
Pair.new(constr: constr, type: AST::Builtin.any_type)
|
|
1236
|
+
end
|
|
1237
|
+
|
|
1238
|
+
when :mlhs
|
|
1239
|
+
yield_self do
|
|
1240
|
+
constr = self
|
|
1241
|
+
|
|
1242
|
+
node.children.each do |arg|
|
|
1243
|
+
_, constr = constr.synthesize(arg)
|
|
1244
|
+
end
|
|
1245
|
+
|
|
1246
|
+
Pair.new(constr: constr, type: AST::Builtin.any_type)
|
|
1247
|
+
end
|
|
1248
|
+
|
|
1249
|
+
when :arg, :kwarg
|
|
1134
1250
|
yield_self do
|
|
1135
1251
|
var = node.children[0]
|
|
1136
|
-
type = context.lvar_env[var
|
|
1252
|
+
type = context.lvar_env[var]
|
|
1137
1253
|
|
|
1138
1254
|
if type
|
|
1139
1255
|
add_typing(node, type: type)
|
|
@@ -1148,13 +1264,13 @@ module Steep
|
|
|
1148
1264
|
var = node.children[0]
|
|
1149
1265
|
rhs = node.children[1]
|
|
1150
1266
|
|
|
1151
|
-
var_type = context.lvar_env[var
|
|
1267
|
+
var_type = context.lvar_env[var]
|
|
1152
1268
|
node_type, constr = synthesize(rhs, hint: var_type)
|
|
1153
1269
|
|
|
1154
1270
|
type = AST::Types::Union.build(types: [var_type, node_type])
|
|
1155
1271
|
|
|
1156
1272
|
constr_ = constr.update_lvar_env do |env|
|
|
1157
|
-
env.assign(var
|
|
1273
|
+
env.assign(var, node: node, type: type) do |declared_type, type, result|
|
|
1158
1274
|
typing.add_error(
|
|
1159
1275
|
Diagnostic::Ruby::IncompatibleAssignment.new(
|
|
1160
1276
|
node: node,
|
|
@@ -1172,7 +1288,7 @@ module Steep
|
|
|
1172
1288
|
when :restarg
|
|
1173
1289
|
yield_self do
|
|
1174
1290
|
var = node.children[0]
|
|
1175
|
-
type = context.lvar_env[var
|
|
1291
|
+
type = context.lvar_env[var]
|
|
1176
1292
|
unless type
|
|
1177
1293
|
if context&.method_context&.method_type
|
|
1178
1294
|
Steep.logger.error { "Unknown variable: #{node}" }
|
|
@@ -1187,7 +1303,7 @@ module Steep
|
|
|
1187
1303
|
when :kwrestarg
|
|
1188
1304
|
yield_self do
|
|
1189
1305
|
var = node.children[0]
|
|
1190
|
-
type = context.lvar_env[var
|
|
1306
|
+
type = context.lvar_env[var]
|
|
1191
1307
|
unless type
|
|
1192
1308
|
if context&.method_context&.method_type
|
|
1193
1309
|
Steep.logger.error { "Unknown variable: #{node}" }
|
|
@@ -1355,9 +1471,22 @@ module Steep
|
|
|
1355
1471
|
constr = self
|
|
1356
1472
|
|
|
1357
1473
|
name, _ = node.children
|
|
1358
|
-
|
|
1474
|
+
if name.type == :const
|
|
1475
|
+
# skip the last constant reference
|
|
1476
|
+
if const_parent = name.children[0]
|
|
1477
|
+
_, constr = constr.synthesize(const_parent)
|
|
1478
|
+
end
|
|
1479
|
+
else
|
|
1480
|
+
_, constr = constr.synthesize(name)
|
|
1481
|
+
end
|
|
1359
1482
|
|
|
1360
1483
|
for_module(node).yield_self do |constructor|
|
|
1484
|
+
if module_type = constructor.module_context&.module_type
|
|
1485
|
+
_, constructor = constructor.add_typing(name, type: module_type)
|
|
1486
|
+
else
|
|
1487
|
+
_, constructor = constructor.fallback_to_any(name)
|
|
1488
|
+
end
|
|
1489
|
+
|
|
1361
1490
|
constructor.typing.source_index.add_definition(
|
|
1362
1491
|
constant: constructor.module_context.class_name,
|
|
1363
1492
|
definition: node
|
|
@@ -1450,7 +1579,13 @@ module Steep
|
|
|
1450
1579
|
|
|
1451
1580
|
const_type = type_env.get(const: const_name) {}
|
|
1452
1581
|
value_type, constr = constr.synthesize(node.children.last, hint: const_type)
|
|
1453
|
-
type = type_env.assign(
|
|
1582
|
+
type = type_env.assign(
|
|
1583
|
+
const: const_name,
|
|
1584
|
+
type: value_type,
|
|
1585
|
+
self_type: self_type,
|
|
1586
|
+
instance_type: module_context.instance_type,
|
|
1587
|
+
class_type: module_context.module_type
|
|
1588
|
+
) do |error|
|
|
1454
1589
|
case error
|
|
1455
1590
|
when Subtyping::Result::Failure
|
|
1456
1591
|
const_type = type_env.get(const: const_name)
|
|
@@ -1517,8 +1652,10 @@ module Steep
|
|
|
1517
1652
|
}
|
|
1518
1653
|
add_typing(node, type: union_type(*types))
|
|
1519
1654
|
else
|
|
1520
|
-
|
|
1521
|
-
fallback_to_any
|
|
1655
|
+
|
|
1656
|
+
fallback_to_any(node) do
|
|
1657
|
+
Diagnostic::Ruby::UnexpectedSuper.new(node: node, method: method_context.name)
|
|
1658
|
+
end
|
|
1522
1659
|
end
|
|
1523
1660
|
else
|
|
1524
1661
|
fallback_to_any node
|
|
@@ -1545,8 +1682,7 @@ module Steep
|
|
|
1545
1682
|
if hint && !(tuples = select_flatten_types(hint) {|type| type.is_a?(AST::Types::Tuple) }).empty?
|
|
1546
1683
|
tuples.each do |tuple|
|
|
1547
1684
|
typing.new_child(node_range) do |child_typing|
|
|
1548
|
-
pair = with_new_typing(child_typing).try_tuple_type(node, tuple)
|
|
1549
|
-
if pair && pair.constr.check_relation(sub_type: pair.type, super_type: hint).success?
|
|
1685
|
+
if pair = with_new_typing(child_typing).try_tuple_type(node, tuple)
|
|
1550
1686
|
child_typing.save!
|
|
1551
1687
|
return pair.with(constr: pair.constr.with_new_typing(typing))
|
|
1552
1688
|
end
|
|
@@ -1717,12 +1853,7 @@ module Steep
|
|
|
1717
1853
|
_, cond_vars = interpreter.decompose_value(cond)
|
|
1718
1854
|
unless cond_vars.empty?
|
|
1719
1855
|
first_var = cond_vars.to_a[0]
|
|
1720
|
-
var_node = cond.updated(
|
|
1721
|
-
:lvar,
|
|
1722
|
-
[
|
|
1723
|
-
ASTUtils::Labeling::LabeledName.new(name: first_var, label: 0)
|
|
1724
|
-
]
|
|
1725
|
-
)
|
|
1856
|
+
var_node = cond.updated(:lvar, [first_var])
|
|
1726
1857
|
else
|
|
1727
1858
|
first_var = nil
|
|
1728
1859
|
var_node = cond
|
|
@@ -1863,7 +1994,7 @@ module Steep
|
|
|
1863
1994
|
if assignment
|
|
1864
1995
|
case assignment.type
|
|
1865
1996
|
when :lvasgn
|
|
1866
|
-
var_name = assignment.children[0]
|
|
1997
|
+
var_name = assignment.children[0]
|
|
1867
1998
|
else
|
|
1868
1999
|
Steep.logger.error "Unexpected rescue variable assignment: #{assignment.type}"
|
|
1869
2000
|
end
|
|
@@ -1942,7 +2073,7 @@ module Steep
|
|
|
1942
2073
|
when AST::Types::Any
|
|
1943
2074
|
AST::Types::Any.new
|
|
1944
2075
|
else
|
|
1945
|
-
each =
|
|
2076
|
+
each = calculate_interface(collection_type, private: true).methods[:each]
|
|
1946
2077
|
method_type = (each&.method_types || []).find {|type| type.block && type.block.type.params.first_param }
|
|
1947
2078
|
method_type&.yield_self do |method_type|
|
|
1948
2079
|
method_type.block.type.params.first_param&.type
|
|
@@ -1952,7 +2083,7 @@ module Steep
|
|
|
1952
2083
|
if var_type
|
|
1953
2084
|
if body
|
|
1954
2085
|
body_constr = constr.with_updated_context(
|
|
1955
|
-
lvar_env: constr.context.lvar_env.assign(asgn.children[0]
|
|
2086
|
+
lvar_env: constr.context.lvar_env.assign(asgn.children[0], node: asgn, type: var_type)
|
|
1956
2087
|
)
|
|
1957
2088
|
|
|
1958
2089
|
typing.add_context_for_body(node, context: body_constr.context)
|
|
@@ -2148,7 +2279,7 @@ module Steep
|
|
|
2148
2279
|
when AST::Types::Any
|
|
2149
2280
|
type = AST::Types::Any.new
|
|
2150
2281
|
else
|
|
2151
|
-
interface =
|
|
2282
|
+
interface = calculate_interface(param_type, private: true)
|
|
2152
2283
|
method = interface.methods[value.children[0]]
|
|
2153
2284
|
if method
|
|
2154
2285
|
return_types = method.method_types.select {|method_type|
|
|
@@ -2266,6 +2397,15 @@ module Steep
|
|
|
2266
2397
|
raise "#synthesize should return an instance of Pair: #{pair.class}, node=#{node.inspect}"
|
|
2267
2398
|
end
|
|
2268
2399
|
end
|
|
2400
|
+
rescue RBS::ErrorBase => exn
|
|
2401
|
+
Steep.logger.warn { "Unexpected RBS error: #{exn.message}" }
|
|
2402
|
+
exn.backtrace.each {|loc| Steep.logger.warn " #{loc}" }
|
|
2403
|
+
typing.add_error(Diagnostic::Ruby::UnexpectedError.new(node: node, error: exn))
|
|
2404
|
+
type_any_rec(node)
|
|
2405
|
+
rescue StandardError => exn
|
|
2406
|
+
Steep.log_error exn
|
|
2407
|
+
typing.add_error(Diagnostic::Ruby::UnexpectedError.new(node: node, error: exn))
|
|
2408
|
+
type_any_rec(node)
|
|
2269
2409
|
end
|
|
2270
2410
|
end
|
|
2271
2411
|
|
|
@@ -2283,7 +2423,13 @@ module Steep
|
|
|
2283
2423
|
|
|
2284
2424
|
def type_ivasgn(name, rhs, node)
|
|
2285
2425
|
rhs_type = synthesize(rhs, hint: type_env.get(ivar: name) { fallback_to_any(node) }).type
|
|
2286
|
-
ivar_type = type_env.assign(
|
|
2426
|
+
ivar_type = type_env.assign(
|
|
2427
|
+
ivar: name,
|
|
2428
|
+
type: rhs_type,
|
|
2429
|
+
self_type: self_type,
|
|
2430
|
+
instance_type: module_context.instance_type,
|
|
2431
|
+
class_type: module_context.module_type
|
|
2432
|
+
) do |error|
|
|
2287
2433
|
case error
|
|
2288
2434
|
when Subtyping::Result::Failure
|
|
2289
2435
|
type = type_env.get(ivar: name)
|
|
@@ -2305,16 +2451,16 @@ module Steep
|
|
|
2305
2451
|
def masgn_lhs?(lhs)
|
|
2306
2452
|
lhs.children.all? do |a|
|
|
2307
2453
|
asgn_type = if a.type == :splat
|
|
2308
|
-
a.children[0]
|
|
2454
|
+
a.children[0]&.type
|
|
2309
2455
|
else
|
|
2310
2456
|
a.type
|
|
2311
2457
|
end
|
|
2312
|
-
asgn_type == :lvasgn || asgn_type == :ivasgn
|
|
2458
|
+
asgn_type.nil? || asgn_type == :lvasgn || asgn_type == :ivasgn
|
|
2313
2459
|
end
|
|
2314
2460
|
end
|
|
2315
2461
|
|
|
2316
2462
|
def lvasgn(node, type)
|
|
2317
|
-
name = node.children[0]
|
|
2463
|
+
name = node.children[0]
|
|
2318
2464
|
env = context.lvar_env.assign(name, node: node, type: type) do |declared_type, type, result|
|
|
2319
2465
|
typing.add_error(
|
|
2320
2466
|
Diagnostic::Ruby::IncompatibleAssignment.new(
|
|
@@ -2332,7 +2478,13 @@ module Steep
|
|
|
2332
2478
|
def ivasgn(node, type)
|
|
2333
2479
|
ivar = node.children[0]
|
|
2334
2480
|
|
|
2335
|
-
type_env.assign(
|
|
2481
|
+
type_env.assign(
|
|
2482
|
+
ivar: ivar,
|
|
2483
|
+
type: type,
|
|
2484
|
+
self_type: self_type,
|
|
2485
|
+
instance_type: module_context.instance_type,
|
|
2486
|
+
class_type: module_context.module_type
|
|
2487
|
+
) do |error|
|
|
2336
2488
|
case error
|
|
2337
2489
|
when Subtyping::Result::Failure
|
|
2338
2490
|
var_type = type_env.get(ivar: ivar)
|
|
@@ -2449,7 +2601,7 @@ module Steep
|
|
|
2449
2601
|
assignment_nodes.each do |asgn|
|
|
2450
2602
|
case asgn.type
|
|
2451
2603
|
when :splat
|
|
2452
|
-
case asgn.children[0]
|
|
2604
|
+
case asgn.children[0]&.type
|
|
2453
2605
|
when :lvasgn
|
|
2454
2606
|
_, constr = constr.lvasgn(asgn.children[0], array_type)
|
|
2455
2607
|
when :ivasgn
|
|
@@ -2675,6 +2827,7 @@ module Steep
|
|
|
2675
2827
|
end
|
|
2676
2828
|
|
|
2677
2829
|
receiver_type = checker.factory.deep_expand_alias(recv_type)
|
|
2830
|
+
private = receiver.nil? || receiver.type == :self
|
|
2678
2831
|
|
|
2679
2832
|
type, constr = case receiver_type
|
|
2680
2833
|
when nil
|
|
@@ -2719,9 +2872,9 @@ module Steep
|
|
|
2719
2872
|
)
|
|
2720
2873
|
)
|
|
2721
2874
|
else
|
|
2722
|
-
interface =
|
|
2723
|
-
|
|
2724
|
-
|
|
2875
|
+
interface = calculate_interface(expanded_self,
|
|
2876
|
+
private: private,
|
|
2877
|
+
self_type: AST::Types::Self.new)
|
|
2725
2878
|
|
|
2726
2879
|
constr.type_send_interface(node,
|
|
2727
2880
|
interface: interface,
|
|
@@ -2733,9 +2886,7 @@ module Steep
|
|
|
2733
2886
|
block_body: block_body)
|
|
2734
2887
|
end
|
|
2735
2888
|
else
|
|
2736
|
-
interface =
|
|
2737
|
-
private: !receiver,
|
|
2738
|
-
self_type: receiver_type)
|
|
2889
|
+
interface = calculate_interface(receiver_type, private: private, self_type: receiver_type)
|
|
2739
2890
|
|
|
2740
2891
|
constr.type_send_interface(node,
|
|
2741
2892
|
interface: interface,
|
|
@@ -2748,27 +2899,19 @@ module Steep
|
|
|
2748
2899
|
end
|
|
2749
2900
|
|
|
2750
2901
|
Pair.new(type: type, constr: constr)
|
|
2751
|
-
|
|
2752
|
-
case exn
|
|
2753
|
-
when RBS::NoTypeFoundError, RBS::NoMixinFoundError, RBS::NoSuperclassFoundError, RBS::InvalidTypeApplicationError
|
|
2754
|
-
# ignore known RBS errors.
|
|
2755
|
-
else
|
|
2756
|
-
Steep.log_error(exn, message: "Unexpected error in #type_send: #{exn.message} (#{exn.class})")
|
|
2757
|
-
end
|
|
2758
|
-
|
|
2759
|
-
error = Diagnostic::Ruby::UnexpectedError.new(node: node, error: exn)
|
|
2902
|
+
end
|
|
2760
2903
|
|
|
2761
|
-
|
|
2904
|
+
def calculate_interface(type, private:, self_type: type)
|
|
2905
|
+
case type
|
|
2906
|
+
when AST::Types::Self
|
|
2907
|
+
type = self_type
|
|
2908
|
+
when AST::Types::Instance
|
|
2909
|
+
type = module_context.instance_type
|
|
2910
|
+
when AST::Types::Class
|
|
2911
|
+
type = module_context.module_type
|
|
2912
|
+
end
|
|
2762
2913
|
|
|
2763
|
-
|
|
2764
|
-
TypeInference::MethodCall::Error.new(
|
|
2765
|
-
node: node,
|
|
2766
|
-
context: context.method_context,
|
|
2767
|
-
method_name: method_name,
|
|
2768
|
-
receiver_type: receiver_type,
|
|
2769
|
-
errors: [error]
|
|
2770
|
-
)
|
|
2771
|
-
)
|
|
2914
|
+
checker.factory.interface(type, private: private, self_type: self_type)
|
|
2772
2915
|
end
|
|
2773
2916
|
|
|
2774
2917
|
def expand_self(type)
|
|
@@ -3061,6 +3204,8 @@ module Steep
|
|
|
3061
3204
|
s = constraints.solution(
|
|
3062
3205
|
checker,
|
|
3063
3206
|
self_type: self_type,
|
|
3207
|
+
instance_type: module_context.instance_type,
|
|
3208
|
+
class_type: module_context.module_type,
|
|
3064
3209
|
variance: variance,
|
|
3065
3210
|
variables: method_type.type.params.free_variables + method_type.block.type.params.free_variables
|
|
3066
3211
|
)
|
|
@@ -3082,7 +3227,14 @@ module Steep
|
|
|
3082
3227
|
|
|
3083
3228
|
case result
|
|
3084
3229
|
when Subtyping::Result::Success
|
|
3085
|
-
s = constraints.solution(
|
|
3230
|
+
s = constraints.solution(
|
|
3231
|
+
checker,
|
|
3232
|
+
self_type: self_type,
|
|
3233
|
+
instance_type: module_context.instance_type,
|
|
3234
|
+
class_type: module_context.module_type,
|
|
3235
|
+
variance: variance,
|
|
3236
|
+
variables: fresh_vars
|
|
3237
|
+
)
|
|
3086
3238
|
method_type = method_type.subst(s)
|
|
3087
3239
|
|
|
3088
3240
|
return_type = method_type.type.return_type
|
|
@@ -3127,7 +3279,14 @@ module Steep
|
|
|
3127
3279
|
message: "Unsupported block params pattern, probably masgn?"
|
|
3128
3280
|
)
|
|
3129
3281
|
|
|
3130
|
-
s = constraints.solution(
|
|
3282
|
+
s = constraints.solution(
|
|
3283
|
+
checker,
|
|
3284
|
+
variance: variance,
|
|
3285
|
+
variables: fresh_vars,
|
|
3286
|
+
self_type: self_type,
|
|
3287
|
+
instance_type: module_context.instance_type,
|
|
3288
|
+
class_type: module_context.module_type
|
|
3289
|
+
)
|
|
3131
3290
|
method_type = method_type.subst(s)
|
|
3132
3291
|
end
|
|
3133
3292
|
else
|
|
@@ -3144,35 +3303,73 @@ module Steep
|
|
|
3144
3303
|
end
|
|
3145
3304
|
else
|
|
3146
3305
|
# block is not given
|
|
3147
|
-
if
|
|
3148
|
-
# Method
|
|
3306
|
+
if !method_type.block
|
|
3307
|
+
# Method doesn't accept blocks
|
|
3149
3308
|
unless args.block_pass_arg
|
|
3150
3309
|
# OK, without block
|
|
3151
|
-
s = constraints.solution(
|
|
3310
|
+
s = constraints.solution(
|
|
3311
|
+
checker,
|
|
3312
|
+
variance: variance,
|
|
3313
|
+
variables: fresh_vars,
|
|
3314
|
+
self_type: self_type,
|
|
3315
|
+
instance_type: module_context.instance_type,
|
|
3316
|
+
class_type: module_context.module_type
|
|
3317
|
+
)
|
|
3152
3318
|
method_type = method_type.subst(s)
|
|
3153
3319
|
else
|
|
3154
3320
|
# &block arg is given
|
|
3155
|
-
s = constraints.solution(
|
|
3321
|
+
s = constraints.solution(
|
|
3322
|
+
checker,
|
|
3323
|
+
variance: variance,
|
|
3324
|
+
variables: fresh_vars,
|
|
3325
|
+
self_type: self_type,
|
|
3326
|
+
instance_type: module_context.instance_type,
|
|
3327
|
+
class_type: module_context.module_type
|
|
3328
|
+
)
|
|
3156
3329
|
method_type = method_type.subst(s)
|
|
3157
3330
|
|
|
3158
|
-
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3331
|
+
type, constr = constr.synthesize(args.block_pass_arg, hint: AST::Builtin.nil_type)
|
|
3332
|
+
type = expand_alias(type)
|
|
3333
|
+
unless type.is_a?(AST::Types::Nil)
|
|
3334
|
+
errors << Diagnostic::Ruby::UnexpectedBlockGiven.new(
|
|
3335
|
+
node: node,
|
|
3336
|
+
method_type: method_type
|
|
3337
|
+
)
|
|
3338
|
+
end
|
|
3162
3339
|
end
|
|
3163
3340
|
else
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3167
|
-
|
|
3168
|
-
|
|
3169
|
-
|
|
3341
|
+
# Method accepts block
|
|
3342
|
+
if !args.block_pass_arg
|
|
3343
|
+
# Block pass is not given
|
|
3344
|
+
if method_type.block.required?
|
|
3345
|
+
# Required block is missing
|
|
3346
|
+
errors << Diagnostic::Ruby::RequiredBlockMissing.new(
|
|
3347
|
+
node: node,
|
|
3348
|
+
method_type: method_type
|
|
3349
|
+
)
|
|
3350
|
+
end
|
|
3170
3351
|
|
|
3171
|
-
s = constraints.solution(
|
|
3352
|
+
s = constraints.solution(
|
|
3353
|
+
checker,
|
|
3354
|
+
variance: variance,
|
|
3355
|
+
variables: fresh_vars,
|
|
3356
|
+
self_type: self_type,
|
|
3357
|
+
instance_type: module_context.instance_type,
|
|
3358
|
+
class_type: module_context.module_type
|
|
3359
|
+
)
|
|
3172
3360
|
method_type = method_type.subst(s)
|
|
3173
3361
|
else
|
|
3174
3362
|
begin
|
|
3175
|
-
method_type = method_type.subst(
|
|
3363
|
+
method_type = method_type.subst(
|
|
3364
|
+
constraints.solution(
|
|
3365
|
+
checker,
|
|
3366
|
+
self_type: self_type,
|
|
3367
|
+
instance_type: module_context.instance_type,
|
|
3368
|
+
class_type: module_context.module_type,
|
|
3369
|
+
variance: variance,
|
|
3370
|
+
variables: occurence.params
|
|
3371
|
+
)
|
|
3372
|
+
)
|
|
3176
3373
|
hint_type = if topdown_hint
|
|
3177
3374
|
AST::Types::Proc.new(type: method_type.block.type, block: nil)
|
|
3178
3375
|
end
|
|
@@ -3196,7 +3393,16 @@ module Steep
|
|
|
3196
3393
|
)
|
|
3197
3394
|
end
|
|
3198
3395
|
|
|
3199
|
-
method_type = method_type.subst(
|
|
3396
|
+
method_type = method_type.subst(
|
|
3397
|
+
constraints.solution(
|
|
3398
|
+
checker,
|
|
3399
|
+
self_type: self_type,
|
|
3400
|
+
instance_type: module_context.instance_type,
|
|
3401
|
+
class_type: module_context.module_type,
|
|
3402
|
+
variance: variance,
|
|
3403
|
+
variables: method_type.free_variables
|
|
3404
|
+
)
|
|
3405
|
+
)
|
|
3200
3406
|
end
|
|
3201
3407
|
end
|
|
3202
3408
|
end
|
|
@@ -3231,6 +3437,16 @@ module Steep
|
|
|
3231
3437
|
end
|
|
3232
3438
|
|
|
3233
3439
|
def type_block_without_hint(node:, block_annotations:, block_params:, block_body:, &block)
|
|
3440
|
+
unless block_params
|
|
3441
|
+
typing.add_error(
|
|
3442
|
+
Diagnostic::Ruby::UnsupportedSyntax.new(
|
|
3443
|
+
node: node.children[1],
|
|
3444
|
+
message: "Unsupported block params pattern, probably masgn?"
|
|
3445
|
+
)
|
|
3446
|
+
)
|
|
3447
|
+
block_params = TypeInference::BlockParams.new(leading_params: [], optional_params: [], rest_param: nil, trailing_params: [])
|
|
3448
|
+
end
|
|
3449
|
+
|
|
3234
3450
|
block_constr = for_block(
|
|
3235
3451
|
block_params: block_params,
|
|
3236
3452
|
block_param_hint: nil,
|
|
@@ -3267,12 +3483,12 @@ module Steep
|
|
|
3267
3483
|
param_types_hash = {}
|
|
3268
3484
|
if block_param_pairs
|
|
3269
3485
|
block_param_pairs.each do |param, type|
|
|
3270
|
-
var_name = param.var
|
|
3486
|
+
var_name = param.var
|
|
3271
3487
|
param_types_hash[var_name] = type
|
|
3272
3488
|
end
|
|
3273
3489
|
else
|
|
3274
3490
|
block_params.each do |param|
|
|
3275
|
-
var_name = param.var
|
|
3491
|
+
var_name = param.var
|
|
3276
3492
|
param_types_hash[var_name] = param.type || AST::Builtin.any_type
|
|
3277
3493
|
end
|
|
3278
3494
|
end
|
|
@@ -3300,6 +3516,23 @@ module Steep
|
|
|
3300
3516
|
next_type: block_context.body_type
|
|
3301
3517
|
)
|
|
3302
3518
|
|
|
3519
|
+
self_type = self.self_type
|
|
3520
|
+
module_context = self.module_context
|
|
3521
|
+
|
|
3522
|
+
if implements = block_annotations.implement_module_annotation
|
|
3523
|
+
module_context = default_module_context(
|
|
3524
|
+
implements.name,
|
|
3525
|
+
const_env: self.module_context.const_env,
|
|
3526
|
+
current_namespace: current_namespace
|
|
3527
|
+
)
|
|
3528
|
+
|
|
3529
|
+
self_type = module_context.module_type
|
|
3530
|
+
end
|
|
3531
|
+
|
|
3532
|
+
if annotation_self_type = block_annotations.self_type
|
|
3533
|
+
self_type = annotation_self_type
|
|
3534
|
+
end
|
|
3535
|
+
|
|
3303
3536
|
self.class.new(
|
|
3304
3537
|
checker: checker,
|
|
3305
3538
|
source: source,
|
|
@@ -3310,7 +3543,7 @@ module Steep
|
|
|
3310
3543
|
method_context: method_context,
|
|
3311
3544
|
module_context: module_context,
|
|
3312
3545
|
break_context: break_context,
|
|
3313
|
-
self_type:
|
|
3546
|
+
self_type: self_type,
|
|
3314
3547
|
type_env: type_env.dup,
|
|
3315
3548
|
lvar_env: lvar_env,
|
|
3316
3549
|
call_context: self.context.call_context
|
|
@@ -3380,13 +3613,13 @@ module Steep
|
|
|
3380
3613
|
nodes.each do |node|
|
|
3381
3614
|
if node.type == :kwarg
|
|
3382
3615
|
name = node.children[0]
|
|
3383
|
-
ty = type.params.required_keywords[name
|
|
3616
|
+
ty = type.params.required_keywords[name]
|
|
3384
3617
|
env[name] = ty if ty
|
|
3385
3618
|
end
|
|
3386
3619
|
|
|
3387
3620
|
if node.type == :kwoptarg
|
|
3388
3621
|
name = node.children[0]
|
|
3389
|
-
ty = type.params.optional_keywords[name
|
|
3622
|
+
ty = type.params.optional_keywords[name]
|
|
3390
3623
|
env[name] = ty if ty
|
|
3391
3624
|
end
|
|
3392
3625
|
|
|
@@ -3568,6 +3801,8 @@ module Steep
|
|
|
3568
3801
|
each_child_node(node) do |child|
|
|
3569
3802
|
type_any_rec(child)
|
|
3570
3803
|
end
|
|
3804
|
+
|
|
3805
|
+
Pair.new(type: AST::Builtin.any_type, constr: self)
|
|
3571
3806
|
end
|
|
3572
3807
|
|
|
3573
3808
|
def fallback_any_rec(node)
|
|
@@ -3595,9 +3830,9 @@ module Steep
|
|
|
3595
3830
|
def self.value_variables(node)
|
|
3596
3831
|
case node&.type
|
|
3597
3832
|
when :lvar
|
|
3598
|
-
Set.new([node.children.first
|
|
3833
|
+
Set.new([node.children.first])
|
|
3599
3834
|
when :lvasgn
|
|
3600
|
-
Set.new([node.children.first
|
|
3835
|
+
Set.new([node.children.first]) + value_variables(node.children[1])
|
|
3601
3836
|
when :begin
|
|
3602
3837
|
value_variables(node.children.last)
|
|
3603
3838
|
else
|