steep 1.8.0.dev.2 → 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/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/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 +4 -4
- 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 +10 -5
- data/lib/steep/server/lsp_formatter.rb +8 -6
- data/lib/steep/server/master.rb +193 -140
- data/lib/steep/server/type_check_worker.rb +18 -19
- data/lib/steep/server/work_done_progress.rb +64 -0
- data/lib/steep/services/completion_provider.rb +24 -22
- data/lib/steep/services/goto_service.rb +3 -2
- data/lib/steep/services/hover_provider/ruby.rb +7 -6
- data/lib/steep/services/signature_help_provider.rb +7 -6
- data/lib/steep/services/signature_service.rb +1 -1
- data/lib/steep/services/type_check_service.rb +3 -3
- data/lib/steep/signature/validator.rb +17 -20
- data/lib/steep/subtyping/check.rb +105 -55
- data/lib/steep/subtyping/constraints.rb +11 -15
- data/lib/steep/type_construction.rb +100 -100
- data/lib/steep/type_inference/block_params.rb +6 -6
- 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 +158 -102
- data/lib/steep/version.rb +1 -1
- data/lib/steep.rb +28 -3
- 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
|
@@ -1426,7 +1423,7 @@ module Steep
|
|
1426
1423
|
when condition
|
1427
1424
|
add_typing(node, type: ty)
|
1428
1425
|
else
|
1429
|
-
add_typing(node, type: AST::Types::Boolean.
|
1426
|
+
add_typing(node, type: AST::Types::Boolean.instance)
|
1430
1427
|
end
|
1431
1428
|
|
1432
1429
|
when :hash, :kwargs
|
@@ -1505,13 +1502,13 @@ module Steep
|
|
1505
1502
|
_, constructor = constructor.fallback_to_any(name_node)
|
1506
1503
|
end
|
1507
1504
|
|
1508
|
-
constructor.typing.
|
1509
|
-
constructor.typing.
|
1505
|
+
constructor.typing.cursor_context.set_node_context(node, constructor.context)
|
1506
|
+
constructor.typing.cursor_context.set_body_context(node, constructor.context)
|
1510
1507
|
|
1511
1508
|
constructor.synthesize(node.children[2]) if node.children[2]
|
1512
1509
|
|
1513
1510
|
if constructor.module_context&.implement_name && !namespace_module?(node)
|
1514
|
-
constructor.validate_method_definitions(node, constructor.module_context.implement_name)
|
1511
|
+
constructor.validate_method_definitions(node, constructor.module_context.implement_name || raise)
|
1515
1512
|
end
|
1516
1513
|
end
|
1517
1514
|
|
@@ -1544,13 +1541,13 @@ module Steep
|
|
1544
1541
|
_, constructor = constructor.fallback_to_any(name_node)
|
1545
1542
|
end
|
1546
1543
|
|
1547
|
-
constructor.typing.
|
1548
|
-
constructor.typing.
|
1544
|
+
constructor.typing.cursor_context.set_node_context(node, constructor.context)
|
1545
|
+
constructor.typing.cursor_context.set_body_context(node, constructor.context)
|
1549
1546
|
|
1550
1547
|
constructor.synthesize(node.children[1]) if node.children[1]
|
1551
1548
|
|
1552
1549
|
if constructor.module_context&.implement_name && !namespace_module?(node)
|
1553
|
-
constructor.validate_method_definitions(node, constructor.module_context.implement_name)
|
1550
|
+
constructor.validate_method_definitions(node, constructor.module_context.implement_name || raise)
|
1554
1551
|
end
|
1555
1552
|
end
|
1556
1553
|
|
@@ -1572,8 +1569,8 @@ module Steep
|
|
1572
1569
|
return constr.add_typing(node, type: AST::Builtin.nil_type)
|
1573
1570
|
end
|
1574
1571
|
|
1575
|
-
constructor.typing.
|
1576
|
-
constructor.typing.
|
1572
|
+
constructor.typing.cursor_context.set_node_context(node, constructor.context)
|
1573
|
+
constructor.typing.cursor_context.set_body_context(node, constructor.context)
|
1577
1574
|
|
1578
1575
|
constructor.synthesize(node.children[1]) if node.children[1]
|
1579
1576
|
|
@@ -1588,10 +1585,10 @@ module Steep
|
|
1588
1585
|
end
|
1589
1586
|
|
1590
1587
|
when :self
|
1591
|
-
add_typing node, type: AST::Types::Self.
|
1588
|
+
add_typing node, type: AST::Types::Self.instance
|
1592
1589
|
|
1593
1590
|
when :cbase
|
1594
|
-
add_typing node, type: AST::Types::Void.
|
1591
|
+
add_typing node, type: AST::Types::Void.instance
|
1595
1592
|
|
1596
1593
|
when :const
|
1597
1594
|
yield_self do
|
@@ -1683,7 +1680,7 @@ module Steep
|
|
1683
1680
|
if method_context && method_context.method
|
1684
1681
|
if method_context.super_method
|
1685
1682
|
types = method_context.super_method.method_types.map {|method_type|
|
1686
|
-
checker.factory.method_type(method_type
|
1683
|
+
checker.factory.method_type(method_type).type.return_type
|
1687
1684
|
}
|
1688
1685
|
add_typing(node, type: union_type(*types))
|
1689
1686
|
else
|
@@ -1711,13 +1708,11 @@ module Steep
|
|
1711
1708
|
add_typing node, type: AST::Builtin::Array.instance_type(AST::Builtin.any_type)
|
1712
1709
|
end
|
1713
1710
|
else
|
1714
|
-
node_range = node.loc.expression.yield_self {|l| l.begin_pos..l.end_pos }
|
1715
|
-
|
1716
1711
|
if hint
|
1717
1712
|
tuples = select_flatten_types(hint) {|type| type.is_a?(AST::Types::Tuple) } #: Array[AST::Types::Tuple]
|
1718
1713
|
unless tuples.empty?
|
1719
1714
|
tuples.each do |tuple|
|
1720
|
-
typing.new_child(
|
1715
|
+
typing.new_child() do |child_typing|
|
1721
1716
|
if pair = with_new_typing(child_typing).try_tuple_type(node, tuple)
|
1722
1717
|
return pair.with(constr: pair.constr.save_typing)
|
1723
1718
|
end
|
@@ -1730,7 +1725,7 @@ module Steep
|
|
1730
1725
|
arrays = select_flatten_types(hint) {|type| AST::Builtin::Array.instance_type?(type) } #: Array[AST::Types::Name::Instance]
|
1731
1726
|
unless arrays.empty?
|
1732
1727
|
arrays.each do |array|
|
1733
|
-
typing.new_child(
|
1728
|
+
typing.new_child() do |child_typing|
|
1734
1729
|
pair = with_new_typing(child_typing).try_array_type(node, array)
|
1735
1730
|
if pair.constr.check_relation(sub_type: pair.type, super_type: hint).success?
|
1736
1731
|
return pair.with(constr: pair.constr.save_typing)
|
@@ -1760,7 +1755,7 @@ module Steep
|
|
1760
1755
|
right_type, constr, right_context =
|
1761
1756
|
constr
|
1762
1757
|
.update_type_env { left_truthy.env }
|
1763
|
-
.tap {|constr| typing.
|
1758
|
+
.tap {|constr| typing.cursor_context.set_node_context(right_node, constr.context) }
|
1764
1759
|
.for_branch(right_node)
|
1765
1760
|
.synthesize(right_node, hint: hint, condition: true).to_ary
|
1766
1761
|
|
@@ -1783,8 +1778,8 @@ module Steep
|
|
1783
1778
|
type = union_type(left_falsy.type, right_type)
|
1784
1779
|
|
1785
1780
|
unless type.is_a?(AST::Types::Any)
|
1786
|
-
if check_relation(sub_type: type, super_type: AST::Types::Boolean.
|
1787
|
-
type = AST::Types::Boolean.
|
1781
|
+
if check_relation(sub_type: type, super_type: AST::Types::Boolean.instance).success?
|
1782
|
+
type = AST::Types::Boolean.instance
|
1788
1783
|
end
|
1789
1784
|
end
|
1790
1785
|
end
|
@@ -1819,7 +1814,7 @@ module Steep
|
|
1819
1814
|
right_type, constr, right_context =
|
1820
1815
|
constr
|
1821
1816
|
.update_type_env { left_falsy.env }
|
1822
|
-
.tap {|constr| typing.
|
1817
|
+
.tap {|constr| typing.cursor_context.set_node_context(right_node, constr.context) }
|
1823
1818
|
.for_branch(right_node)
|
1824
1819
|
.synthesize(right_node, hint: left_truthy.type, condition: true).to_ary
|
1825
1820
|
|
@@ -1841,8 +1836,8 @@ module Steep
|
|
1841
1836
|
type = union_type(left_truthy.type, right_type)
|
1842
1837
|
|
1843
1838
|
unless type.is_a?(AST::Types::Any)
|
1844
|
-
if check_relation(sub_type: type, super_type: AST::Types::Boolean.
|
1845
|
-
type = AST::Types::Boolean.
|
1839
|
+
if check_relation(sub_type: type, super_type: AST::Types::Boolean.instance).success?
|
1840
|
+
type = AST::Types::Boolean.instance
|
1846
1841
|
end
|
1847
1842
|
end
|
1848
1843
|
end
|
@@ -1871,7 +1866,7 @@ module Steep
|
|
1871
1866
|
constr
|
1872
1867
|
.update_type_env { truthy.env }
|
1873
1868
|
.for_branch(true_clause)
|
1874
|
-
.tap {|constr| typing.
|
1869
|
+
.tap {|constr| typing.cursor_context.set_node_context(true_clause, constr.context) }
|
1875
1870
|
.synthesize(true_clause, hint: hint)
|
1876
1871
|
end
|
1877
1872
|
|
@@ -1880,7 +1875,7 @@ module Steep
|
|
1880
1875
|
constr
|
1881
1876
|
.update_type_env { falsy.env }
|
1882
1877
|
.for_branch(false_clause)
|
1883
|
-
.tap {|constr| typing.
|
1878
|
+
.tap {|constr| typing.cursor_context.set_node_context(false_clause, constr.context) }
|
1884
1879
|
.synthesize(false_clause, hint: hint)
|
1885
1880
|
end
|
1886
1881
|
|
@@ -2010,7 +2005,7 @@ module Steep
|
|
2010
2005
|
when_clause_constr
|
2011
2006
|
.for_branch(body)
|
2012
2007
|
.update_type_env {|env| env.join(*body_envs) }
|
2013
|
-
.tap {|constr| typing.
|
2008
|
+
.tap {|constr| typing.cursor_context.set_node_context(body, constr.context) }
|
2014
2009
|
.synthesize(body, hint: hint)
|
2015
2010
|
else
|
2016
2011
|
Pair.new(type: AST::Builtin.nil_type, constr: when_clause_constr)
|
@@ -2112,7 +2107,7 @@ module Steep
|
|
2112
2107
|
end
|
2113
2108
|
|
2114
2109
|
if body
|
2115
|
-
resbody_construction.typing.
|
2110
|
+
resbody_construction.typing.cursor_context.set_node_context(body, resbody_construction.context)
|
2116
2111
|
resbody_construction.synthesize(body, hint: hint)
|
2117
2112
|
else
|
2118
2113
|
Pair.new(constr: body_constr, type: AST::Builtin.nil_type)
|
@@ -2120,7 +2115,7 @@ module Steep
|
|
2120
2115
|
end
|
2121
2116
|
|
2122
2117
|
resbody_pairs.select! do |pair|
|
2123
|
-
no_subtyping?(sub_type: pair.type, super_type: AST::Types::Bot.
|
2118
|
+
no_subtyping?(sub_type: pair.type, super_type: AST::Types::Bot.instance)
|
2124
2119
|
end
|
2125
2120
|
|
2126
2121
|
resbody_types = resbody_pairs.map(&:type)
|
@@ -2213,7 +2208,7 @@ module Steep
|
|
2213
2208
|
type_env.merge(local_variable_types: pins)
|
2214
2209
|
end
|
2215
2210
|
|
2216
|
-
typing.
|
2211
|
+
typing.cursor_context.set_body_context(node, body_constr.context)
|
2217
2212
|
_, _, body_context = body_constr.synthesize(body).to_ary
|
2218
2213
|
|
2219
2214
|
constr = constr.update_type_env do |env|
|
@@ -2267,7 +2262,7 @@ module Steep
|
|
2267
2262
|
constr
|
2268
2263
|
.update_type_env { body_env }
|
2269
2264
|
.for_branch(body, break_context: TypeInference::Context::BreakContext.new(break_type: hint || AST::Builtin.nil_type, next_type: nil))
|
2270
|
-
.tap {|constr| typing.
|
2265
|
+
.tap {|constr| typing.cursor_context.set_node_context(body, constr.context) }
|
2271
2266
|
.synthesize(body).to_ary
|
2272
2267
|
|
2273
2268
|
constr = constr.update_type_env {|env| env.join(exit_env, body_constr.context.type_env) }
|
@@ -2290,7 +2285,7 @@ module Steep
|
|
2290
2285
|
.update_type_env {|env| env.merge(local_variable_types: env.pin_local_variables(nil)) }
|
2291
2286
|
.for_branch(body, break_context: TypeInference::Context::BreakContext.new(break_type: hint || AST::Builtin.nil_type, next_type: nil))
|
2292
2287
|
|
2293
|
-
typing.
|
2288
|
+
typing.cursor_context.set_node_context(body, for_loop.context)
|
2294
2289
|
_, body_constr, body_context = for_loop.synthesize(body)
|
2295
2290
|
|
2296
2291
|
constr = cond_constr.update_type_env {|env| env.join(env, body_context.type_env) }
|
@@ -2413,7 +2408,7 @@ module Steep
|
|
2413
2408
|
param_type = hint.type.params.required[0]
|
2414
2409
|
case param_type
|
2415
2410
|
when AST::Types::Any
|
2416
|
-
type = AST::Types::Any.
|
2411
|
+
type = AST::Types::Any.instance
|
2417
2412
|
else
|
2418
2413
|
if method = calculate_interface(param_type, private: true)&.methods&.[](value_node.children[0])
|
2419
2414
|
return_types = method.method_types.filter_map do |method_type|
|
@@ -2456,7 +2451,6 @@ module Steep
|
|
2456
2451
|
if block_type = method_context!.block_type
|
2457
2452
|
type = AST::Types::Proc.new(
|
2458
2453
|
type: block_type.type,
|
2459
|
-
location: nil,
|
2460
2454
|
block: nil,
|
2461
2455
|
self_type: block_type.self_type
|
2462
2456
|
)
|
@@ -3087,7 +3081,7 @@ module Steep
|
|
3087
3081
|
node_type_hint: nil
|
3088
3082
|
)
|
3089
3083
|
|
3090
|
-
block_constr.typing.
|
3084
|
+
block_constr.typing.cursor_context.set_body_context(node, block_constr.context)
|
3091
3085
|
|
3092
3086
|
params.each_single_param do |param|
|
3093
3087
|
_, block_constr = block_constr.synthesize(param.node, hint: param.type)
|
@@ -3295,7 +3289,11 @@ module Steep
|
|
3295
3289
|
method_name: method_name,
|
3296
3290
|
method_types: method.method_types
|
3297
3291
|
)
|
3298
|
-
|
3292
|
+
|
3293
|
+
decls = method.overloads.flat_map do |method_overload|
|
3294
|
+
method_overload.method_decls(method_name)
|
3295
|
+
end.to_set
|
3296
|
+
|
3299
3297
|
call = TypeInference::MethodCall::Error.new(
|
3300
3298
|
node: node,
|
3301
3299
|
context: context.call_context,
|
@@ -3499,8 +3497,9 @@ module Steep
|
|
3499
3497
|
]
|
3500
3498
|
}
|
3501
3499
|
|
3502
|
-
def try_special_method(node, receiver_type:, method_name:,
|
3503
|
-
|
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
|
3504
3503
|
|
3505
3504
|
case
|
3506
3505
|
when decl = decls.find {|decl| SPECIAL_METHOD_NAMES[:array_compact].include?(decl.method_name) }
|
@@ -3573,21 +3572,19 @@ module Steep
|
|
3573
3572
|
end
|
3574
3573
|
|
3575
3574
|
def type_method_call(node, method_name:, receiver_type:, method:, arguments:, block_params:, block_body:, tapp:, hint:)
|
3576
|
-
node_range = node.loc.expression.to_range
|
3577
|
-
|
3578
3575
|
# @type var fails: Array[[TypeInference::MethodCall::t, TypeConstruction]]
|
3579
3576
|
fails = []
|
3580
3577
|
|
3581
|
-
method.
|
3582
|
-
Steep.logger.tagged method_type.to_s do
|
3583
|
-
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|
|
3584
3581
|
constr = self.with_new_typing(child_typing)
|
3585
3582
|
|
3586
3583
|
call, constr = constr.try_special_method(
|
3587
3584
|
node,
|
3588
3585
|
receiver_type: receiver_type,
|
3589
3586
|
method_name: method_name,
|
3590
|
-
|
3587
|
+
method_overload: overload,
|
3591
3588
|
arguments: arguments,
|
3592
3589
|
block_params: block_params,
|
3593
3590
|
block_body: block_body,
|
@@ -3596,7 +3593,7 @@ module Steep
|
|
3596
3593
|
node,
|
3597
3594
|
receiver_type: receiver_type,
|
3598
3595
|
method_name: method_name,
|
3599
|
-
|
3596
|
+
method_overload: overload,
|
3600
3597
|
arguments: arguments,
|
3601
3598
|
block_params: block_params,
|
3602
3599
|
block_body: block_body,
|
@@ -3648,8 +3645,8 @@ module Steep
|
|
3648
3645
|
end
|
3649
3646
|
end
|
3650
3647
|
|
3651
|
-
def with_child_typing(
|
3652
|
-
constr = with_new_typing(typing.new_child(
|
3648
|
+
def with_child_typing()
|
3649
|
+
constr = with_new_typing(typing.new_child())
|
3653
3650
|
|
3654
3651
|
if block_given?
|
3655
3652
|
yield constr
|
@@ -3752,7 +3749,7 @@ module Steep
|
|
3752
3749
|
when TypeInference::SendArgs::PositionalArgs::SplatArg
|
3753
3750
|
arg_type, _ =
|
3754
3751
|
constr
|
3755
|
-
.with_child_typing(
|
3752
|
+
.with_child_typing()
|
3756
3753
|
.try_tuple_type!(arg.node.children[0])
|
3757
3754
|
arg.type = arg_type
|
3758
3755
|
|
@@ -3834,9 +3831,12 @@ module Steep
|
|
3834
3831
|
constr
|
3835
3832
|
end
|
3836
3833
|
|
3837
|
-
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:)
|
3838
3835
|
constr = self
|
3839
3836
|
|
3837
|
+
method_type = method_overload.method_type
|
3838
|
+
decls = method_overload.method_decls(method_name).to_set
|
3839
|
+
|
3840
3840
|
if tapp && type_args = tapp.types?(module_context.nesting, checker, [])
|
3841
3841
|
type_arity = method_type.type_params.size
|
3842
3842
|
type_param_names = method_type.type_params.map(&:name)
|
@@ -3848,21 +3848,23 @@ module Steep
|
|
3848
3848
|
|
3849
3849
|
type_args.each_with_index do |type, index|
|
3850
3850
|
param = method_type.type_params[index]
|
3851
|
-
|
3852
|
-
|
3851
|
+
|
3852
|
+
if upper_bound = param.upper_bound
|
3853
|
+
if result = no_subtyping?(sub_type: type.value, super_type: upper_bound)
|
3853
3854
|
args_ << AST::Builtin.any_type
|
3854
3855
|
constr.typing.add_error(
|
3855
3856
|
Diagnostic::Ruby::TypeArgumentMismatchError.new(
|
3856
|
-
type_arg: type,
|
3857
|
+
type_arg: type.value,
|
3857
3858
|
type_param: param,
|
3858
|
-
result: result
|
3859
|
+
result: result,
|
3860
|
+
location: type.location
|
3859
3861
|
)
|
3860
3862
|
)
|
3861
3863
|
else
|
3862
|
-
args_ << type
|
3864
|
+
args_ << type.value
|
3863
3865
|
end
|
3864
3866
|
else
|
3865
|
-
args_ << type
|
3867
|
+
args_ << type.value
|
3866
3868
|
end
|
3867
3869
|
end
|
3868
3870
|
|
@@ -3872,8 +3874,9 @@ module Steep
|
|
3872
3874
|
type_args.drop(type_arity).each do |type_arg|
|
3873
3875
|
constr.typing.add_error(
|
3874
3876
|
Diagnostic::Ruby::UnexpectedTypeArgument.new(
|
3875
|
-
type_arg: type_arg,
|
3876
|
-
method_type: method_type
|
3877
|
+
type_arg: type_arg.value,
|
3878
|
+
method_type: method_type,
|
3879
|
+
location: type_arg.location
|
3877
3880
|
)
|
3878
3881
|
)
|
3879
3882
|
end
|
@@ -3883,7 +3886,7 @@ module Steep
|
|
3883
3886
|
constr.typing.add_error(
|
3884
3887
|
Diagnostic::Ruby::InsufficientTypeArgument.new(
|
3885
3888
|
node: tapp.node,
|
3886
|
-
type_args: type_args,
|
3889
|
+
type_args: type_args.map(&:value),
|
3887
3890
|
method_type: method_type
|
3888
3891
|
)
|
3889
3892
|
)
|
@@ -3995,10 +3998,10 @@ module Steep
|
|
3995
3998
|
)
|
3996
3999
|
|
3997
4000
|
block_constr = block_constr.with_new_typing(
|
3998
|
-
block_constr.typing.new_child(
|
4001
|
+
block_constr.typing.new_child()
|
3999
4002
|
)
|
4000
4003
|
|
4001
|
-
block_constr.typing.
|
4004
|
+
block_constr.typing.cursor_context.set_body_context(node, block_constr.context)
|
4002
4005
|
|
4003
4006
|
pairs.each do |param, type|
|
4004
4007
|
case param
|
@@ -4280,7 +4283,7 @@ module Steep
|
|
4280
4283
|
method_name: method_name,
|
4281
4284
|
actual_method_type: method_type,
|
4282
4285
|
return_type: return_type || method_type.type.return_type,
|
4283
|
-
method_decls:
|
4286
|
+
method_decls: decls
|
4284
4287
|
)
|
4285
4288
|
else
|
4286
4289
|
TypeInference::MethodCall::Error.new(
|
@@ -4289,7 +4292,7 @@ module Steep
|
|
4289
4292
|
receiver_type: receiver_type,
|
4290
4293
|
method_name: method_name,
|
4291
4294
|
return_type: return_type || method_type.type.return_type,
|
4292
|
-
method_decls:
|
4295
|
+
method_decls: decls,
|
4293
4296
|
errors: errors
|
4294
4297
|
)
|
4295
4298
|
end
|
@@ -4345,7 +4348,7 @@ module Steep
|
|
4345
4348
|
node_type_hint: nil
|
4346
4349
|
)
|
4347
4350
|
|
4348
|
-
block_constr.typing.
|
4351
|
+
block_constr.typing.cursor_context.set_body_context(node, block_constr.context)
|
4349
4352
|
|
4350
4353
|
block_params.params.each do |param|
|
4351
4354
|
param.each_param do |param|
|
@@ -4523,7 +4526,7 @@ module Steep
|
|
4523
4526
|
body_type, _, context = synthesize(block_body, hint: block_context&.body_type || block_type_hint)
|
4524
4527
|
|
4525
4528
|
range = block_body.loc.expression.end_pos..node.loc.end.begin_pos
|
4526
|
-
typing.
|
4529
|
+
typing.cursor_context.set(range, context)
|
4527
4530
|
|
4528
4531
|
body_type
|
4529
4532
|
else
|
@@ -4548,7 +4551,7 @@ module Steep
|
|
4548
4551
|
types = types.reject {|t| t.is_a?(AST::Types::Bot) }
|
4549
4552
|
|
4550
4553
|
if types.empty?
|
4551
|
-
AST::Types::Bot.
|
4554
|
+
AST::Types::Bot.instance
|
4552
4555
|
else
|
4553
4556
|
types.inject do |type1, type2|
|
4554
4557
|
next type2 if type1.is_a?(AST::Types::Any)
|
@@ -4718,7 +4721,7 @@ module Steep
|
|
4718
4721
|
end
|
4719
4722
|
|
4720
4723
|
def unwrap(type)
|
4721
|
-
checker.factory.unwrap_optional(type) || AST::Types::Bot.
|
4724
|
+
checker.factory.unwrap_optional(type) || AST::Types::Bot.instance
|
4722
4725
|
end
|
4723
4726
|
|
4724
4727
|
def deep_expand_alias(type)
|
@@ -4765,7 +4768,7 @@ module Steep
|
|
4765
4768
|
when AST::Types::Any
|
4766
4769
|
nil
|
4767
4770
|
else
|
4768
|
-
literal_type = AST::Types::Literal.new(value: literal
|
4771
|
+
literal_type = AST::Types::Literal.new(value: literal)
|
4769
4772
|
if check_relation(sub_type: literal_type, super_type: hint).success?
|
4770
4773
|
hint
|
4771
4774
|
end
|
@@ -4788,9 +4791,7 @@ module Steep
|
|
4788
4791
|
def try_tuple_type!(node, hint: nil)
|
4789
4792
|
if node.type == :array
|
4790
4793
|
if hint.nil? || hint.is_a?(AST::Types::Tuple)
|
4791
|
-
|
4792
|
-
|
4793
|
-
typing.new_child(node_range) do |child_typing|
|
4794
|
+
typing.new_child() do |child_typing|
|
4794
4795
|
if pair = with_new_typing(child_typing).try_tuple_type(node, hint)
|
4795
4796
|
return pair.with(constr: pair.constr.save_typing)
|
4796
4797
|
end
|
@@ -4961,7 +4962,7 @@ module Steep
|
|
4961
4962
|
each_child_node(hash_node) do |child|
|
4962
4963
|
if child.type == :pair
|
4963
4964
|
case child.children[0].type
|
4964
|
-
when :sym
|
4965
|
+
when :sym
|
4965
4966
|
key_node = child.children[0] #: Parser::AST::Node
|
4966
4967
|
value_node = child.children[1] #: Parser::AST::Node
|
4967
4968
|
|
@@ -4990,7 +4991,7 @@ module Steep
|
|
4990
4991
|
end
|
4991
4992
|
end
|
4992
4993
|
|
4993
|
-
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))
|
4994
4995
|
constr.add_typing(hash_node, type: type)
|
4995
4996
|
end
|
4996
4997
|
|
@@ -4998,18 +4999,17 @@ module Steep
|
|
4998
4999
|
if hint
|
4999
5000
|
hint = deep_expand_alias(hint)
|
5000
5001
|
end
|
5001
|
-
range = hash_node.loc.expression.yield_self {|l| l.begin_pos..l.end_pos }
|
5002
5002
|
|
5003
5003
|
case hint
|
5004
5004
|
when AST::Types::Record
|
5005
|
-
with_child_typing(
|
5005
|
+
with_child_typing() do |constr|
|
5006
5006
|
pair = constr.type_hash_record(hash_node, hint)
|
5007
5007
|
if pair
|
5008
5008
|
return pair.with(constr: pair.constr.save_typing)
|
5009
5009
|
end
|
5010
5010
|
end
|
5011
5011
|
when AST::Types::Union
|
5012
|
-
pair = pick_one_of(hint.types
|
5012
|
+
pair = pick_one_of(hint.types) do |type, constr|
|
5013
5013
|
constr.type_hash(hash_node, hint: type)
|
5014
5014
|
end
|
5015
5015
|
|
@@ -5075,9 +5075,9 @@ module Steep
|
|
5075
5075
|
constr.add_typing(hash_node, type: hash_type)
|
5076
5076
|
end
|
5077
5077
|
|
5078
|
-
def pick_one_of(types
|
5078
|
+
def pick_one_of(types)
|
5079
5079
|
types.each do |type|
|
5080
|
-
with_child_typing(
|
5080
|
+
with_child_typing() do |constr|
|
5081
5081
|
if (type_, constr = yield(type, constr))
|
5082
5082
|
constr.check_relation(sub_type: type_, super_type: type).then do
|
5083
5083
|
constr = constr.save_typing
|
@@ -174,7 +174,7 @@ module Steep
|
|
174
174
|
def params_type0(hint:)
|
175
175
|
# @type var leadings: Array[AST::Types::t]
|
176
176
|
# @type var optionals: Array[AST::Types::t]
|
177
|
-
|
177
|
+
|
178
178
|
if hint
|
179
179
|
case
|
180
180
|
when leading_params.size == hint.required.size
|
@@ -223,8 +223,8 @@ module Steep
|
|
223
223
|
end
|
224
224
|
end
|
225
225
|
else
|
226
|
-
leadings = leading_params.map {|param| param.type || AST::Types::Any.
|
227
|
-
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 }
|
228
228
|
|
229
229
|
if rest_param
|
230
230
|
if rest_type = rest_param.type
|
@@ -232,7 +232,7 @@ module Steep
|
|
232
232
|
rest = array.args.first or raise
|
233
233
|
end
|
234
234
|
end
|
235
|
-
rest ||= AST::Types::Any.
|
235
|
+
rest ||= AST::Types::Any.instance
|
236
236
|
end
|
237
237
|
end
|
238
238
|
|
@@ -282,7 +282,7 @@ module Steep
|
|
282
282
|
if ty
|
283
283
|
zip << [param, ty]
|
284
284
|
else
|
285
|
-
zip << [param, AST::Types::Nil.
|
285
|
+
zip << [param, AST::Types::Nil.instance]
|
286
286
|
end
|
287
287
|
end
|
288
288
|
|
@@ -291,7 +291,7 @@ module Steep
|
|
291
291
|
union = AST::Types::Union.build(types: types)
|
292
292
|
zip << [rest_param, AST::Builtin::Array.instance_type(union)]
|
293
293
|
else
|
294
|
-
zip << [rest_param, AST::Types::Nil.
|
294
|
+
zip << [rest_param, AST::Types::Nil.instance]
|
295
295
|
end
|
296
296
|
end
|
297
297
|
end
|