steep-activesupport-4 1.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.gitmodules +0 -0
- data/CHANGELOG.md +1032 -0
- data/LICENSE +21 -0
- data/README.md +260 -0
- data/Rakefile +227 -0
- data/Steepfile +68 -0
- data/bin/console +14 -0
- data/bin/generate-diagnostics-docs.rb +112 -0
- data/bin/mem_graph.rb +67 -0
- data/bin/mem_prof.rb +102 -0
- data/bin/output_rebaseline.rb +34 -0
- data/bin/output_test.rb +60 -0
- data/bin/rbs +20 -0
- data/bin/rbs-inline +19 -0
- data/bin/setup +9 -0
- data/bin/stackprof_test.rb +19 -0
- data/bin/steep +19 -0
- data/bin/steep-check.rb +251 -0
- data/bin/steep-prof +16 -0
- data/doc/narrowing.md +195 -0
- data/doc/shape.md +194 -0
- data/exe/steep +18 -0
- data/guides/README.md +5 -0
- data/guides/src/gem-rbs-collection/gem-rbs-collection.md +126 -0
- data/guides/src/getting-started/getting-started.md +163 -0
- data/guides/src/nil-optional/nil-optional.md +195 -0
- data/lib/steep/annotation_parser.rb +199 -0
- data/lib/steep/ast/annotation/collection.rb +172 -0
- data/lib/steep/ast/annotation.rb +137 -0
- data/lib/steep/ast/builtin.rb +104 -0
- data/lib/steep/ast/ignore.rb +148 -0
- data/lib/steep/ast/node/type_application.rb +88 -0
- data/lib/steep/ast/node/type_assertion.rb +81 -0
- data/lib/steep/ast/types/any.rb +35 -0
- data/lib/steep/ast/types/boolean.rb +45 -0
- data/lib/steep/ast/types/bot.rb +35 -0
- data/lib/steep/ast/types/class.rb +43 -0
- data/lib/steep/ast/types/factory.rb +557 -0
- data/lib/steep/ast/types/helper.rb +40 -0
- data/lib/steep/ast/types/instance.rb +42 -0
- data/lib/steep/ast/types/intersection.rb +93 -0
- data/lib/steep/ast/types/literal.rb +59 -0
- data/lib/steep/ast/types/logic.rb +84 -0
- data/lib/steep/ast/types/name.rb +128 -0
- data/lib/steep/ast/types/nil.rb +41 -0
- data/lib/steep/ast/types/proc.rb +117 -0
- data/lib/steep/ast/types/record.rb +79 -0
- data/lib/steep/ast/types/self.rb +43 -0
- data/lib/steep/ast/types/shared_instance.rb +11 -0
- data/lib/steep/ast/types/top.rb +35 -0
- data/lib/steep/ast/types/tuple.rb +60 -0
- data/lib/steep/ast/types/union.rb +97 -0
- data/lib/steep/ast/types/var.rb +65 -0
- data/lib/steep/ast/types/void.rb +35 -0
- data/lib/steep/cli.rb +401 -0
- data/lib/steep/diagnostic/deprecated/else_on_exhaustive_case.rb +20 -0
- data/lib/steep/diagnostic/deprecated/unknown_constant_assigned.rb +28 -0
- data/lib/steep/diagnostic/helper.rb +18 -0
- data/lib/steep/diagnostic/lsp_formatter.rb +78 -0
- data/lib/steep/diagnostic/result_printer2.rb +48 -0
- data/lib/steep/diagnostic/ruby.rb +1221 -0
- data/lib/steep/diagnostic/signature.rb +570 -0
- data/lib/steep/drivers/annotations.rb +52 -0
- data/lib/steep/drivers/check.rb +339 -0
- data/lib/steep/drivers/checkfile.rb +210 -0
- data/lib/steep/drivers/diagnostic_printer.rb +105 -0
- data/lib/steep/drivers/init.rb +66 -0
- data/lib/steep/drivers/langserver.rb +56 -0
- data/lib/steep/drivers/print_project.rb +113 -0
- data/lib/steep/drivers/stats.rb +203 -0
- data/lib/steep/drivers/utils/driver_helper.rb +143 -0
- data/lib/steep/drivers/utils/jobs_option.rb +26 -0
- data/lib/steep/drivers/vendor.rb +27 -0
- data/lib/steep/drivers/watch.rb +194 -0
- data/lib/steep/drivers/worker.rb +58 -0
- data/lib/steep/equatable.rb +23 -0
- data/lib/steep/expectations.rb +228 -0
- data/lib/steep/index/rbs_index.rb +350 -0
- data/lib/steep/index/signature_symbol_provider.rb +185 -0
- data/lib/steep/index/source_index.rb +167 -0
- data/lib/steep/interface/block.rb +103 -0
- data/lib/steep/interface/builder.rb +843 -0
- data/lib/steep/interface/function.rb +1090 -0
- data/lib/steep/interface/method_type.rb +330 -0
- data/lib/steep/interface/shape.rb +239 -0
- data/lib/steep/interface/substitution.rb +159 -0
- data/lib/steep/interface/type_param.rb +115 -0
- data/lib/steep/located_value.rb +20 -0
- data/lib/steep/method_name.rb +42 -0
- data/lib/steep/module_helper.rb +24 -0
- data/lib/steep/node_helper.rb +273 -0
- data/lib/steep/path_helper.rb +30 -0
- data/lib/steep/project/dsl.rb +268 -0
- data/lib/steep/project/group.rb +31 -0
- data/lib/steep/project/options.rb +63 -0
- data/lib/steep/project/pattern.rb +59 -0
- data/lib/steep/project/target.rb +92 -0
- data/lib/steep/project.rb +78 -0
- data/lib/steep/rake_task.rb +132 -0
- data/lib/steep/range_extension.rb +29 -0
- data/lib/steep/server/base_worker.rb +97 -0
- data/lib/steep/server/change_buffer.rb +73 -0
- data/lib/steep/server/custom_methods.rb +77 -0
- data/lib/steep/server/delay_queue.rb +45 -0
- data/lib/steep/server/interaction_worker.rb +492 -0
- data/lib/steep/server/lsp_formatter.rb +455 -0
- data/lib/steep/server/master.rb +912 -0
- data/lib/steep/server/target_group_files.rb +205 -0
- data/lib/steep/server/type_check_controller.rb +366 -0
- data/lib/steep/server/type_check_worker.rb +303 -0
- data/lib/steep/server/work_done_progress.rb +64 -0
- data/lib/steep/server/worker_process.rb +176 -0
- data/lib/steep/services/completion_provider.rb +802 -0
- data/lib/steep/services/content_change.rb +61 -0
- data/lib/steep/services/file_loader.rb +74 -0
- data/lib/steep/services/goto_service.rb +441 -0
- data/lib/steep/services/hover_provider/rbs.rb +88 -0
- data/lib/steep/services/hover_provider/ruby.rb +221 -0
- data/lib/steep/services/hover_provider/singleton_methods.rb +20 -0
- data/lib/steep/services/path_assignment.rb +46 -0
- data/lib/steep/services/signature_help_provider.rb +202 -0
- data/lib/steep/services/signature_service.rb +428 -0
- data/lib/steep/services/stats_calculator.rb +68 -0
- data/lib/steep/services/type_check_service.rb +394 -0
- data/lib/steep/services/type_name_completion.rb +236 -0
- data/lib/steep/signature/validator.rb +651 -0
- data/lib/steep/source/ignore_ranges.rb +69 -0
- data/lib/steep/source.rb +691 -0
- data/lib/steep/subtyping/cache.rb +30 -0
- data/lib/steep/subtyping/check.rb +1113 -0
- data/lib/steep/subtyping/constraints.rb +341 -0
- data/lib/steep/subtyping/relation.rb +101 -0
- data/lib/steep/subtyping/result.rb +324 -0
- data/lib/steep/subtyping/variable_variance.rb +89 -0
- data/lib/steep/test.rb +9 -0
- data/lib/steep/thread_waiter.rb +43 -0
- data/lib/steep/type_construction.rb +5183 -0
- data/lib/steep/type_inference/block_params.rb +416 -0
- data/lib/steep/type_inference/case_when.rb +303 -0
- data/lib/steep/type_inference/constant_env.rb +56 -0
- data/lib/steep/type_inference/context.rb +195 -0
- data/lib/steep/type_inference/logic_type_interpreter.rb +613 -0
- data/lib/steep/type_inference/method_call.rb +193 -0
- data/lib/steep/type_inference/method_params.rb +531 -0
- data/lib/steep/type_inference/multiple_assignment.rb +194 -0
- data/lib/steep/type_inference/send_args.rb +712 -0
- data/lib/steep/type_inference/type_env.rb +341 -0
- data/lib/steep/type_inference/type_env_builder.rb +138 -0
- data/lib/steep/typing.rb +321 -0
- data/lib/steep/version.rb +3 -0
- data/lib/steep.rb +369 -0
- data/manual/annotations.md +181 -0
- data/manual/ignore.md +20 -0
- data/manual/ruby-diagnostics.md +1879 -0
- data/sample/Steepfile +22 -0
- data/sample/lib/conference.rb +49 -0
- data/sample/lib/length.rb +35 -0
- data/sample/sig/conference.rbs +42 -0
- data/sample/sig/generics.rbs +15 -0
- data/sample/sig/length.rbs +34 -0
- data/steep-activesupport-4.gemspec +55 -0
- metadata +437 -0
@@ -0,0 +1,194 @@
|
|
1
|
+
module Steep
|
2
|
+
module TypeInference
|
3
|
+
class MultipleAssignment
|
4
|
+
Assignments = _ = Struct.new(:rhs_type, :optional, :leading_assignments, :trailing_assignments, :splat_assignment, keyword_init: true) do
|
5
|
+
# @implements Assignments
|
6
|
+
|
7
|
+
def each(&block)
|
8
|
+
if block
|
9
|
+
leading_assignments.each(&block)
|
10
|
+
if sp = splat_assignment
|
11
|
+
yield sp
|
12
|
+
end
|
13
|
+
trailing_assignments.each(&block)
|
14
|
+
else
|
15
|
+
enum_for :each
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def expand(mlhs, rhs_type, optional)
|
21
|
+
lhss = mlhs.children
|
22
|
+
|
23
|
+
case rhs_type
|
24
|
+
when AST::Types::Tuple
|
25
|
+
expand_tuple(lhss.dup, rhs_type, rhs_type.types.dup, optional)
|
26
|
+
when AST::Types::Name::Instance
|
27
|
+
if AST::Builtin::Array.instance_type?(rhs_type)
|
28
|
+
expand_array(lhss.dup, rhs_type, optional)
|
29
|
+
end
|
30
|
+
when AST::Types::Any
|
31
|
+
expand_any(lhss, rhs_type, AST::Builtin.any_type, optional)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def expand_tuple(lhss, rhs_type, tuples, optional)
|
36
|
+
# @type var leading_assignments: Array[node_type_pair]
|
37
|
+
leading_assignments = []
|
38
|
+
# @type var trailing_assignments: Array[node_type_pair]
|
39
|
+
trailing_assignments = []
|
40
|
+
# @type var splat_assignment: node_type_pair?
|
41
|
+
splat_assignment = nil
|
42
|
+
|
43
|
+
while !lhss.empty?
|
44
|
+
first = lhss.first or raise
|
45
|
+
|
46
|
+
case
|
47
|
+
when first.type == :splat
|
48
|
+
break
|
49
|
+
else
|
50
|
+
leading_assignments << [first, tuples.first || AST::Builtin.nil_type]
|
51
|
+
lhss.shift
|
52
|
+
tuples.shift
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
while !lhss.empty?
|
57
|
+
last = lhss.last or raise
|
58
|
+
|
59
|
+
case
|
60
|
+
when last.type == :splat
|
61
|
+
break
|
62
|
+
else
|
63
|
+
trailing_assignments << [last, tuples.last || AST::Builtin.nil_type]
|
64
|
+
lhss.pop
|
65
|
+
tuples.pop
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
case lhss.size
|
70
|
+
when 0
|
71
|
+
# nop
|
72
|
+
when 1
|
73
|
+
splat_assignment = [lhss.first || raise, AST::Types::Tuple.new(types: tuples)]
|
74
|
+
else
|
75
|
+
raise
|
76
|
+
end
|
77
|
+
|
78
|
+
Assignments.new(
|
79
|
+
rhs_type: rhs_type,
|
80
|
+
optional: optional,
|
81
|
+
leading_assignments: leading_assignments,
|
82
|
+
trailing_assignments: trailing_assignments,
|
83
|
+
splat_assignment: splat_assignment
|
84
|
+
)
|
85
|
+
end
|
86
|
+
|
87
|
+
def expand_array(lhss, rhs_type, optional)
|
88
|
+
element_type = rhs_type.args[0] or raise
|
89
|
+
|
90
|
+
# @type var leading_assignments: Array[node_type_pair]
|
91
|
+
leading_assignments = []
|
92
|
+
# @type var trailing_assignments: Array[node_type_pair]
|
93
|
+
trailing_assignments = []
|
94
|
+
# @type var splat_assignment: node_type_pair?
|
95
|
+
splat_assignment = nil
|
96
|
+
|
97
|
+
while !lhss.empty?
|
98
|
+
first = lhss.first or raise
|
99
|
+
|
100
|
+
case
|
101
|
+
when first.type == :splat
|
102
|
+
break
|
103
|
+
else
|
104
|
+
leading_assignments << [first, AST::Builtin.optional(element_type)]
|
105
|
+
lhss.shift
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
while !lhss.empty?
|
110
|
+
last = lhss.last or raise
|
111
|
+
|
112
|
+
case
|
113
|
+
when last.type == :splat
|
114
|
+
break
|
115
|
+
else
|
116
|
+
trailing_assignments << [last, AST::Builtin.optional(element_type)]
|
117
|
+
lhss.pop
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
case lhss.size
|
122
|
+
when 0
|
123
|
+
# nop
|
124
|
+
when 1
|
125
|
+
splat_assignment = [
|
126
|
+
lhss.first || raise,
|
127
|
+
AST::Builtin::Array.instance_type(element_type)
|
128
|
+
]
|
129
|
+
else
|
130
|
+
raise
|
131
|
+
end
|
132
|
+
|
133
|
+
Assignments.new(
|
134
|
+
rhs_type: rhs_type,
|
135
|
+
optional: optional,
|
136
|
+
leading_assignments: leading_assignments,
|
137
|
+
trailing_assignments: trailing_assignments,
|
138
|
+
splat_assignment: splat_assignment
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
def expand_any(nodes, rhs_type, element_type, optional)
|
143
|
+
# @type var leading_assignments: Array[node_type_pair]
|
144
|
+
leading_assignments = []
|
145
|
+
# @type var trailing_assignments: Array[node_type_pair]
|
146
|
+
trailing_assignments = []
|
147
|
+
# @type var splat_assignment: node_type_pair?
|
148
|
+
splat_assignment = nil
|
149
|
+
|
150
|
+
array = leading_assignments
|
151
|
+
|
152
|
+
nodes.each do |node|
|
153
|
+
case node.type
|
154
|
+
when :splat
|
155
|
+
splat_assignment = [node, AST::Builtin::Array.instance_type(element_type)]
|
156
|
+
array = trailing_assignments
|
157
|
+
else
|
158
|
+
array << [node, element_type]
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
Assignments.new(
|
163
|
+
rhs_type: rhs_type,
|
164
|
+
optional: optional,
|
165
|
+
leading_assignments: leading_assignments,
|
166
|
+
trailing_assignments: trailing_assignments,
|
167
|
+
splat_assignment: splat_assignment
|
168
|
+
)
|
169
|
+
end
|
170
|
+
|
171
|
+
def hint_for_mlhs(mlhs, env)
|
172
|
+
case mlhs.type
|
173
|
+
when :mlhs
|
174
|
+
types = mlhs.children.map do |node|
|
175
|
+
hint_for_mlhs(node, env) or return
|
176
|
+
end
|
177
|
+
AST::Types::Tuple.new(types: types)
|
178
|
+
when :lvasgn, :ivasgn, :gvasgn
|
179
|
+
name = mlhs.children[0]
|
180
|
+
|
181
|
+
unless TypeConstruction::SPECIAL_LVAR_NAMES.include?(name)
|
182
|
+
env[name] || AST::Builtin.any_type
|
183
|
+
else
|
184
|
+
AST::Builtin.any_type
|
185
|
+
end
|
186
|
+
when :splat
|
187
|
+
return
|
188
|
+
else
|
189
|
+
return
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|