steep 1.8.0.dev.1 → 1.8.0.pre.1
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 +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
@@ -154,7 +154,7 @@ module Steep
|
|
154
154
|
definition_method_type = if definition
|
155
155
|
definition.methods[method_name]&.yield_self do |method|
|
156
156
|
method.method_types
|
157
|
-
.map {|method_type| checker.factory.method_type(method_type
|
157
|
+
.map {|method_type| checker.factory.method_type(method_type) }
|
158
158
|
.select {|method_type| method_type.is_a?(Interface::MethodType) }
|
159
159
|
.inject {|t1, t2| t1 + t2}
|
160
160
|
end
|
@@ -195,11 +195,11 @@ module Steep
|
|
195
195
|
end
|
196
196
|
|
197
197
|
method_params =
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
198
|
+
if method_type
|
199
|
+
TypeInference::MethodParams.build(node: node, method_type: method_type)
|
200
|
+
else
|
201
|
+
TypeInference::MethodParams.empty(node: node)
|
202
|
+
end
|
203
203
|
|
204
204
|
method_context = TypeInference::Context::MethodContext.new(
|
205
205
|
name: method_name,
|
@@ -405,9 +405,10 @@ module Steep
|
|
405
405
|
type_params = definition.type_params_decl.map do |param|
|
406
406
|
Interface::TypeParam.new(
|
407
407
|
name: param.name,
|
408
|
-
upper_bound: checker.factory.type_opt(param.
|
408
|
+
upper_bound: checker.factory.type_opt(param.upper_bound_type),
|
409
409
|
variance: param.variance,
|
410
|
-
unchecked: param.unchecked
|
410
|
+
unchecked: param.unchecked?,
|
411
|
+
default_type: checker.factory.type_opt(param.default_type)
|
411
412
|
)
|
412
413
|
end
|
413
414
|
variable_context = TypeInference::Context::TypeVariableContext.new(type_params)
|
@@ -494,10 +495,11 @@ module Steep
|
|
494
495
|
type_params = definition.type_params_decl.map do |type_param|
|
495
496
|
Interface::TypeParam.new(
|
496
497
|
name: type_param.name,
|
497
|
-
upper_bound: type_param.
|
498
|
+
upper_bound: type_param.upper_bound_type&.yield_self {|t| checker.factory.type(t) },
|
498
499
|
variance: type_param.variance,
|
499
500
|
unchecked: type_param.unchecked?,
|
500
|
-
location: type_param.location
|
501
|
+
location: type_param.location,
|
502
|
+
default_type: checker.factory.type_opt(type_param.default_type)
|
501
503
|
)
|
502
504
|
end
|
503
505
|
variable_context = TypeInference::Context::TypeVariableContext.new(type_params)
|
@@ -705,7 +707,7 @@ module Steep
|
|
705
707
|
if new_pair.constr.context != pair.constr.context
|
706
708
|
# update context
|
707
709
|
range = node.loc.expression.end_pos..end_pos
|
708
|
-
typing.
|
710
|
+
typing.cursor_context.set(range, new_pair.constr.context)
|
709
711
|
end
|
710
712
|
end
|
711
713
|
end
|
@@ -878,16 +880,11 @@ module Steep
|
|
878
880
|
if self_type && method_context!.method
|
879
881
|
if super_def = method_context!.super_method
|
880
882
|
super_method = Interface::Shape::Entry.new(
|
883
|
+
method_name: method_context!.name,
|
881
884
|
private_method: true,
|
882
|
-
|
883
|
-
|
884
|
-
|
885
|
-
type_name: super_def.implemented_in || super_def.defined_in || raise,
|
886
|
-
method_name: method_context!.name || raise("method context must have a name")
|
887
|
-
),
|
888
|
-
method_def: type_def
|
889
|
-
)
|
890
|
-
checker.factory.method_type(type_def.type, method_decls: Set[decl])
|
885
|
+
overloads: super_def.defs.map {|type_def|
|
886
|
+
type = checker.factory.method_type(type_def.type)
|
887
|
+
Interface::Shape::MethodOverload.new(type, [type_def])
|
891
888
|
}
|
892
889
|
)
|
893
890
|
|
@@ -949,8 +946,8 @@ module Steep
|
|
949
946
|
) do |new|
|
950
947
|
# @type var new: TypeConstruction
|
951
948
|
|
952
|
-
new.typing.
|
953
|
-
new.typing.
|
949
|
+
new.typing.cursor_context.set_node_context(node, new.context)
|
950
|
+
new.typing.cursor_context.set_body_context(node, new.context)
|
954
951
|
|
955
952
|
new.method_context!.tap do |method_context|
|
956
953
|
if method_context.method
|
@@ -1028,7 +1025,7 @@ module Steep
|
|
1028
1025
|
# Skip end-less def
|
1029
1026
|
begin_pos = body_node.loc.expression.end_pos
|
1030
1027
|
end_pos = node.loc.end.begin_pos
|
1031
|
-
typing.
|
1028
|
+
typing.cursor_context.set(begin_pos..end_pos, body_pair.context)
|
1032
1029
|
end
|
1033
1030
|
end
|
1034
1031
|
|
@@ -1061,8 +1058,8 @@ module Steep
|
|
1061
1058
|
self_type: self_type,
|
1062
1059
|
definition: definition
|
1063
1060
|
)
|
1064
|
-
new.typing.
|
1065
|
-
new.typing.
|
1061
|
+
new.typing.cursor_context.set_node_context(node, new.context)
|
1062
|
+
new.typing.cursor_context.set_body_context(node, new.context)
|
1066
1063
|
|
1067
1064
|
new.method_context!.tap do |method_context|
|
1068
1065
|
if method_context.method
|
@@ -1375,6 +1372,12 @@ module Steep
|
|
1375
1372
|
when :float
|
1376
1373
|
add_typing(node, type: AST::Builtin::Float.instance_type)
|
1377
1374
|
|
1375
|
+
when :rational
|
1376
|
+
add_typing(node, type: AST::Types::Name::Instance.new(name: TypeName("::Rational"), args: []))
|
1377
|
+
|
1378
|
+
when :complex
|
1379
|
+
add_typing(node, type: AST::Types::Name::Instance.new(name: TypeName("::Complex"), args: []))
|
1380
|
+
|
1378
1381
|
when :nil
|
1379
1382
|
add_typing(node, type: AST::Builtin.nil_type)
|
1380
1383
|
|
@@ -1420,7 +1423,7 @@ module Steep
|
|
1420
1423
|
when condition
|
1421
1424
|
add_typing(node, type: ty)
|
1422
1425
|
else
|
1423
|
-
add_typing(node, type: AST::Types::Boolean.
|
1426
|
+
add_typing(node, type: AST::Types::Boolean.instance)
|
1424
1427
|
end
|
1425
1428
|
|
1426
1429
|
when :hash, :kwargs
|
@@ -1499,13 +1502,13 @@ module Steep
|
|
1499
1502
|
_, constructor = constructor.fallback_to_any(name_node)
|
1500
1503
|
end
|
1501
1504
|
|
1502
|
-
constructor.typing.
|
1503
|
-
constructor.typing.
|
1505
|
+
constructor.typing.cursor_context.set_node_context(node, constructor.context)
|
1506
|
+
constructor.typing.cursor_context.set_body_context(node, constructor.context)
|
1504
1507
|
|
1505
1508
|
constructor.synthesize(node.children[2]) if node.children[2]
|
1506
1509
|
|
1507
1510
|
if constructor.module_context&.implement_name && !namespace_module?(node)
|
1508
|
-
constructor.validate_method_definitions(node, constructor.module_context.implement_name)
|
1511
|
+
constructor.validate_method_definitions(node, constructor.module_context.implement_name || raise)
|
1509
1512
|
end
|
1510
1513
|
end
|
1511
1514
|
|
@@ -1538,13 +1541,13 @@ module Steep
|
|
1538
1541
|
_, constructor = constructor.fallback_to_any(name_node)
|
1539
1542
|
end
|
1540
1543
|
|
1541
|
-
constructor.typing.
|
1542
|
-
constructor.typing.
|
1544
|
+
constructor.typing.cursor_context.set_node_context(node, constructor.context)
|
1545
|
+
constructor.typing.cursor_context.set_body_context(node, constructor.context)
|
1543
1546
|
|
1544
1547
|
constructor.synthesize(node.children[1]) if node.children[1]
|
1545
1548
|
|
1546
1549
|
if constructor.module_context&.implement_name && !namespace_module?(node)
|
1547
|
-
constructor.validate_method_definitions(node, constructor.module_context.implement_name)
|
1550
|
+
constructor.validate_method_definitions(node, constructor.module_context.implement_name || raise)
|
1548
1551
|
end
|
1549
1552
|
end
|
1550
1553
|
|
@@ -1566,8 +1569,8 @@ module Steep
|
|
1566
1569
|
return constr.add_typing(node, type: AST::Builtin.nil_type)
|
1567
1570
|
end
|
1568
1571
|
|
1569
|
-
constructor.typing.
|
1570
|
-
constructor.typing.
|
1572
|
+
constructor.typing.cursor_context.set_node_context(node, constructor.context)
|
1573
|
+
constructor.typing.cursor_context.set_body_context(node, constructor.context)
|
1571
1574
|
|
1572
1575
|
constructor.synthesize(node.children[1]) if node.children[1]
|
1573
1576
|
|
@@ -1582,10 +1585,10 @@ module Steep
|
|
1582
1585
|
end
|
1583
1586
|
|
1584
1587
|
when :self
|
1585
|
-
add_typing node, type: AST::Types::Self.
|
1588
|
+
add_typing node, type: AST::Types::Self.instance
|
1586
1589
|
|
1587
1590
|
when :cbase
|
1588
|
-
add_typing node, type: AST::Types::Void.
|
1591
|
+
add_typing node, type: AST::Types::Void.instance
|
1589
1592
|
|
1590
1593
|
when :const
|
1591
1594
|
yield_self do
|
@@ -1677,7 +1680,7 @@ module Steep
|
|
1677
1680
|
if method_context && method_context.method
|
1678
1681
|
if method_context.super_method
|
1679
1682
|
types = method_context.super_method.method_types.map {|method_type|
|
1680
|
-
checker.factory.method_type(method_type
|
1683
|
+
checker.factory.method_type(method_type).type.return_type
|
1681
1684
|
}
|
1682
1685
|
add_typing(node, type: union_type(*types))
|
1683
1686
|
else
|
@@ -1705,13 +1708,11 @@ module Steep
|
|
1705
1708
|
add_typing node, type: AST::Builtin::Array.instance_type(AST::Builtin.any_type)
|
1706
1709
|
end
|
1707
1710
|
else
|
1708
|
-
node_range = node.loc.expression.yield_self {|l| l.begin_pos..l.end_pos }
|
1709
|
-
|
1710
1711
|
if hint
|
1711
1712
|
tuples = select_flatten_types(hint) {|type| type.is_a?(AST::Types::Tuple) } #: Array[AST::Types::Tuple]
|
1712
1713
|
unless tuples.empty?
|
1713
1714
|
tuples.each do |tuple|
|
1714
|
-
typing.new_child(
|
1715
|
+
typing.new_child() do |child_typing|
|
1715
1716
|
if pair = with_new_typing(child_typing).try_tuple_type(node, tuple)
|
1716
1717
|
return pair.with(constr: pair.constr.save_typing)
|
1717
1718
|
end
|
@@ -1724,7 +1725,7 @@ module Steep
|
|
1724
1725
|
arrays = select_flatten_types(hint) {|type| AST::Builtin::Array.instance_type?(type) } #: Array[AST::Types::Name::Instance]
|
1725
1726
|
unless arrays.empty?
|
1726
1727
|
arrays.each do |array|
|
1727
|
-
typing.new_child(
|
1728
|
+
typing.new_child() do |child_typing|
|
1728
1729
|
pair = with_new_typing(child_typing).try_array_type(node, array)
|
1729
1730
|
if pair.constr.check_relation(sub_type: pair.type, super_type: hint).success?
|
1730
1731
|
return pair.with(constr: pair.constr.save_typing)
|
@@ -1754,7 +1755,7 @@ module Steep
|
|
1754
1755
|
right_type, constr, right_context =
|
1755
1756
|
constr
|
1756
1757
|
.update_type_env { left_truthy.env }
|
1757
|
-
.tap {|constr| typing.
|
1758
|
+
.tap {|constr| typing.cursor_context.set_node_context(right_node, constr.context) }
|
1758
1759
|
.for_branch(right_node)
|
1759
1760
|
.synthesize(right_node, hint: hint, condition: true).to_ary
|
1760
1761
|
|
@@ -1777,8 +1778,8 @@ module Steep
|
|
1777
1778
|
type = union_type(left_falsy.type, right_type)
|
1778
1779
|
|
1779
1780
|
unless type.is_a?(AST::Types::Any)
|
1780
|
-
if check_relation(sub_type: type, super_type: AST::Types::Boolean.
|
1781
|
-
type = AST::Types::Boolean.
|
1781
|
+
if check_relation(sub_type: type, super_type: AST::Types::Boolean.instance).success?
|
1782
|
+
type = AST::Types::Boolean.instance
|
1782
1783
|
end
|
1783
1784
|
end
|
1784
1785
|
end
|
@@ -1813,7 +1814,7 @@ module Steep
|
|
1813
1814
|
right_type, constr, right_context =
|
1814
1815
|
constr
|
1815
1816
|
.update_type_env { left_falsy.env }
|
1816
|
-
.tap {|constr| typing.
|
1817
|
+
.tap {|constr| typing.cursor_context.set_node_context(right_node, constr.context) }
|
1817
1818
|
.for_branch(right_node)
|
1818
1819
|
.synthesize(right_node, hint: left_truthy.type, condition: true).to_ary
|
1819
1820
|
|
@@ -1835,8 +1836,8 @@ module Steep
|
|
1835
1836
|
type = union_type(left_truthy.type, right_type)
|
1836
1837
|
|
1837
1838
|
unless type.is_a?(AST::Types::Any)
|
1838
|
-
if check_relation(sub_type: type, super_type: AST::Types::Boolean.
|
1839
|
-
type = AST::Types::Boolean.
|
1839
|
+
if check_relation(sub_type: type, super_type: AST::Types::Boolean.instance).success?
|
1840
|
+
type = AST::Types::Boolean.instance
|
1840
1841
|
end
|
1841
1842
|
end
|
1842
1843
|
end
|
@@ -1865,7 +1866,7 @@ module Steep
|
|
1865
1866
|
constr
|
1866
1867
|
.update_type_env { truthy.env }
|
1867
1868
|
.for_branch(true_clause)
|
1868
|
-
.tap {|constr| typing.
|
1869
|
+
.tap {|constr| typing.cursor_context.set_node_context(true_clause, constr.context) }
|
1869
1870
|
.synthesize(true_clause, hint: hint)
|
1870
1871
|
end
|
1871
1872
|
|
@@ -1874,7 +1875,7 @@ module Steep
|
|
1874
1875
|
constr
|
1875
1876
|
.update_type_env { falsy.env }
|
1876
1877
|
.for_branch(false_clause)
|
1877
|
-
.tap {|constr| typing.
|
1878
|
+
.tap {|constr| typing.cursor_context.set_node_context(false_clause, constr.context) }
|
1878
1879
|
.synthesize(false_clause, hint: hint)
|
1879
1880
|
end
|
1880
1881
|
|
@@ -2004,7 +2005,7 @@ module Steep
|
|
2004
2005
|
when_clause_constr
|
2005
2006
|
.for_branch(body)
|
2006
2007
|
.update_type_env {|env| env.join(*body_envs) }
|
2007
|
-
.tap {|constr| typing.
|
2008
|
+
.tap {|constr| typing.cursor_context.set_node_context(body, constr.context) }
|
2008
2009
|
.synthesize(body, hint: hint)
|
2009
2010
|
else
|
2010
2011
|
Pair.new(type: AST::Builtin.nil_type, constr: when_clause_constr)
|
@@ -2106,7 +2107,7 @@ module Steep
|
|
2106
2107
|
end
|
2107
2108
|
|
2108
2109
|
if body
|
2109
|
-
resbody_construction.typing.
|
2110
|
+
resbody_construction.typing.cursor_context.set_node_context(body, resbody_construction.context)
|
2110
2111
|
resbody_construction.synthesize(body, hint: hint)
|
2111
2112
|
else
|
2112
2113
|
Pair.new(constr: body_constr, type: AST::Builtin.nil_type)
|
@@ -2114,7 +2115,7 @@ module Steep
|
|
2114
2115
|
end
|
2115
2116
|
|
2116
2117
|
resbody_pairs.select! do |pair|
|
2117
|
-
no_subtyping?(sub_type: pair.type, super_type: AST::Types::Bot.
|
2118
|
+
no_subtyping?(sub_type: pair.type, super_type: AST::Types::Bot.instance)
|
2118
2119
|
end
|
2119
2120
|
|
2120
2121
|
resbody_types = resbody_pairs.map(&:type)
|
@@ -2207,7 +2208,7 @@ module Steep
|
|
2207
2208
|
type_env.merge(local_variable_types: pins)
|
2208
2209
|
end
|
2209
2210
|
|
2210
|
-
typing.
|
2211
|
+
typing.cursor_context.set_body_context(node, body_constr.context)
|
2211
2212
|
_, _, body_context = body_constr.synthesize(body).to_ary
|
2212
2213
|
|
2213
2214
|
constr = constr.update_type_env do |env|
|
@@ -2261,7 +2262,7 @@ module Steep
|
|
2261
2262
|
constr
|
2262
2263
|
.update_type_env { body_env }
|
2263
2264
|
.for_branch(body, break_context: TypeInference::Context::BreakContext.new(break_type: hint || AST::Builtin.nil_type, next_type: nil))
|
2264
|
-
.tap {|constr| typing.
|
2265
|
+
.tap {|constr| typing.cursor_context.set_node_context(body, constr.context) }
|
2265
2266
|
.synthesize(body).to_ary
|
2266
2267
|
|
2267
2268
|
constr = constr.update_type_env {|env| env.join(exit_env, body_constr.context.type_env) }
|
@@ -2284,7 +2285,7 @@ module Steep
|
|
2284
2285
|
.update_type_env {|env| env.merge(local_variable_types: env.pin_local_variables(nil)) }
|
2285
2286
|
.for_branch(body, break_context: TypeInference::Context::BreakContext.new(break_type: hint || AST::Builtin.nil_type, next_type: nil))
|
2286
2287
|
|
2287
|
-
typing.
|
2288
|
+
typing.cursor_context.set_node_context(body, for_loop.context)
|
2288
2289
|
_, body_constr, body_context = for_loop.synthesize(body)
|
2289
2290
|
|
2290
2291
|
constr = cond_constr.update_type_env {|env| env.join(env, body_context.type_env) }
|
@@ -2407,7 +2408,7 @@ module Steep
|
|
2407
2408
|
param_type = hint.type.params.required[0]
|
2408
2409
|
case param_type
|
2409
2410
|
when AST::Types::Any
|
2410
|
-
type = AST::Types::Any.
|
2411
|
+
type = AST::Types::Any.instance
|
2411
2412
|
else
|
2412
2413
|
if method = calculate_interface(param_type, private: true)&.methods&.[](value_node.children[0])
|
2413
2414
|
return_types = method.method_types.filter_map do |method_type|
|
@@ -2450,7 +2451,6 @@ module Steep
|
|
2450
2451
|
if block_type = method_context!.block_type
|
2451
2452
|
type = AST::Types::Proc.new(
|
2452
2453
|
type: block_type.type,
|
2453
|
-
location: nil,
|
2454
2454
|
block: nil,
|
2455
2455
|
self_type: block_type.self_type
|
2456
2456
|
)
|
@@ -3081,7 +3081,7 @@ module Steep
|
|
3081
3081
|
node_type_hint: nil
|
3082
3082
|
)
|
3083
3083
|
|
3084
|
-
block_constr.typing.
|
3084
|
+
block_constr.typing.cursor_context.set_body_context(node, block_constr.context)
|
3085
3085
|
|
3086
3086
|
params.each_single_param do |param|
|
3087
3087
|
_, block_constr = block_constr.synthesize(param.node, hint: param.type)
|
@@ -3289,7 +3289,11 @@ module Steep
|
|
3289
3289
|
method_name: method_name,
|
3290
3290
|
method_types: method.method_types
|
3291
3291
|
)
|
3292
|
-
|
3292
|
+
|
3293
|
+
decls = method.overloads.flat_map do |method_overload|
|
3294
|
+
method_overload.method_decls(method_name)
|
3295
|
+
end.to_set
|
3296
|
+
|
3293
3297
|
call = TypeInference::MethodCall::Error.new(
|
3294
3298
|
node: node,
|
3295
3299
|
context: context.call_context,
|
@@ -3493,8 +3497,9 @@ module Steep
|
|
3493
3497
|
]
|
3494
3498
|
}
|
3495
3499
|
|
3496
|
-
def try_special_method(node, receiver_type:, method_name:,
|
3497
|
-
|
3500
|
+
def try_special_method(node, receiver_type:, method_name:, method_overload:, arguments:, block_params:, block_body:, hint:)
|
3501
|
+
method_type = method_overload.method_type
|
3502
|
+
decls = method_overload.method_decls(method_name).to_set
|
3498
3503
|
|
3499
3504
|
case
|
3500
3505
|
when decl = decls.find {|decl| SPECIAL_METHOD_NAMES[:array_compact].include?(decl.method_name) }
|
@@ -3567,21 +3572,19 @@ module Steep
|
|
3567
3572
|
end
|
3568
3573
|
|
3569
3574
|
def type_method_call(node, method_name:, receiver_type:, method:, arguments:, block_params:, block_body:, tapp:, hint:)
|
3570
|
-
node_range = node.loc.expression.to_range
|
3571
|
-
|
3572
3575
|
# @type var fails: Array[[TypeInference::MethodCall::t, TypeConstruction]]
|
3573
3576
|
fails = []
|
3574
3577
|
|
3575
|
-
method.
|
3576
|
-
Steep.logger.tagged method_type.to_s do
|
3577
|
-
typing.new_child(
|
3578
|
+
method.overloads.each do |overload|
|
3579
|
+
Steep.logger.tagged overload.method_type.to_s do
|
3580
|
+
typing.new_child() do |child_typing|
|
3578
3581
|
constr = self.with_new_typing(child_typing)
|
3579
3582
|
|
3580
3583
|
call, constr = constr.try_special_method(
|
3581
3584
|
node,
|
3582
3585
|
receiver_type: receiver_type,
|
3583
3586
|
method_name: method_name,
|
3584
|
-
|
3587
|
+
method_overload: overload,
|
3585
3588
|
arguments: arguments,
|
3586
3589
|
block_params: block_params,
|
3587
3590
|
block_body: block_body,
|
@@ -3590,7 +3593,7 @@ module Steep
|
|
3590
3593
|
node,
|
3591
3594
|
receiver_type: receiver_type,
|
3592
3595
|
method_name: method_name,
|
3593
|
-
|
3596
|
+
method_overload: overload,
|
3594
3597
|
arguments: arguments,
|
3595
3598
|
block_params: block_params,
|
3596
3599
|
block_body: block_body,
|
@@ -3642,8 +3645,8 @@ module Steep
|
|
3642
3645
|
end
|
3643
3646
|
end
|
3644
3647
|
|
3645
|
-
def with_child_typing(
|
3646
|
-
constr = with_new_typing(typing.new_child(
|
3648
|
+
def with_child_typing()
|
3649
|
+
constr = with_new_typing(typing.new_child())
|
3647
3650
|
|
3648
3651
|
if block_given?
|
3649
3652
|
yield constr
|
@@ -3746,7 +3749,7 @@ module Steep
|
|
3746
3749
|
when TypeInference::SendArgs::PositionalArgs::SplatArg
|
3747
3750
|
arg_type, _ =
|
3748
3751
|
constr
|
3749
|
-
.with_child_typing(
|
3752
|
+
.with_child_typing()
|
3750
3753
|
.try_tuple_type!(arg.node.children[0])
|
3751
3754
|
arg.type = arg_type
|
3752
3755
|
|
@@ -3828,9 +3831,12 @@ module Steep
|
|
3828
3831
|
constr
|
3829
3832
|
end
|
3830
3833
|
|
3831
|
-
def try_method_type(node, receiver_type:, method_name:,
|
3834
|
+
def try_method_type(node, receiver_type:, method_name:, method_overload:, arguments:, block_params:, block_body:, tapp:, hint:)
|
3832
3835
|
constr = self
|
3833
3836
|
|
3837
|
+
method_type = method_overload.method_type
|
3838
|
+
decls = method_overload.method_decls(method_name).to_set
|
3839
|
+
|
3834
3840
|
if tapp && type_args = tapp.types?(module_context.nesting, checker, [])
|
3835
3841
|
type_arity = method_type.type_params.size
|
3836
3842
|
type_param_names = method_type.type_params.map(&:name)
|
@@ -3842,21 +3848,23 @@ module Steep
|
|
3842
3848
|
|
3843
3849
|
type_args.each_with_index do |type, index|
|
3844
3850
|
param = method_type.type_params[index]
|
3845
|
-
|
3846
|
-
|
3851
|
+
|
3852
|
+
if upper_bound = param.upper_bound
|
3853
|
+
if result = no_subtyping?(sub_type: type.value, super_type: upper_bound)
|
3847
3854
|
args_ << AST::Builtin.any_type
|
3848
3855
|
constr.typing.add_error(
|
3849
3856
|
Diagnostic::Ruby::TypeArgumentMismatchError.new(
|
3850
|
-
type_arg: type,
|
3857
|
+
type_arg: type.value,
|
3851
3858
|
type_param: param,
|
3852
|
-
result: result
|
3859
|
+
result: result,
|
3860
|
+
location: type.location
|
3853
3861
|
)
|
3854
3862
|
)
|
3855
3863
|
else
|
3856
|
-
args_ << type
|
3864
|
+
args_ << type.value
|
3857
3865
|
end
|
3858
3866
|
else
|
3859
|
-
args_ << type
|
3867
|
+
args_ << type.value
|
3860
3868
|
end
|
3861
3869
|
end
|
3862
3870
|
|
@@ -3866,8 +3874,9 @@ module Steep
|
|
3866
3874
|
type_args.drop(type_arity).each do |type_arg|
|
3867
3875
|
constr.typing.add_error(
|
3868
3876
|
Diagnostic::Ruby::UnexpectedTypeArgument.new(
|
3869
|
-
type_arg: type_arg,
|
3870
|
-
method_type: method_type
|
3877
|
+
type_arg: type_arg.value,
|
3878
|
+
method_type: method_type,
|
3879
|
+
location: type_arg.location
|
3871
3880
|
)
|
3872
3881
|
)
|
3873
3882
|
end
|
@@ -3877,7 +3886,7 @@ module Steep
|
|
3877
3886
|
constr.typing.add_error(
|
3878
3887
|
Diagnostic::Ruby::InsufficientTypeArgument.new(
|
3879
3888
|
node: tapp.node,
|
3880
|
-
type_args: type_args,
|
3889
|
+
type_args: type_args.map(&:value),
|
3881
3890
|
method_type: method_type
|
3882
3891
|
)
|
3883
3892
|
)
|
@@ -3989,10 +3998,10 @@ module Steep
|
|
3989
3998
|
)
|
3990
3999
|
|
3991
4000
|
block_constr = block_constr.with_new_typing(
|
3992
|
-
block_constr.typing.new_child(
|
4001
|
+
block_constr.typing.new_child()
|
3993
4002
|
)
|
3994
4003
|
|
3995
|
-
block_constr.typing.
|
4004
|
+
block_constr.typing.cursor_context.set_body_context(node, block_constr.context)
|
3996
4005
|
|
3997
4006
|
pairs.each do |param, type|
|
3998
4007
|
case param
|
@@ -4274,7 +4283,7 @@ module Steep
|
|
4274
4283
|
method_name: method_name,
|
4275
4284
|
actual_method_type: method_type,
|
4276
4285
|
return_type: return_type || method_type.type.return_type,
|
4277
|
-
method_decls:
|
4286
|
+
method_decls: decls
|
4278
4287
|
)
|
4279
4288
|
else
|
4280
4289
|
TypeInference::MethodCall::Error.new(
|
@@ -4283,7 +4292,7 @@ module Steep
|
|
4283
4292
|
receiver_type: receiver_type,
|
4284
4293
|
method_name: method_name,
|
4285
4294
|
return_type: return_type || method_type.type.return_type,
|
4286
|
-
method_decls:
|
4295
|
+
method_decls: decls,
|
4287
4296
|
errors: errors
|
4288
4297
|
)
|
4289
4298
|
end
|
@@ -4339,7 +4348,7 @@ module Steep
|
|
4339
4348
|
node_type_hint: nil
|
4340
4349
|
)
|
4341
4350
|
|
4342
|
-
block_constr.typing.
|
4351
|
+
block_constr.typing.cursor_context.set_body_context(node, block_constr.context)
|
4343
4352
|
|
4344
4353
|
block_params.params.each do |param|
|
4345
4354
|
param.each_param do |param|
|
@@ -4517,7 +4526,7 @@ module Steep
|
|
4517
4526
|
body_type, _, context = synthesize(block_body, hint: block_context&.body_type || block_type_hint)
|
4518
4527
|
|
4519
4528
|
range = block_body.loc.expression.end_pos..node.loc.end.begin_pos
|
4520
|
-
typing.
|
4529
|
+
typing.cursor_context.set(range, context)
|
4521
4530
|
|
4522
4531
|
body_type
|
4523
4532
|
else
|
@@ -4542,7 +4551,7 @@ module Steep
|
|
4542
4551
|
types = types.reject {|t| t.is_a?(AST::Types::Bot) }
|
4543
4552
|
|
4544
4553
|
if types.empty?
|
4545
|
-
AST::Types::Bot.
|
4554
|
+
AST::Types::Bot.instance
|
4546
4555
|
else
|
4547
4556
|
types.inject do |type1, type2|
|
4548
4557
|
next type2 if type1.is_a?(AST::Types::Any)
|
@@ -4712,7 +4721,7 @@ module Steep
|
|
4712
4721
|
end
|
4713
4722
|
|
4714
4723
|
def unwrap(type)
|
4715
|
-
checker.factory.unwrap_optional(type) || AST::Types::Bot.
|
4724
|
+
checker.factory.unwrap_optional(type) || AST::Types::Bot.instance
|
4716
4725
|
end
|
4717
4726
|
|
4718
4727
|
def deep_expand_alias(type)
|
@@ -4759,7 +4768,7 @@ module Steep
|
|
4759
4768
|
when AST::Types::Any
|
4760
4769
|
nil
|
4761
4770
|
else
|
4762
|
-
literal_type = AST::Types::Literal.new(value: literal
|
4771
|
+
literal_type = AST::Types::Literal.new(value: literal)
|
4763
4772
|
if check_relation(sub_type: literal_type, super_type: hint).success?
|
4764
4773
|
hint
|
4765
4774
|
end
|
@@ -4782,9 +4791,7 @@ module Steep
|
|
4782
4791
|
def try_tuple_type!(node, hint: nil)
|
4783
4792
|
if node.type == :array
|
4784
4793
|
if hint.nil? || hint.is_a?(AST::Types::Tuple)
|
4785
|
-
|
4786
|
-
|
4787
|
-
typing.new_child(node_range) do |child_typing|
|
4794
|
+
typing.new_child() do |child_typing|
|
4788
4795
|
if pair = with_new_typing(child_typing).try_tuple_type(node, hint)
|
4789
4796
|
return pair.with(constr: pair.constr.save_typing)
|
4790
4797
|
end
|
@@ -4955,7 +4962,7 @@ module Steep
|
|
4955
4962
|
each_child_node(hash_node) do |child|
|
4956
4963
|
if child.type == :pair
|
4957
4964
|
case child.children[0].type
|
4958
|
-
when :sym
|
4965
|
+
when :sym
|
4959
4966
|
key_node = child.children[0] #: Parser::AST::Node
|
4960
4967
|
value_node = child.children[1] #: Parser::AST::Node
|
4961
4968
|
|
@@ -4984,7 +4991,7 @@ module Steep
|
|
4984
4991
|
end
|
4985
4992
|
end
|
4986
4993
|
|
4987
|
-
type = AST::Types::Record.new(elements: elems)
|
4994
|
+
type = AST::Types::Record.new(elements: elems, required_keys: record_type&.required_keys || Set.new(elems.keys))
|
4988
4995
|
constr.add_typing(hash_node, type: type)
|
4989
4996
|
end
|
4990
4997
|
|
@@ -4992,18 +4999,17 @@ module Steep
|
|
4992
4999
|
if hint
|
4993
5000
|
hint = deep_expand_alias(hint)
|
4994
5001
|
end
|
4995
|
-
range = hash_node.loc.expression.yield_self {|l| l.begin_pos..l.end_pos }
|
4996
5002
|
|
4997
5003
|
case hint
|
4998
5004
|
when AST::Types::Record
|
4999
|
-
with_child_typing(
|
5005
|
+
with_child_typing() do |constr|
|
5000
5006
|
pair = constr.type_hash_record(hash_node, hint)
|
5001
5007
|
if pair
|
5002
5008
|
return pair.with(constr: pair.constr.save_typing)
|
5003
5009
|
end
|
5004
5010
|
end
|
5005
5011
|
when AST::Types::Union
|
5006
|
-
pair = pick_one_of(hint.types
|
5012
|
+
pair = pick_one_of(hint.types) do |type, constr|
|
5007
5013
|
constr.type_hash(hash_node, hint: type)
|
5008
5014
|
end
|
5009
5015
|
|
@@ -5069,9 +5075,9 @@ module Steep
|
|
5069
5075
|
constr.add_typing(hash_node, type: hash_type)
|
5070
5076
|
end
|
5071
5077
|
|
5072
|
-
def pick_one_of(types
|
5078
|
+
def pick_one_of(types)
|
5073
5079
|
types.each do |type|
|
5074
|
-
with_child_typing(
|
5080
|
+
with_child_typing() do |constr|
|
5075
5081
|
if (type_, constr = yield(type, constr))
|
5076
5082
|
constr.check_relation(sub_type: type_, super_type: type).then do
|
5077
5083
|
constr = constr.save_typing
|
@@ -172,6 +172,9 @@ module Steep
|
|
172
172
|
end
|
173
173
|
|
174
174
|
def params_type0(hint:)
|
175
|
+
# @type var leadings: Array[AST::Types::t]
|
176
|
+
# @type var optionals: Array[AST::Types::t]
|
177
|
+
|
175
178
|
if hint
|
176
179
|
case
|
177
180
|
when leading_params.size == hint.required.size
|
@@ -220,8 +223,8 @@ module Steep
|
|
220
223
|
end
|
221
224
|
end
|
222
225
|
else
|
223
|
-
leadings = leading_params.map {|param| param.type || AST::Types::Any.
|
224
|
-
optionals = optional_params.map {|param| param.type || AST::Types::Any.
|
226
|
+
leadings = leading_params.map {|param| param.type || AST::Types::Any.instance }
|
227
|
+
optionals = optional_params.map {|param| param.type || AST::Types::Any.instance }
|
225
228
|
|
226
229
|
if rest_param
|
227
230
|
if rest_type = rest_param.type
|
@@ -229,7 +232,7 @@ module Steep
|
|
229
232
|
rest = array.args.first or raise
|
230
233
|
end
|
231
234
|
end
|
232
|
-
rest ||= AST::Types::Any.
|
235
|
+
rest ||= AST::Types::Any.instance
|
233
236
|
end
|
234
237
|
end
|
235
238
|
|
@@ -279,7 +282,7 @@ module Steep
|
|
279
282
|
if ty
|
280
283
|
zip << [param, ty]
|
281
284
|
else
|
282
|
-
zip << [param, AST::Types::Nil.
|
285
|
+
zip << [param, AST::Types::Nil.instance]
|
283
286
|
end
|
284
287
|
end
|
285
288
|
|
@@ -288,7 +291,7 @@ module Steep
|
|
288
291
|
union = AST::Types::Union.build(types: types)
|
289
292
|
zip << [rest_param, AST::Builtin::Array.instance_type(union)]
|
290
293
|
else
|
291
|
-
zip << [rest_param, AST::Types::Nil.
|
294
|
+
zip << [rest_param, AST::Types::Nil.instance]
|
292
295
|
end
|
293
296
|
end
|
294
297
|
end
|