steep 0.42.0 → 0.43.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/lib/steep.rb +4 -3
- data/lib/steep/annotation_parser.rb +10 -2
- data/lib/steep/cli.rb +1 -0
- data/lib/steep/diagnostic/ruby.rb +15 -6
- data/lib/steep/diagnostic/signature.rb +28 -11
- data/lib/steep/drivers/annotations.rb +1 -3
- data/lib/steep/drivers/check.rb +17 -7
- data/lib/steep/drivers/diagnostic_printer.rb +4 -0
- data/lib/steep/drivers/langserver.rb +1 -0
- data/lib/steep/drivers/print_project.rb +1 -1
- data/lib/steep/drivers/stats.rb +125 -105
- data/lib/steep/drivers/utils/driver_helper.rb +35 -0
- data/lib/steep/drivers/validate.rb +1 -1
- data/lib/steep/drivers/watch.rb +12 -10
- data/lib/steep/index/signature_symbol_provider.rb +20 -6
- data/lib/steep/project/target.rb +4 -4
- data/lib/steep/server/interaction_worker.rb +2 -3
- data/lib/steep/server/master.rb +621 -170
- data/lib/steep/server/type_check_worker.rb +127 -13
- data/lib/steep/server/worker_process.rb +7 -4
- data/lib/steep/services/completion_provider.rb +2 -2
- data/lib/steep/services/hover_content.rb +5 -4
- data/lib/steep/services/path_assignment.rb +6 -8
- data/lib/steep/services/signature_service.rb +43 -9
- data/lib/steep/services/type_check_service.rb +184 -138
- data/lib/steep/signature/validator.rb +17 -9
- data/lib/steep/source.rb +21 -18
- data/lib/steep/subtyping/constraints.rb +2 -2
- data/lib/steep/type_construction.rb +223 -125
- data/lib/steep/type_inference/block_params.rb +1 -1
- data/lib/steep/type_inference/context.rb +22 -0
- data/lib/steep/type_inference/logic.rb +1 -1
- data/lib/steep/type_inference/logic_type_interpreter.rb +3 -3
- data/lib/steep/version.rb +1 -1
- data/smoke/implements/b.rb +13 -0
- data/smoke/implements/b.rbs +12 -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/masgn.rb +4 -0
- data/smoke/regression/test_expectations.yml +29 -0
- data/smoke/regression/thread.rb +7 -0
- data/smoke/super/test_expectations.yml +2 -12
- data/steep.gemspec +2 -2
- metadata +40 -20
@@ -252,20 +252,28 @@ module Steep
|
|
252
252
|
|
253
253
|
def validate_const
|
254
254
|
env.constant_decls.each do |name, entry|
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
255
|
+
validate_one_constant(name, entry)
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
def validate_one_constant(name, entry)
|
260
|
+
rescue_validation_errors do
|
261
|
+
Steep.logger.debug "Validating constant `#{name}`..."
|
262
|
+
builder.ensure_namespace!(name.namespace, location: entry.decl.location)
|
263
|
+
validate_type entry.decl.type
|
260
264
|
end
|
261
265
|
end
|
262
266
|
|
263
267
|
def validate_global
|
264
268
|
env.global_decls.each do |name, entry|
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
+
validate_one_global(name, entry)
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
def validate_one_global(name, entry)
|
274
|
+
rescue_validation_errors do
|
275
|
+
Steep.logger.debug "Validating global `#{name}`..."
|
276
|
+
validate_type entry.decl.type
|
269
277
|
end
|
270
278
|
end
|
271
279
|
|
data/lib/steep/source.rb
CHANGED
@@ -44,16 +44,10 @@ module Steep
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
|
-
def self.parse(source_code, path:, factory
|
47
|
+
def self.parse(source_code, path:, factory:)
|
48
48
|
buffer = ::Parser::Source::Buffer.new(path.to_s, 1)
|
49
49
|
buffer.source = source_code
|
50
|
-
node = parser.parse(buffer)
|
51
|
-
if n
|
52
|
-
labeling.translate(n, {})
|
53
|
-
else
|
54
|
-
return new(path: path, node: nil, mapping: {})
|
55
|
-
end
|
56
|
-
end
|
50
|
+
node = parser.parse(buffer)
|
57
51
|
|
58
52
|
annotations = []
|
59
53
|
|
@@ -78,13 +72,13 @@ module Steep
|
|
78
72
|
end
|
79
73
|
end
|
80
74
|
|
81
|
-
mapping = {}
|
75
|
+
mapping = {}.compare_by_identity
|
82
76
|
|
83
77
|
construct_mapping(node: node, annotations: annotations, mapping: mapping)
|
84
78
|
|
85
79
|
annotations.each do |annot|
|
86
|
-
mapping[node
|
87
|
-
mapping[node
|
80
|
+
mapping[node] ||= []
|
81
|
+
mapping[node] << annot
|
88
82
|
end
|
89
83
|
|
90
84
|
new(path: path, node: node, mapping: mapping)
|
@@ -262,8 +256,8 @@ module Steep
|
|
262
256
|
end
|
263
257
|
|
264
258
|
associated_annotations.each do |annot|
|
265
|
-
mapping[node
|
266
|
-
mapping[node
|
259
|
+
mapping[node] ||= []
|
260
|
+
mapping[node] << annot
|
267
261
|
annotations.delete annot
|
268
262
|
end
|
269
263
|
end
|
@@ -290,17 +284,16 @@ module Steep
|
|
290
284
|
|
291
285
|
def annotations(block:, factory:, current_module:)
|
292
286
|
AST::Annotation::Collection.new(
|
293
|
-
annotations: mapping[block
|
287
|
+
annotations: (mapping[block] || []).map(&:annotation),
|
294
288
|
factory: factory,
|
295
289
|
current_module: current_module
|
296
290
|
)
|
297
291
|
end
|
298
292
|
|
299
|
-
def each_annotation
|
293
|
+
def each_annotation(&block)
|
300
294
|
if block_given?
|
301
|
-
mapping.
|
302
|
-
node
|
303
|
-
yield node, mapping[id]
|
295
|
+
mapping.each do |node, annots|
|
296
|
+
yield node, annots.map(&:annotation)
|
304
297
|
end
|
305
298
|
else
|
306
299
|
enum_for :each_annotation
|
@@ -356,6 +349,16 @@ module Steep
|
|
356
349
|
|
357
350
|
node_ = Source.delete_defs(node, defs)
|
358
351
|
|
352
|
+
mapping = {}.compare_by_identity
|
353
|
+
|
354
|
+
annotations = self.mapping.values.flatten
|
355
|
+
Source.construct_mapping(node: node_, annotations: annotations, mapping: mapping)
|
356
|
+
|
357
|
+
annotations.each do |annot|
|
358
|
+
mapping[node] ||= []
|
359
|
+
mapping[node] << annot
|
360
|
+
end
|
361
|
+
|
359
362
|
Source.new(path: path, node: node_, mapping: mapping)
|
360
363
|
end
|
361
364
|
|
@@ -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,7 +203,7 @@ 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
|
|
@@ -223,7 +223,7 @@ module Steep
|
|
223
223
|
lvar_env = lvar_env.update(
|
224
224
|
assigned_types: var_types.each.with_object({}) {|(var, type), hash|
|
225
225
|
arg_node = args.find {|arg| arg.children[0] == var }
|
226
|
-
hash[var
|
226
|
+
hash[var] = TypeInference::LocalVariableTypeEnv::Entry.new(type: type, nodes: [arg_node].compact)
|
227
227
|
}
|
228
228
|
)
|
229
229
|
end
|
@@ -296,6 +296,41 @@ module Steep
|
|
296
296
|
end
|
297
297
|
end
|
298
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
|
+
|
299
334
|
def for_module(node)
|
300
335
|
new_module_name = module_name_from_node(node.children.first) or raise "Unexpected module name: #{node.children.first}"
|
301
336
|
new_namespace = nested_namespace_for_module(new_module_name)
|
@@ -304,64 +339,55 @@ module Steep
|
|
304
339
|
module_const_env = TypeInference::ConstantEnv.new(factory: checker.factory, context: const_context)
|
305
340
|
|
306
341
|
annots = source.annotations(block: node, factory: checker.factory, current_module: new_namespace)
|
307
|
-
module_type = AST::Builtin::Module.instance_type
|
308
342
|
|
309
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
|
310
349
|
|
311
350
|
if implement_module_name
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
checker.factory.type(type)
|
339
|
-
},
|
340
|
-
AST::Types::Name::Instance.new(name: module_name, args: module_args)
|
341
|
-
].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
|
+
)
|
342
377
|
)
|
343
|
-
|
344
|
-
module_type = AST::Types::Name::Singleton.new(name: module_name)
|
345
378
|
end
|
346
379
|
|
347
380
|
if annots.instance_type
|
348
|
-
|
381
|
+
module_context = module_context.update(instance_type: annots.instance_type)
|
349
382
|
end
|
350
383
|
|
351
384
|
if annots.module_type
|
352
|
-
|
353
|
-
end
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
implement_name: implement_module_name,
|
359
|
-
current_namespace: new_namespace,
|
360
|
-
const_env: module_const_env,
|
361
|
-
class_name: absolute_name(new_module_name),
|
362
|
-
instance_definition: instance_def,
|
363
|
-
module_definition: module_def
|
364
|
-
)
|
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
|
365
391
|
|
366
392
|
module_type_env = TypeInference::TypeEnv.build(annotations: annots,
|
367
393
|
subtyping: checker,
|
@@ -370,9 +396,9 @@ module Steep
|
|
370
396
|
|
371
397
|
lvar_env = TypeInference::LocalVariableTypeEnv.empty(
|
372
398
|
subtyping: checker,
|
373
|
-
self_type:
|
374
|
-
instance_type:
|
375
|
-
class_type:
|
399
|
+
self_type: module_context.module_type,
|
400
|
+
instance_type: module_context.instance_type,
|
401
|
+
class_type: module_context.module_type
|
376
402
|
).annotate(annots)
|
377
403
|
|
378
404
|
self.class.new(
|
@@ -384,11 +410,11 @@ module Steep
|
|
384
410
|
method_context: nil,
|
385
411
|
block_context: nil,
|
386
412
|
break_context: nil,
|
387
|
-
module_context:
|
388
|
-
self_type:
|
413
|
+
module_context: module_context,
|
414
|
+
self_type: module_context.module_type,
|
389
415
|
type_env: module_type_env,
|
390
416
|
lvar_env: lvar_env,
|
391
|
-
call_context: TypeInference::MethodCall::ModuleContext.new(type_name:
|
417
|
+
call_context: TypeInference::MethodCall::ModuleContext.new(type_name: module_context.class_name)
|
392
418
|
)
|
393
419
|
)
|
394
420
|
end
|
@@ -400,48 +426,37 @@ module Steep
|
|
400
426
|
|
401
427
|
annots = source.annotations(block: node, factory: checker.factory, current_module: new_namespace)
|
402
428
|
|
403
|
-
|
429
|
+
const_context = [new_namespace] + self.module_context.const_env.context
|
430
|
+
class_const_env = TypeInference::ConstantEnv.new(factory: checker.factory, context: const_context)
|
404
431
|
|
405
|
-
|
406
|
-
|
407
|
-
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)
|
408
434
|
|
409
435
|
if implement_module_name
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
instance_type = AST::Types::Name::Instance.new(name: class_name, args: class_args)
|
418
|
-
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
|
419
442
|
else
|
420
|
-
|
421
|
-
|
443
|
+
module_context = module_context.update(
|
444
|
+
instance_type: AST::Builtin::Object.instance_type,
|
445
|
+
module_type: AST::Builtin::Object.module_type
|
446
|
+
)
|
422
447
|
end
|
423
448
|
|
424
449
|
if annots.instance_type
|
425
|
-
|
450
|
+
module_context = module_context.update(instance_type: annots.instance_type)
|
426
451
|
end
|
427
452
|
|
428
453
|
if annots.module_type
|
429
|
-
|
454
|
+
module_context = module_context.update(module_type: annots.module_type)
|
430
455
|
end
|
431
456
|
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
module_context = TypeInference::Context::ModuleContext.new(
|
436
|
-
instance_type: annots.instance_type || instance_type,
|
437
|
-
module_type: annots.self_type || annots.module_type || module_type,
|
438
|
-
implement_name: implement_module_name,
|
439
|
-
current_namespace: new_namespace,
|
440
|
-
const_env: class_const_env,
|
441
|
-
class_name: absolute_name(new_class_name),
|
442
|
-
module_definition: module_def,
|
443
|
-
instance_definition: instance_def
|
444
|
-
)
|
457
|
+
if annots.self_type
|
458
|
+
module_context = module_context.update(module_type: annots.self_type)
|
459
|
+
end
|
445
460
|
|
446
461
|
class_type_env = TypeInference::TypeEnv.build(annotations: annots,
|
447
462
|
subtyping: checker,
|
@@ -707,7 +722,7 @@ module Steep
|
|
707
722
|
when :lvasgn
|
708
723
|
yield_self do
|
709
724
|
var, rhs = node.children
|
710
|
-
name = var
|
725
|
+
name = var
|
711
726
|
|
712
727
|
case name
|
713
728
|
when :_, :__any__
|
@@ -743,7 +758,7 @@ module Steep
|
|
743
758
|
when :lvar
|
744
759
|
yield_self do
|
745
760
|
var = node.children[0]
|
746
|
-
if (type = context.lvar_env[var
|
761
|
+
if (type = context.lvar_env[var])
|
747
762
|
add_typing node, type: type
|
748
763
|
else
|
749
764
|
fallback_to_any(node)
|
@@ -884,7 +899,27 @@ module Steep
|
|
884
899
|
block_body: nil,
|
885
900
|
topdown_hint: true)
|
886
901
|
|
887
|
-
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
|
888
923
|
else
|
889
924
|
fallback_to_any node do
|
890
925
|
Diagnostic::Ruby::UnexpectedSuper.new(node: node, method: method_context.name)
|
@@ -1148,15 +1183,45 @@ module Steep
|
|
1148
1183
|
add_typing(node, type: AST::Builtin.bottom_type)
|
1149
1184
|
|
1150
1185
|
when :retry
|
1151
|
-
unless break_context
|
1152
|
-
typing.add_error Diagnostic::Ruby::UnexpectedJump.new(node: node)
|
1153
|
-
end
|
1154
1186
|
add_typing(node, type: AST::Builtin.bottom_type)
|
1155
1187
|
|
1156
|
-
when :
|
1188
|
+
when :procarg0
|
1189
|
+
yield_self do
|
1190
|
+
constr = self
|
1191
|
+
|
1192
|
+
node.children.each do |arg|
|
1193
|
+
if arg.is_a?(Symbol)
|
1194
|
+
type = context.lvar_env[arg]
|
1195
|
+
|
1196
|
+
if type
|
1197
|
+
_, constr = add_typing(node, type: type)
|
1198
|
+
else
|
1199
|
+
type = AST::Builtin.any_type
|
1200
|
+
_, constr = lvasgn(node, type)
|
1201
|
+
end
|
1202
|
+
else
|
1203
|
+
_, constr = constr.synthesize(arg)
|
1204
|
+
end
|
1205
|
+
end
|
1206
|
+
|
1207
|
+
Pair.new(constr: constr, type: AST::Builtin.any_type)
|
1208
|
+
end
|
1209
|
+
|
1210
|
+
when :mlhs
|
1211
|
+
yield_self do
|
1212
|
+
constr = self
|
1213
|
+
|
1214
|
+
node.children.each do |arg|
|
1215
|
+
_, constr = constr.synthesize(arg)
|
1216
|
+
end
|
1217
|
+
|
1218
|
+
Pair.new(constr: constr, type: AST::Builtin.any_type)
|
1219
|
+
end
|
1220
|
+
|
1221
|
+
when :arg, :kwarg
|
1157
1222
|
yield_self do
|
1158
1223
|
var = node.children[0]
|
1159
|
-
type = context.lvar_env[var
|
1224
|
+
type = context.lvar_env[var]
|
1160
1225
|
|
1161
1226
|
if type
|
1162
1227
|
add_typing(node, type: type)
|
@@ -1171,13 +1236,13 @@ module Steep
|
|
1171
1236
|
var = node.children[0]
|
1172
1237
|
rhs = node.children[1]
|
1173
1238
|
|
1174
|
-
var_type = context.lvar_env[var
|
1239
|
+
var_type = context.lvar_env[var]
|
1175
1240
|
node_type, constr = synthesize(rhs, hint: var_type)
|
1176
1241
|
|
1177
1242
|
type = AST::Types::Union.build(types: [var_type, node_type])
|
1178
1243
|
|
1179
1244
|
constr_ = constr.update_lvar_env do |env|
|
1180
|
-
env.assign(var
|
1245
|
+
env.assign(var, node: node, type: type) do |declared_type, type, result|
|
1181
1246
|
typing.add_error(
|
1182
1247
|
Diagnostic::Ruby::IncompatibleAssignment.new(
|
1183
1248
|
node: node,
|
@@ -1195,7 +1260,7 @@ module Steep
|
|
1195
1260
|
when :restarg
|
1196
1261
|
yield_self do
|
1197
1262
|
var = node.children[0]
|
1198
|
-
type = context.lvar_env[var
|
1263
|
+
type = context.lvar_env[var]
|
1199
1264
|
unless type
|
1200
1265
|
if context&.method_context&.method_type
|
1201
1266
|
Steep.logger.error { "Unknown variable: #{node}" }
|
@@ -1210,7 +1275,7 @@ module Steep
|
|
1210
1275
|
when :kwrestarg
|
1211
1276
|
yield_self do
|
1212
1277
|
var = node.children[0]
|
1213
|
-
type = context.lvar_env[var
|
1278
|
+
type = context.lvar_env[var]
|
1214
1279
|
unless type
|
1215
1280
|
if context&.method_context&.method_type
|
1216
1281
|
Steep.logger.error { "Unknown variable: #{node}" }
|
@@ -1546,8 +1611,10 @@ module Steep
|
|
1546
1611
|
}
|
1547
1612
|
add_typing(node, type: union_type(*types))
|
1548
1613
|
else
|
1549
|
-
|
1550
|
-
fallback_to_any
|
1614
|
+
|
1615
|
+
fallback_to_any(node) do
|
1616
|
+
Diagnostic::Ruby::UnexpectedSuper.new(node: node, method: method_context.name)
|
1617
|
+
end
|
1551
1618
|
end
|
1552
1619
|
else
|
1553
1620
|
fallback_to_any node
|
@@ -1574,8 +1641,7 @@ module Steep
|
|
1574
1641
|
if hint && !(tuples = select_flatten_types(hint) {|type| type.is_a?(AST::Types::Tuple) }).empty?
|
1575
1642
|
tuples.each do |tuple|
|
1576
1643
|
typing.new_child(node_range) do |child_typing|
|
1577
|
-
pair = with_new_typing(child_typing).try_tuple_type(node, tuple)
|
1578
|
-
if pair && pair.constr.check_relation(sub_type: pair.type, super_type: hint).success?
|
1644
|
+
if pair = with_new_typing(child_typing).try_tuple_type(node, tuple)
|
1579
1645
|
child_typing.save!
|
1580
1646
|
return pair.with(constr: pair.constr.with_new_typing(typing))
|
1581
1647
|
end
|
@@ -1746,12 +1812,7 @@ module Steep
|
|
1746
1812
|
_, cond_vars = interpreter.decompose_value(cond)
|
1747
1813
|
unless cond_vars.empty?
|
1748
1814
|
first_var = cond_vars.to_a[0]
|
1749
|
-
var_node = cond.updated(
|
1750
|
-
:lvar,
|
1751
|
-
[
|
1752
|
-
ASTUtils::Labeling::LabeledName.new(name: first_var, label: 0)
|
1753
|
-
]
|
1754
|
-
)
|
1815
|
+
var_node = cond.updated(:lvar, [first_var])
|
1755
1816
|
else
|
1756
1817
|
first_var = nil
|
1757
1818
|
var_node = cond
|
@@ -1892,7 +1953,7 @@ module Steep
|
|
1892
1953
|
if assignment
|
1893
1954
|
case assignment.type
|
1894
1955
|
when :lvasgn
|
1895
|
-
var_name = assignment.children[0]
|
1956
|
+
var_name = assignment.children[0]
|
1896
1957
|
else
|
1897
1958
|
Steep.logger.error "Unexpected rescue variable assignment: #{assignment.type}"
|
1898
1959
|
end
|
@@ -1981,7 +2042,7 @@ module Steep
|
|
1981
2042
|
if var_type
|
1982
2043
|
if body
|
1983
2044
|
body_constr = constr.with_updated_context(
|
1984
|
-
lvar_env: constr.context.lvar_env.assign(asgn.children[0]
|
2045
|
+
lvar_env: constr.context.lvar_env.assign(asgn.children[0], node: asgn, type: var_type)
|
1985
2046
|
)
|
1986
2047
|
|
1987
2048
|
typing.add_context_for_body(node, context: body_constr.context)
|
@@ -2295,6 +2356,11 @@ module Steep
|
|
2295
2356
|
raise "#synthesize should return an instance of Pair: #{pair.class}, node=#{node.inspect}"
|
2296
2357
|
end
|
2297
2358
|
end
|
2359
|
+
rescue RBS::ErrorBase => exn
|
2360
|
+
Steep.logger.warn { "Unexpected RBS error: #{exn.message}" }
|
2361
|
+
exn.backtrace.each {|loc| Steep.logger.warn " #{loc}" }
|
2362
|
+
typing.add_error(Diagnostic::Ruby::UnexpectedError.new(node: node, error: exn))
|
2363
|
+
type_any_rec(node)
|
2298
2364
|
rescue StandardError => exn
|
2299
2365
|
Steep.log_error exn
|
2300
2366
|
typing.add_error(Diagnostic::Ruby::UnexpectedError.new(node: node, error: exn))
|
@@ -2344,16 +2410,16 @@ module Steep
|
|
2344
2410
|
def masgn_lhs?(lhs)
|
2345
2411
|
lhs.children.all? do |a|
|
2346
2412
|
asgn_type = if a.type == :splat
|
2347
|
-
a.children[0]
|
2413
|
+
a.children[0]&.type
|
2348
2414
|
else
|
2349
2415
|
a.type
|
2350
2416
|
end
|
2351
|
-
asgn_type == :lvasgn || asgn_type == :ivasgn
|
2417
|
+
asgn_type.nil? || asgn_type == :lvasgn || asgn_type == :ivasgn
|
2352
2418
|
end
|
2353
2419
|
end
|
2354
2420
|
|
2355
2421
|
def lvasgn(node, type)
|
2356
|
-
name = node.children[0]
|
2422
|
+
name = node.children[0]
|
2357
2423
|
env = context.lvar_env.assign(name, node: node, type: type) do |declared_type, type, result|
|
2358
2424
|
typing.add_error(
|
2359
2425
|
Diagnostic::Ruby::IncompatibleAssignment.new(
|
@@ -2494,7 +2560,7 @@ module Steep
|
|
2494
2560
|
assignment_nodes.each do |asgn|
|
2495
2561
|
case asgn.type
|
2496
2562
|
when :splat
|
2497
|
-
case asgn.children[0]
|
2563
|
+
case asgn.children[0]&.type
|
2498
2564
|
when :lvasgn
|
2499
2565
|
_, constr = constr.lvasgn(asgn.children[0], array_type)
|
2500
2566
|
when :ivasgn
|
@@ -2720,6 +2786,7 @@ module Steep
|
|
2720
2786
|
end
|
2721
2787
|
|
2722
2788
|
receiver_type = checker.factory.deep_expand_alias(recv_type)
|
2789
|
+
private = receiver.nil? || receiver.type == :self
|
2723
2790
|
|
2724
2791
|
type, constr = case receiver_type
|
2725
2792
|
when nil
|
@@ -2765,7 +2832,7 @@ module Steep
|
|
2765
2832
|
)
|
2766
2833
|
else
|
2767
2834
|
interface = calculate_interface(expanded_self,
|
2768
|
-
private:
|
2835
|
+
private: private,
|
2769
2836
|
self_type: AST::Types::Self.new)
|
2770
2837
|
|
2771
2838
|
constr.type_send_interface(node,
|
@@ -2778,7 +2845,7 @@ module Steep
|
|
2778
2845
|
block_body: block_body)
|
2779
2846
|
end
|
2780
2847
|
else
|
2781
|
-
interface = calculate_interface(receiver_type, private:
|
2848
|
+
interface = calculate_interface(receiver_type, private: private, self_type: receiver_type)
|
2782
2849
|
|
2783
2850
|
constr.type_send_interface(node,
|
2784
2851
|
interface: interface,
|
@@ -3220,10 +3287,14 @@ module Steep
|
|
3220
3287
|
)
|
3221
3288
|
method_type = method_type.subst(s)
|
3222
3289
|
|
3223
|
-
|
3224
|
-
|
3225
|
-
|
3226
|
-
|
3290
|
+
type, constr = constr.synthesize(args.block_pass_arg, hint: AST::Builtin.nil_type)
|
3291
|
+
type = expand_alias(type)
|
3292
|
+
unless type.is_a?(AST::Types::Nil)
|
3293
|
+
errors << Diagnostic::Ruby::UnexpectedBlockGiven.new(
|
3294
|
+
node: node,
|
3295
|
+
method_type: method_type
|
3296
|
+
)
|
3297
|
+
end
|
3227
3298
|
end
|
3228
3299
|
else
|
3229
3300
|
unless args.block_pass_arg
|
@@ -3321,6 +3392,16 @@ module Steep
|
|
3321
3392
|
end
|
3322
3393
|
|
3323
3394
|
def type_block_without_hint(node:, block_annotations:, block_params:, block_body:, &block)
|
3395
|
+
unless block_params
|
3396
|
+
typing.add_error(
|
3397
|
+
Diagnostic::Ruby::UnsupportedSyntax.new(
|
3398
|
+
node: node.children[1],
|
3399
|
+
message: "Unsupported block params pattern, probably masgn?"
|
3400
|
+
)
|
3401
|
+
)
|
3402
|
+
block_params = TypeInference::BlockParams.new(leading_params: [], optional_params: [], rest_param: nil, trailing_params: [])
|
3403
|
+
end
|
3404
|
+
|
3324
3405
|
block_constr = for_block(
|
3325
3406
|
block_params: block_params,
|
3326
3407
|
block_param_hint: nil,
|
@@ -3357,12 +3438,12 @@ module Steep
|
|
3357
3438
|
param_types_hash = {}
|
3358
3439
|
if block_param_pairs
|
3359
3440
|
block_param_pairs.each do |param, type|
|
3360
|
-
var_name = param.var
|
3441
|
+
var_name = param.var
|
3361
3442
|
param_types_hash[var_name] = type
|
3362
3443
|
end
|
3363
3444
|
else
|
3364
3445
|
block_params.each do |param|
|
3365
|
-
var_name = param.var
|
3446
|
+
var_name = param.var
|
3366
3447
|
param_types_hash[var_name] = param.type || AST::Builtin.any_type
|
3367
3448
|
end
|
3368
3449
|
end
|
@@ -3390,6 +3471,23 @@ module Steep
|
|
3390
3471
|
next_type: block_context.body_type
|
3391
3472
|
)
|
3392
3473
|
|
3474
|
+
self_type = self.self_type
|
3475
|
+
module_context = self.module_context
|
3476
|
+
|
3477
|
+
if implements = block_annotations.implement_module_annotation
|
3478
|
+
module_context = default_module_context(
|
3479
|
+
implements.name,
|
3480
|
+
const_env: self.module_context.const_env,
|
3481
|
+
current_namespace: current_namespace
|
3482
|
+
)
|
3483
|
+
|
3484
|
+
self_type = module_context.module_type
|
3485
|
+
end
|
3486
|
+
|
3487
|
+
if annotation_self_type = block_annotations.self_type
|
3488
|
+
self_type = annotation_self_type
|
3489
|
+
end
|
3490
|
+
|
3393
3491
|
self.class.new(
|
3394
3492
|
checker: checker,
|
3395
3493
|
source: source,
|
@@ -3400,7 +3498,7 @@ module Steep
|
|
3400
3498
|
method_context: method_context,
|
3401
3499
|
module_context: module_context,
|
3402
3500
|
break_context: break_context,
|
3403
|
-
self_type:
|
3501
|
+
self_type: self_type,
|
3404
3502
|
type_env: type_env.dup,
|
3405
3503
|
lvar_env: lvar_env,
|
3406
3504
|
call_context: self.context.call_context
|
@@ -3470,13 +3568,13 @@ module Steep
|
|
3470
3568
|
nodes.each do |node|
|
3471
3569
|
if node.type == :kwarg
|
3472
3570
|
name = node.children[0]
|
3473
|
-
ty = type.params.required_keywords[name
|
3571
|
+
ty = type.params.required_keywords[name]
|
3474
3572
|
env[name] = ty if ty
|
3475
3573
|
end
|
3476
3574
|
|
3477
3575
|
if node.type == :kwoptarg
|
3478
3576
|
name = node.children[0]
|
3479
|
-
ty = type.params.optional_keywords[name
|
3577
|
+
ty = type.params.optional_keywords[name]
|
3480
3578
|
env[name] = ty if ty
|
3481
3579
|
end
|
3482
3580
|
|
@@ -3687,9 +3785,9 @@ module Steep
|
|
3687
3785
|
def self.value_variables(node)
|
3688
3786
|
case node&.type
|
3689
3787
|
when :lvar
|
3690
|
-
Set.new([node.children.first
|
3788
|
+
Set.new([node.children.first])
|
3691
3789
|
when :lvasgn
|
3692
|
-
Set.new([node.children.first
|
3790
|
+
Set.new([node.children.first]) + value_variables(node.children[1])
|
3693
3791
|
when :begin
|
3694
3792
|
value_variables(node.children.last)
|
3695
3793
|
else
|