steep 1.8.0.dev.1 → 1.8.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +33 -0
- data/README.md +3 -2
- data/bin/mem_graph.rb +67 -0
- data/bin/mem_prof.rb +102 -0
- data/bin/stackprof_test.rb +19 -0
- data/bin/steep-check.rb +251 -0
- data/guides/src/gem-rbs-collection/gem-rbs-collection.md +1 -1
- data/lib/steep/annotation_parser.rb +1 -1
- data/lib/steep/ast/builtin.rb +5 -5
- data/lib/steep/ast/node/type_application.rb +7 -6
- data/lib/steep/ast/types/any.rb +1 -9
- data/lib/steep/ast/types/boolean.rb +8 -16
- data/lib/steep/ast/types/bot.rb +2 -10
- data/lib/steep/ast/types/class.rb +1 -13
- data/lib/steep/ast/types/factory.rb +101 -85
- data/lib/steep/ast/types/instance.rb +1 -13
- data/lib/steep/ast/types/intersection.rb +8 -15
- data/lib/steep/ast/types/literal.rb +2 -8
- data/lib/steep/ast/types/logic.rb +3 -24
- data/lib/steep/ast/types/name.rb +5 -16
- data/lib/steep/ast/types/nil.rb +3 -12
- data/lib/steep/ast/types/proc.rb +4 -13
- data/lib/steep/ast/types/record.rb +21 -12
- data/lib/steep/ast/types/self.rb +1 -13
- data/lib/steep/ast/types/shared_instance.rb +11 -0
- data/lib/steep/ast/types/top.rb +1 -9
- data/lib/steep/ast/types/tuple.rb +4 -10
- data/lib/steep/ast/types/union.rb +10 -15
- data/lib/steep/ast/types/var.rb +4 -13
- data/lib/steep/ast/types/void.rb +2 -10
- data/lib/steep/diagnostic/ruby.rb +10 -10
- data/lib/steep/drivers/check.rb +11 -14
- data/lib/steep/drivers/checkfile.rb +8 -10
- data/lib/steep/drivers/stats.rb +17 -13
- data/lib/steep/drivers/utils/driver_helper.rb +24 -3
- data/lib/steep/drivers/watch.rb +3 -3
- data/lib/steep/interface/builder.rb +162 -138
- data/lib/steep/interface/method_type.rb +12 -20
- data/lib/steep/interface/shape.rb +66 -10
- data/lib/steep/interface/substitution.rb +2 -0
- data/lib/steep/interface/type_param.rb +20 -7
- data/lib/steep/located_value.rb +20 -0
- data/lib/steep/server/change_buffer.rb +5 -7
- data/lib/steep/server/custom_methods.rb +61 -0
- data/lib/steep/server/delay_queue.rb +8 -1
- data/lib/steep/server/interaction_worker.rb +13 -6
- data/lib/steep/server/lsp_formatter.rb +8 -6
- data/lib/steep/server/master.rb +195 -142
- data/lib/steep/server/type_check_worker.rb +25 -22
- data/lib/steep/server/work_done_progress.rb +64 -0
- data/lib/steep/server/worker_process.rb +1 -1
- data/lib/steep/services/completion_provider.rb +32 -24
- data/lib/steep/services/goto_service.rb +3 -2
- data/lib/steep/services/hover_provider/ruby.rb +30 -17
- data/lib/steep/services/signature_help_provider.rb +9 -7
- data/lib/steep/services/signature_service.rb +1 -1
- data/lib/steep/services/type_check_service.rb +19 -9
- data/lib/steep/signature/validator.rb +17 -20
- data/lib/steep/source.rb +47 -1
- data/lib/steep/subtyping/check.rb +105 -55
- data/lib/steep/subtyping/constraints.rb +13 -17
- data/lib/steep/type_construction.rb +106 -100
- data/lib/steep/type_inference/block_params.rb +8 -5
- data/lib/steep/type_inference/logic_type_interpreter.rb +11 -7
- data/lib/steep/type_inference/method_call.rb +3 -3
- data/lib/steep/type_inference/method_params.rb +1 -1
- data/lib/steep/type_inference/send_args.rb +1 -1
- data/lib/steep/typing.rb +164 -106
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +29 -4
- data/steep.gemspec +2 -2
- metadata +16 -9
- data/lib/steep/type_inference/context_array.rb +0 -112
data/lib/steep/drivers/watch.rb
CHANGED
@@ -59,7 +59,7 @@ module Steep
|
|
59
59
|
end
|
60
60
|
|
61
61
|
initialize_id = request_id()
|
62
|
-
client_writer.write(method: "initialize", id: initialize_id)
|
62
|
+
client_writer.write(method: "initialize", id: initialize_id, params: DEFAULT_CLI_LSP_INITIALIZE_PARAMS)
|
63
63
|
wait_for_response_id(reader: client_reader, id: initialize_id)
|
64
64
|
|
65
65
|
Steep.logger.info "Watching #{dirs.join(", ")}..."
|
@@ -112,7 +112,7 @@ module Steep
|
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
client_writer.write(
|
115
|
+
client_writer.write(Server::CustomMethods::TypeCheck.request(SecureRandom.uuid, { guid: nil }))
|
116
116
|
|
117
117
|
stdout.puts Rainbow("done!").bold
|
118
118
|
end.tap(&:start)
|
@@ -120,7 +120,7 @@ module Steep
|
|
120
120
|
begin
|
121
121
|
stdout.puts Rainbow("👀 Watching directories, Ctrl-C to stop.").bold
|
122
122
|
|
123
|
-
client_writer.write(
|
123
|
+
client_writer.write(Server::CustomMethods::TypeCheck.request(SecureRandom.uuid, { guid: nil }))
|
124
124
|
|
125
125
|
client_reader.read do |response|
|
126
126
|
case response[:method]
|
@@ -277,15 +277,14 @@ module Steep
|
|
277
277
|
|
278
278
|
definition.methods.each do |name, method|
|
279
279
|
Steep.logger.tagged "method = #{type_name}.#{name}" do
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
)
|
280
|
+
overloads = method.defs.map do |type_def|
|
281
|
+
method_name = method_name_for(type_def, name)
|
282
|
+
method_type = factory.method_type(type_def.type)
|
283
|
+
method_type = replace_primitive_method(method_name, type_def, method_type)
|
284
|
+
Shape::MethodOverload.new(method_type, [type_def])
|
285
|
+
end
|
286
|
+
|
287
|
+
shape.methods[name] = Interface::Shape::Entry.new(method_name: name, private_method: method.private?, overloads: overloads)
|
289
288
|
end
|
290
289
|
end
|
291
290
|
|
@@ -308,15 +307,14 @@ module Steep
|
|
308
307
|
|
309
308
|
definition.methods.each do |name, method|
|
310
309
|
Steep.logger.tagged "method = #{type_name}##{name}" do
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
)
|
310
|
+
overloads = method.defs.map do |type_def|
|
311
|
+
method_name = method_name_for(type_def, name)
|
312
|
+
method_type = factory.method_type(type_def.type)
|
313
|
+
method_type = replace_primitive_method(method_name, type_def, method_type)
|
314
|
+
Shape::MethodOverload.new(method_type, [type_def])
|
315
|
+
end
|
316
|
+
|
317
|
+
shape.methods[name] = Interface::Shape::Entry.new(method_name: name, private_method: method.private?, overloads: overloads)
|
320
318
|
end
|
321
319
|
end
|
322
320
|
|
@@ -334,51 +332,49 @@ module Steep
|
|
334
332
|
|
335
333
|
shape = Interface::Shape.new(type: shape_type, private: true)
|
336
334
|
all_common_methods.each do |method_name|
|
337
|
-
|
335
|
+
overloadss = [] #: Array[Array[Shape::MethodOverload]]
|
338
336
|
private_method = false
|
339
337
|
shapes.each do |shape|
|
340
338
|
entry = shape.methods[method_name] || raise
|
341
|
-
|
339
|
+
overloadss << entry.overloads
|
342
340
|
private_method ||= entry.private_method?
|
343
341
|
end
|
344
342
|
|
345
|
-
shape.methods[method_name] = Interface::Shape::Entry.new(private_method: private_method) do
|
346
|
-
|
343
|
+
shape.methods[method_name] = Interface::Shape::Entry.new(method_name: method_name, private_method: private_method) do
|
344
|
+
overloadss.inject do |overloads1, overloads2|
|
347
345
|
# @type break: nil
|
348
346
|
|
349
|
-
|
350
|
-
|
351
|
-
decl_array2 = types2.map(&:method_decls)
|
352
|
-
|
353
|
-
if decl_array1 == decl_array2
|
354
|
-
next types1
|
355
|
-
end
|
347
|
+
types1 = overloads1.map(&:method_type)
|
348
|
+
types2 = overloads2.map(&:method_type)
|
356
349
|
|
357
|
-
|
358
|
-
|
350
|
+
if types1 == types2
|
351
|
+
defs1 = overloads1.flat_map(&:method_defs)
|
352
|
+
defs2 = overloads2.flat_map(&:method_defs)
|
359
353
|
|
360
|
-
if
|
361
|
-
next
|
354
|
+
if defs1 == defs2
|
355
|
+
next overloads1
|
362
356
|
end
|
363
357
|
end
|
364
358
|
|
365
|
-
|
359
|
+
method_overloads = {} #: Hash[Shape::MethodOverload, bool]
|
366
360
|
|
367
|
-
|
368
|
-
|
369
|
-
if
|
370
|
-
|
361
|
+
overloads1.each do |overload1|
|
362
|
+
overloads2.each do |overload2|
|
363
|
+
if overload1.method_type == overload2.method_type
|
364
|
+
overload = Shape::MethodOverload.new(overload1.method_type, overload1.method_defs + overload2.method_defs)
|
365
|
+
method_overloads[overload] = true
|
371
366
|
else
|
372
|
-
if type = MethodType.union(
|
373
|
-
|
367
|
+
if type = MethodType.union(overload1.method_type, overload2.method_type, subtyping)
|
368
|
+
overload = Shape::MethodOverload.new(type, overload1.method_defs + overload2.method_defs)
|
369
|
+
method_overloads[overload] = true
|
374
370
|
end
|
375
371
|
end
|
376
372
|
end
|
377
373
|
end
|
378
374
|
|
379
|
-
break nil if
|
375
|
+
break nil if method_overloads.empty?
|
380
376
|
|
381
|
-
|
377
|
+
method_overloads.keys
|
382
378
|
end
|
383
379
|
end
|
384
380
|
end
|
@@ -427,7 +423,7 @@ module Steep
|
|
427
423
|
end
|
428
424
|
|
429
425
|
def tuple_shape(tuple)
|
430
|
-
element_type = AST::Types::Union.build(types: tuple.types
|
426
|
+
element_type = AST::Types::Union.build(types: tuple.types)
|
431
427
|
array_type = AST::Builtin::Array.instance_type(element_type)
|
432
428
|
|
433
429
|
array_shape = yield(array_type) or raise
|
@@ -438,19 +434,22 @@ module Steep
|
|
438
434
|
raise unless aref
|
439
435
|
|
440
436
|
Shape::Entry.new(
|
437
|
+
method_name: :[],
|
441
438
|
private_method: false,
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
439
|
+
overloads: tuple.types.map.with_index {|elem_type, index|
|
440
|
+
Shape::MethodOverload.new(
|
441
|
+
MethodType.new(
|
442
|
+
type_params: [],
|
443
|
+
type: Function.new(
|
444
|
+
params: Function::Params.build(required: [AST::Types::Literal.new(value: index)]),
|
445
|
+
return_type: elem_type,
|
446
|
+
location: nil
|
447
|
+
),
|
448
|
+
block: nil
|
449
449
|
),
|
450
|
-
|
451
|
-
method_decls: Set[]
|
450
|
+
[]
|
452
451
|
)
|
453
|
-
} + aref.
|
452
|
+
} + aref.overloads
|
454
453
|
)
|
455
454
|
end
|
456
455
|
|
@@ -458,19 +457,22 @@ module Steep
|
|
458
457
|
raise unless update
|
459
458
|
|
460
459
|
Shape::Entry.new(
|
460
|
+
method_name: :[]=,
|
461
461
|
private_method: false,
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
462
|
+
overloads: tuple.types.map.with_index {|elem_type, index|
|
463
|
+
Shape::MethodOverload.new(
|
464
|
+
MethodType.new(
|
465
|
+
type_params: [],
|
466
|
+
type: Function.new(
|
467
|
+
params: Function::Params.build(required: [AST::Types::Literal.new(value: index), elem_type]),
|
468
|
+
return_type: elem_type,
|
469
|
+
location: nil
|
470
|
+
),
|
471
|
+
block: nil
|
469
472
|
),
|
470
|
-
|
471
|
-
method_decls: Set[]
|
473
|
+
[]
|
472
474
|
)
|
473
|
-
} + update.
|
475
|
+
} + update.overloads
|
474
476
|
)
|
475
477
|
end
|
476
478
|
|
@@ -478,8 +480,9 @@ module Steep
|
|
478
480
|
raise unless fetch
|
479
481
|
|
480
482
|
Shape::Entry.new(
|
483
|
+
method_name: :fetch,
|
481
484
|
private_method: false,
|
482
|
-
|
485
|
+
overloads: tuple.types.flat_map.with_index {|elem_type, index|
|
483
486
|
[
|
484
487
|
MethodType.new(
|
485
488
|
type_params: [],
|
@@ -488,11 +491,10 @@ module Steep
|
|
488
491
|
return_type: elem_type,
|
489
492
|
location: nil
|
490
493
|
),
|
491
|
-
block: nil
|
492
|
-
method_decls: Set[]
|
494
|
+
block: nil
|
493
495
|
),
|
494
496
|
MethodType.new(
|
495
|
-
type_params: [TypeParam.new(name: :T, upper_bound: nil, variance: :invariant, unchecked: false)],
|
497
|
+
type_params: [TypeParam.new(name: :T, upper_bound: nil, variance: :invariant, unchecked: false, default_type: nil)],
|
496
498
|
type: Function.new(
|
497
499
|
params: Function::Params.build(
|
498
500
|
required: [
|
@@ -503,11 +505,10 @@ module Steep
|
|
503
505
|
return_type: AST::Types::Union.build(types: [elem_type, AST::Types::Var.new(name: :T)]),
|
504
506
|
location: nil
|
505
507
|
),
|
506
|
-
block: nil
|
507
|
-
method_decls: Set[]
|
508
|
+
block: nil
|
508
509
|
),
|
509
510
|
MethodType.new(
|
510
|
-
type_params: [TypeParam.new(name: :T, upper_bound: nil, variance: :invariant, unchecked: false)],
|
511
|
+
type_params: [TypeParam.new(name: :T, upper_bound: nil, variance: :invariant, unchecked: false, default_type: nil)],
|
511
512
|
type: Function.new(
|
512
513
|
params: Function::Params.build(required: [AST::Types::Literal.new(value: index)]),
|
513
514
|
return_type: AST::Types::Union.build(types: [elem_type, AST::Types::Var.new(name: :T)]),
|
@@ -521,27 +522,29 @@ module Steep
|
|
521
522
|
),
|
522
523
|
optional: false,
|
523
524
|
self_type: nil
|
524
|
-
)
|
525
|
-
method_decls: Set[]
|
525
|
+
)
|
526
526
|
)
|
527
|
-
]
|
528
|
-
} + fetch.
|
527
|
+
].map { Shape::MethodOverload.new(_1, []) }
|
528
|
+
} + fetch.overloads
|
529
529
|
)
|
530
530
|
end
|
531
531
|
|
532
532
|
first_entry = array_shape.methods[:first].yield_self do |first|
|
533
533
|
Shape::Entry.new(
|
534
|
+
method_name: :first,
|
534
535
|
private_method: false,
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
536
|
+
overloads: [
|
537
|
+
Shape::MethodOverload.new(
|
538
|
+
MethodType.new(
|
539
|
+
type_params: [],
|
540
|
+
type: Function.new(
|
541
|
+
params: Function::Params.empty,
|
542
|
+
return_type: tuple.types[0] || AST::Builtin.nil_type,
|
543
|
+
location: nil
|
544
|
+
),
|
545
|
+
block: nil
|
542
546
|
),
|
543
|
-
|
544
|
-
method_decls: Set[]
|
547
|
+
[]
|
545
548
|
)
|
546
549
|
]
|
547
550
|
)
|
@@ -549,17 +552,20 @@ module Steep
|
|
549
552
|
|
550
553
|
last_entry = array_shape.methods[:last].yield_self do |last|
|
551
554
|
Shape::Entry.new(
|
555
|
+
method_name: :last,
|
552
556
|
private_method: false,
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
557
|
+
overloads: [
|
558
|
+
Shape::MethodOverload.new(
|
559
|
+
MethodType.new(
|
560
|
+
type_params: [],
|
561
|
+
type: Function.new(
|
562
|
+
params: Function::Params.empty,
|
563
|
+
return_type: tuple.types.last || AST::Builtin.nil_type,
|
564
|
+
location: nil
|
565
|
+
),
|
566
|
+
block: nil
|
560
567
|
),
|
561
|
-
|
562
|
-
method_decls: Set[]
|
568
|
+
[]
|
563
569
|
)
|
564
570
|
]
|
565
571
|
)
|
@@ -576,10 +582,9 @@ module Steep
|
|
576
582
|
|
577
583
|
def record_shape(record)
|
578
584
|
all_key_type = AST::Types::Union.build(
|
579
|
-
types: record.elements.each_key.map {|value| AST::Types::Literal.new(value: value
|
580
|
-
location: nil
|
585
|
+
types: record.elements.each_key.map {|value| AST::Types::Literal.new(value: value) }
|
581
586
|
)
|
582
|
-
all_value_type = AST::Types::Union.build(types: record.elements.values
|
587
|
+
all_value_type = AST::Types::Union.build(types: record.elements.values)
|
583
588
|
hash_type = AST::Builtin::Hash.instance_type(all_key_type, all_value_type)
|
584
589
|
|
585
590
|
hash_shape = yield(hash_type) or raise
|
@@ -589,21 +594,28 @@ module Steep
|
|
589
594
|
shape.methods[:[]] = hash_shape.methods[:[]].yield_self do |aref|
|
590
595
|
aref or raise
|
591
596
|
Shape::Entry.new(
|
597
|
+
method_name: :[],
|
592
598
|
private_method: false,
|
593
|
-
|
594
|
-
key_type = AST::Types::Literal.new(value: key_value
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
599
|
+
overloads: record.elements.map do |key_value, value_type|
|
600
|
+
key_type = AST::Types::Literal.new(value: key_value)
|
601
|
+
|
602
|
+
if record.optional?(key_value)
|
603
|
+
value_type = AST::Builtin.optional(value_type)
|
604
|
+
end
|
605
|
+
|
606
|
+
Shape::MethodOverload.new(
|
607
|
+
MethodType.new(
|
608
|
+
type_params: [],
|
609
|
+
type: Function.new(
|
610
|
+
params: Function::Params.build(required: [key_type]),
|
611
|
+
return_type: value_type,
|
612
|
+
location: nil
|
613
|
+
),
|
614
|
+
block: nil
|
602
615
|
),
|
603
|
-
|
604
|
-
method_decls: Set[]
|
616
|
+
[]
|
605
617
|
)
|
606
|
-
end + aref.
|
618
|
+
end + aref.overloads
|
607
619
|
)
|
608
620
|
end
|
609
621
|
|
@@ -611,19 +623,22 @@ module Steep
|
|
611
623
|
update or raise
|
612
624
|
|
613
625
|
Shape::Entry.new(
|
626
|
+
method_name: :[]=,
|
614
627
|
private_method: false,
|
615
|
-
|
616
|
-
key_type = AST::Types::Literal.new(value: key_value
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
628
|
+
overloads: record.elements.map do |key_value, value_type|
|
629
|
+
key_type = AST::Types::Literal.new(value: key_value)
|
630
|
+
Shape::MethodOverload.new(
|
631
|
+
MethodType.new(
|
632
|
+
type_params: [],
|
633
|
+
type: Function.new(
|
634
|
+
params: Function::Params.build(required: [key_type, value_type]),
|
635
|
+
return_type: value_type,
|
636
|
+
location: nil),
|
637
|
+
block: nil
|
638
|
+
),
|
639
|
+
[]
|
625
640
|
)
|
626
|
-
end + update.
|
641
|
+
end + update.overloads
|
627
642
|
)
|
628
643
|
end
|
629
644
|
|
@@ -631,9 +646,10 @@ module Steep
|
|
631
646
|
update or raise
|
632
647
|
|
633
648
|
Shape::Entry.new(
|
649
|
+
method_name: :fetch,
|
634
650
|
private_method: false,
|
635
|
-
|
636
|
-
key_type = AST::Types::Literal.new(value: key_value
|
651
|
+
overloads: record.elements.flat_map {|key_value, value_type|
|
652
|
+
key_type = AST::Types::Literal.new(value: key_value)
|
637
653
|
|
638
654
|
[
|
639
655
|
MethodType.new(
|
@@ -643,21 +659,19 @@ module Steep
|
|
643
659
|
return_type: value_type,
|
644
660
|
location: nil
|
645
661
|
),
|
646
|
-
block: nil
|
647
|
-
method_decls: Set[]
|
662
|
+
block: nil
|
648
663
|
),
|
649
664
|
MethodType.new(
|
650
|
-
type_params: [TypeParam.new(name: :T, upper_bound: nil, variance: :invariant, unchecked: false)],
|
665
|
+
type_params: [TypeParam.new(name: :T, upper_bound: nil, variance: :invariant, unchecked: false, default_type: nil)],
|
651
666
|
type: Function.new(
|
652
667
|
params: Function::Params.build(required: [key_type, AST::Types::Var.new(name: :T)]),
|
653
668
|
return_type: AST::Types::Union.build(types: [value_type, AST::Types::Var.new(name: :T)]),
|
654
669
|
location: nil
|
655
670
|
),
|
656
|
-
block: nil
|
657
|
-
method_decls: Set[]
|
671
|
+
block: nil
|
658
672
|
),
|
659
673
|
MethodType.new(
|
660
|
-
type_params: [TypeParam.new(name: :T, upper_bound: nil, variance: :invariant, unchecked: false)],
|
674
|
+
type_params: [TypeParam.new(name: :T, upper_bound: nil, variance: :invariant, unchecked: false, default_type: nil)],
|
661
675
|
type: Function.new(
|
662
676
|
params: Function::Params.build(required: [key_type]),
|
663
677
|
return_type: AST::Types::Union.build(types: [value_type, AST::Types::Var.new(name: :T)]),
|
@@ -671,11 +685,10 @@ module Steep
|
|
671
685
|
),
|
672
686
|
optional: false,
|
673
687
|
self_type: nil
|
674
|
-
)
|
675
|
-
method_decls: Set[]
|
688
|
+
)
|
676
689
|
)
|
677
|
-
]
|
678
|
-
} + update.
|
690
|
+
].map { Shape::MethodOverload.new(_1, []) }
|
691
|
+
} + update.overloads
|
679
692
|
)
|
680
693
|
end
|
681
694
|
|
@@ -686,9 +699,20 @@ module Steep
|
|
686
699
|
shape = Shape.new(type: proc, private: true)
|
687
700
|
shape.methods.merge!(proc_shape.methods)
|
688
701
|
|
689
|
-
|
702
|
+
overload = Shape::MethodOverload.new(
|
703
|
+
MethodType.new(type_params: [], type: proc.type, block: proc.block),
|
704
|
+
[]
|
705
|
+
)
|
706
|
+
|
707
|
+
shape.methods[:[]] = Shape::Entry.new(
|
708
|
+
method_name: :[],
|
709
|
+
private_method: false,
|
710
|
+
overloads: [overload]
|
711
|
+
)
|
712
|
+
shape.methods[:call] = Shape::Entry.new(
|
713
|
+
method_name: :call,
|
690
714
|
private_method: false,
|
691
|
-
|
715
|
+
overloads: [overload]
|
692
716
|
)
|
693
717
|
|
694
718
|
shape
|
@@ -707,7 +731,7 @@ module Steep
|
|
707
731
|
if member.instance?
|
708
732
|
return method_type.with(
|
709
733
|
type: method_type.type.with(
|
710
|
-
return_type: AST::Types::Logic::ReceiverIsArg.
|
734
|
+
return_type: AST::Types::Logic::ReceiverIsArg.instance()
|
711
735
|
)
|
712
736
|
)
|
713
737
|
end
|
@@ -721,7 +745,7 @@ module Steep
|
|
721
745
|
if member.instance?
|
722
746
|
return method_type.with(
|
723
747
|
type: method_type.type.with(
|
724
|
-
return_type: AST::Types::Logic::ReceiverIsNil.
|
748
|
+
return_type: AST::Types::Logic::ReceiverIsNil.instance()
|
725
749
|
)
|
726
750
|
)
|
727
751
|
end
|
@@ -735,7 +759,7 @@ module Steep
|
|
735
759
|
AST::Builtin::NilClass.module_name
|
736
760
|
return method_type.with(
|
737
761
|
type: method_type.type.with(
|
738
|
-
return_type: AST::Types::Logic::Not.
|
762
|
+
return_type: AST::Types::Logic::Not.instance()
|
739
763
|
)
|
740
764
|
)
|
741
765
|
end
|
@@ -745,7 +769,7 @@ module Steep
|
|
745
769
|
when RBS::BuiltinNames::Module.name
|
746
770
|
return method_type.with(
|
747
771
|
type: method_type.type.with(
|
748
|
-
return_type: AST::Types::Logic::ArgIsReceiver.
|
772
|
+
return_type: AST::Types::Logic::ArgIsReceiver.instance()
|
749
773
|
)
|
750
774
|
)
|
751
775
|
when RBS::BuiltinNames::Object.name,
|
@@ -759,7 +783,7 @@ module Steep
|
|
759
783
|
# Value based type-case works on literal types which is available for String, Integer, Symbol, TrueClass, FalseClass, and NilClass
|
760
784
|
return method_type.with(
|
761
785
|
type: method_type.type.with(
|
762
|
-
return_type: AST::Types::Logic::ArgEqualsReceiver.
|
786
|
+
return_type: AST::Types::Logic::ArgEqualsReceiver.instance()
|
763
787
|
)
|
764
788
|
)
|
765
789
|
end
|
@@ -768,7 +792,7 @@ module Steep
|
|
768
792
|
when RBS::BuiltinNames::Module.name
|
769
793
|
return method_type.with(
|
770
794
|
type: method_type.type.with(
|
771
|
-
return_type: AST::Types::Logic::ArgIsAncestor.
|
795
|
+
return_type: AST::Types::Logic::ArgIsAncestor.instance()
|
772
796
|
)
|
773
797
|
)
|
774
798
|
end
|
@@ -4,13 +4,11 @@ module Steep
|
|
4
4
|
attr_reader :type_params
|
5
5
|
attr_reader :type
|
6
6
|
attr_reader :block
|
7
|
-
attr_reader :method_decls
|
8
7
|
|
9
|
-
def initialize(type_params:, type:, block
|
8
|
+
def initialize(type_params:, type:, block:)
|
10
9
|
@type_params = type_params
|
11
10
|
@type = type
|
12
11
|
@block = block
|
13
|
-
@method_decls = method_decls
|
14
12
|
end
|
15
13
|
|
16
14
|
def ==(other)
|
@@ -52,7 +50,7 @@ module Steep
|
|
52
50
|
if ty == type && bl == block
|
53
51
|
self
|
54
52
|
else
|
55
|
-
self.class.new(type_params: type_params, type: ty, block: bl
|
53
|
+
self.class.new(type_params: type_params, type: ty, block: bl)
|
56
54
|
end
|
57
55
|
end
|
58
56
|
|
@@ -72,15 +70,13 @@ module Steep
|
|
72
70
|
def instantiate(s)
|
73
71
|
self.class.new(type_params: [],
|
74
72
|
type: type.subst(s),
|
75
|
-
block: block&.subst(s)
|
76
|
-
method_decls: method_decls)
|
73
|
+
block: block&.subst(s))
|
77
74
|
end
|
78
75
|
|
79
|
-
def with(type_params: self.type_params, type: self.type, block: self.block
|
76
|
+
def with(type_params: self.type_params, type: self.type, block: self.block)
|
80
77
|
self.class.new(type_params: type_params,
|
81
78
|
type: type,
|
82
|
-
block: block
|
83
|
-
method_decls: method_decls)
|
79
|
+
block: block)
|
84
80
|
end
|
85
81
|
|
86
82
|
def to_s
|
@@ -95,8 +91,7 @@ module Steep
|
|
95
91
|
def map_type(&block)
|
96
92
|
self.class.new(type_params: type_params,
|
97
93
|
type: type.map_type(&block),
|
98
|
-
block: self.block&.yield_self {|blk| blk.map_type(&block) }
|
99
|
-
method_decls: method_decls)
|
94
|
+
block: self.block&.yield_self {|blk| blk.map_type(&block) })
|
100
95
|
end
|
101
96
|
|
102
97
|
# Returns a new method type which can be used for the method implementation type of both `self` and `other`.
|
@@ -125,8 +120,7 @@ module Steep
|
|
125
120
|
),
|
126
121
|
location: nil
|
127
122
|
),
|
128
|
-
block: block
|
129
|
-
method_decls: method_decls + other.method_decls
|
123
|
+
block: block
|
130
124
|
)
|
131
125
|
end
|
132
126
|
|
@@ -245,7 +239,7 @@ module Steep
|
|
245
239
|
when (self_self = b.self_type) && (other_self = ob.self_type)
|
246
240
|
AST::Types::Union.build(types: [self_self, other_self])
|
247
241
|
when b.self_type || ob.self_type
|
248
|
-
AST::Types::Bot.
|
242
|
+
AST::Types::Bot.instance
|
249
243
|
else
|
250
244
|
nil
|
251
245
|
end
|
@@ -280,8 +274,7 @@ module Steep
|
|
280
274
|
MethodType.new(
|
281
275
|
type_params: [],
|
282
276
|
type: Function.new(params: params, return_type: return_type, location: nil),
|
283
|
-
block: block
|
284
|
-
method_decls: method_decls + other.method_decls
|
277
|
+
block: block
|
285
278
|
)
|
286
279
|
end
|
287
280
|
|
@@ -293,7 +286,7 @@ module Steep
|
|
293
286
|
else
|
294
287
|
params = self.type.params || other.type.params
|
295
288
|
end
|
296
|
-
|
289
|
+
|
297
290
|
block =
|
298
291
|
case
|
299
292
|
when (b = self.block) && (ob = other.block)
|
@@ -302,7 +295,7 @@ module Steep
|
|
302
295
|
when (self_self = b.self_type) && (other_self = ob.self_type)
|
303
296
|
AST::Types::Intersection.build(types: [self_self, other_self])
|
304
297
|
when b.self_type || ob.self_type
|
305
|
-
AST::Types::Top.
|
298
|
+
AST::Types::Top.instance
|
306
299
|
else
|
307
300
|
nil
|
308
301
|
end
|
@@ -324,8 +317,7 @@ module Steep
|
|
324
317
|
MethodType.new(
|
325
318
|
type_params: [],
|
326
319
|
type: Function.new(params: params, return_type: return_type, location: nil),
|
327
|
-
block: block
|
328
|
-
method_decls: method_decls + other.method_decls
|
320
|
+
block: block
|
329
321
|
)
|
330
322
|
end
|
331
323
|
end
|