steep 1.7.0.dev.3 → 1.7.0
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 +43 -0
- data/README.md +18 -0
- data/doc/narrowing.md +1 -1
- data/doc/shape.md +176 -0
- data/guides/src/gem-rbs-collection/gem-rbs-collection.md +7 -24
- data/lib/steep/ast/types/factory.rb +27 -18
- data/lib/steep/ast/types/proc.rb +14 -9
- data/lib/steep/interface/block.rb +1 -1
- data/lib/steep/interface/builder.rb +1 -0
- data/lib/steep/interface/function.rb +14 -6
- data/lib/steep/interface/method_type.rb +15 -7
- data/lib/steep/project/pattern.rb +1 -2
- data/lib/steep/rake_task.rb +132 -0
- data/lib/steep/server/interaction_worker.rb +6 -0
- data/lib/steep/server/lsp_formatter.rb +2 -0
- data/lib/steep/services/completion_provider.rb +1 -1
- data/lib/steep/services/file_loader.rb +15 -20
- data/lib/steep/services/signature_help_provider.rb +11 -9
- data/lib/steep/signature/validator.rb +1 -1
- data/lib/steep/subtyping/check.rb +15 -6
- data/lib/steep/subtyping/variable_variance.rb +3 -3
- data/lib/steep/type_construction.rb +186 -149
- data/lib/steep/type_inference/block_params.rb +1 -1
- data/lib/steep/type_inference/logic_type_interpreter.rb +2 -1
- data/lib/steep/type_inference/method_params.rb +16 -0
- data/lib/steep/type_inference/send_args.rb +5 -2
- data/lib/steep/version.rb +1 -1
- data/steep.gemspec +5 -2
- metadata +7 -145
- data/.github/dependabot.yml +0 -28
- data/.github/workflows/ruby-windows.yml +0 -35
- data/.github/workflows/ruby.yml +0 -32
- data/.vscode/steep-shared.code-snippets +0 -41
- data/Gemfile +0 -14
- data/Gemfile.lock +0 -104
- data/Gemfile.steep +0 -0
- data/gemfile_steep/Gemfile +0 -3
- data/gemfile_steep/Gemfile.lock +0 -77
- data/rbs_collection.steep.lock.yaml +0 -108
- data/rbs_collection.steep.yaml +0 -23
- data/sig/shims/bundler.rbs +0 -3
- data/sig/shims/concurrent-ruby.rbs +0 -39
- data/sig/shims/exception.rbs +0 -4
- data/sig/shims/language-server_protocol.rbs +0 -450
- data/sig/shims/parser/comment.rbs +0 -33
- data/sig/shims/parser/nodes.rbs +0 -252
- data/sig/shims/parser/source/map.rbs +0 -146
- data/sig/shims/parser/source/range.rbs +0 -237
- data/sig/shims/parser.rbs +0 -69
- data/sig/shims/string.rbs +0 -4
- data/sig/shims/tagged_logging.rbs +0 -6
- data/sig/shims/yaml.rbs +0 -4
- data/sig/steep/annotation_parser.rbs +0 -60
- data/sig/steep/ast/annotation/collection.rbs +0 -78
- data/sig/steep/ast/annotation.rbs +0 -121
- data/sig/steep/ast/builtin.rbs +0 -69
- data/sig/steep/ast/ignore.rbs +0 -66
- data/sig/steep/ast/node/type_application.rbs +0 -31
- data/sig/steep/ast/node/type_assertion.rbs +0 -32
- data/sig/steep/ast/types/any.rbs +0 -29
- data/sig/steep/ast/types/boolean.rbs +0 -31
- data/sig/steep/ast/types/bot.rbs +0 -29
- data/sig/steep/ast/types/class.rbs +0 -33
- data/sig/steep/ast/types/factory.rbs +0 -110
- data/sig/steep/ast/types/helper.rbs +0 -24
- data/sig/steep/ast/types/instance.rbs +0 -33
- data/sig/steep/ast/types/intersection.rbs +0 -40
- data/sig/steep/ast/types/literal.rbs +0 -35
- data/sig/steep/ast/types/logic.rbs +0 -83
- data/sig/steep/ast/types/name.rbs +0 -84
- data/sig/steep/ast/types/nil.rbs +0 -31
- data/sig/steep/ast/types/proc.rbs +0 -53
- data/sig/steep/ast/types/record.rbs +0 -39
- data/sig/steep/ast/types/self.rbs +0 -33
- data/sig/steep/ast/types/top.rbs +0 -29
- data/sig/steep/ast/types/tuple.rbs +0 -37
- data/sig/steep/ast/types/union.rbs +0 -40
- data/sig/steep/ast/types/var.rbs +0 -42
- data/sig/steep/ast/types/void.rbs +0 -29
- data/sig/steep/ast/types.rbs +0 -16
- data/sig/steep/cli.rbs +0 -55
- data/sig/steep/diagnostic/deprecated/else_on_exhaustive_case.rbs +0 -13
- data/sig/steep/diagnostic/deprecated/unknown_constant_assigned.rbs +0 -15
- data/sig/steep/diagnostic/helper.rbs +0 -15
- data/sig/steep/diagnostic/lsp_formatter.rbs +0 -36
- data/sig/steep/diagnostic/ruby.rbs +0 -703
- data/sig/steep/diagnostic/signature.rbs +0 -252
- data/sig/steep/drivers/annotations.rbs +0 -17
- data/sig/steep/drivers/check.rbs +0 -33
- data/sig/steep/drivers/checkfile.rbs +0 -27
- data/sig/steep/drivers/diagnostic_printer.rbs +0 -25
- data/sig/steep/drivers/init.rbs +0 -19
- data/sig/steep/drivers/langserver.rbs +0 -36
- data/sig/steep/drivers/print_project.rbs +0 -15
- data/sig/steep/drivers/stats.rbs +0 -47
- data/sig/steep/drivers/utils/driver_helper.rbs +0 -25
- data/sig/steep/drivers/utils/jobs_option.rbs +0 -19
- data/sig/steep/drivers/validate.rbs +0 -15
- data/sig/steep/drivers/vendor.rbs +0 -19
- data/sig/steep/drivers/watch.rbs +0 -27
- data/sig/steep/drivers/worker.rbs +0 -29
- data/sig/steep/equatable.rbs +0 -11
- data/sig/steep/expectations.rbs +0 -72
- data/sig/steep/index/rbs_index.rbs +0 -141
- data/sig/steep/index/signature_symbol_provider.rbs +0 -41
- data/sig/steep/index/source_index.rbs +0 -63
- data/sig/steep/interface/block.rbs +0 -41
- data/sig/steep/interface/builder.rbs +0 -152
- data/sig/steep/interface/function.rbs +0 -270
- data/sig/steep/interface/method_type.rbs +0 -105
- data/sig/steep/interface/shape.rbs +0 -80
- data/sig/steep/interface/substitution.rbs +0 -51
- data/sig/steep/interface/type_param.rbs +0 -43
- data/sig/steep/method_name.rbs +0 -30
- data/sig/steep/module_helper.rbs +0 -16
- data/sig/steep/node_helper.rbs +0 -91
- data/sig/steep/path_helper.rbs +0 -15
- data/sig/steep/project/dsl.rbs +0 -108
- data/sig/steep/project/options.rbs +0 -47
- data/sig/steep/project/pattern.rbs +0 -47
- data/sig/steep/project/target.rbs +0 -25
- data/sig/steep/project.rbs +0 -26
- data/sig/steep/range_extension.rbs +0 -7
- data/sig/steep/server/base_worker.rbs +0 -49
- data/sig/steep/server/change_buffer.rbs +0 -38
- data/sig/steep/server/delay_queue.rbs +0 -37
- data/sig/steep/server/interaction_worker.rbs +0 -90
- data/sig/steep/server/lsp_formatter.rbs +0 -63
- data/sig/steep/server/master.rbs +0 -299
- data/sig/steep/server/type_check_worker.rbs +0 -141
- data/sig/steep/server/worker_process.rbs +0 -97
- data/sig/steep/services/completion_provider.rbs +0 -264
- data/sig/steep/services/content_change.rbs +0 -37
- data/sig/steep/services/file_loader.rbs +0 -21
- data/sig/steep/services/goto_service.rbs +0 -106
- data/sig/steep/services/hover_provider/rbs.rbs +0 -47
- data/sig/steep/services/hover_provider/ruby.rbs +0 -127
- data/sig/steep/services/hover_provider/singleton_methods.rbs +0 -11
- data/sig/steep/services/path_assignment.rbs +0 -21
- data/sig/steep/services/signature_help_provider.rbs +0 -51
- data/sig/steep/services/signature_service.rbs +0 -156
- data/sig/steep/services/stats_calculator.rbs +0 -41
- data/sig/steep/services/type_check_service.rbs +0 -112
- data/sig/steep/services/type_name_completion.rbs +0 -135
- data/sig/steep/signature/validator.rbs +0 -85
- data/sig/steep/source/ignore_ranges.rbs +0 -38
- data/sig/steep/source.rbs +0 -105
- data/sig/steep/subtyping/cache.rbs +0 -17
- data/sig/steep/subtyping/check.rbs +0 -131
- data/sig/steep/subtyping/constraints.rbs +0 -111
- data/sig/steep/subtyping/relation.rbs +0 -63
- data/sig/steep/subtyping/result.rbs +0 -179
- data/sig/steep/subtyping/variable_variance.rbs +0 -25
- data/sig/steep/thread_waiter.rbs +0 -13
- data/sig/steep/type_construction.rbs +0 -542
- data/sig/steep/type_inference/block_params.rbs +0 -170
- data/sig/steep/type_inference/case_when.rbs +0 -130
- data/sig/steep/type_inference/constant_env.rbs +0 -29
- data/sig/steep/type_inference/context.rbs +0 -216
- data/sig/steep/type_inference/context_array.rbs +0 -38
- data/sig/steep/type_inference/logic_type_interpreter.rbs +0 -108
- data/sig/steep/type_inference/method_call.rbs +0 -124
- data/sig/steep/type_inference/method_params.rbs +0 -127
- data/sig/steep/type_inference/multiple_assignment.rbs +0 -76
- data/sig/steep/type_inference/send_args.rbs +0 -243
- data/sig/steep/type_inference/type_env.rbs +0 -160
- data/sig/steep/type_inference/type_env_builder.rbs +0 -81
- data/sig/steep/typing.rbs +0 -75
- data/sig/steep.rbs +0 -45
|
@@ -1635,28 +1635,32 @@ module Steep
|
|
|
1635
1635
|
when :yield
|
|
1636
1636
|
if method_context && method_context.method_type
|
|
1637
1637
|
if block_type = method_context.block_type
|
|
1638
|
-
|
|
1639
|
-
type
|
|
1640
|
-
|
|
1641
|
-
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1638
|
+
if block_type.type.params
|
|
1639
|
+
type = AST::Types::Proc.new(
|
|
1640
|
+
type: block_type.type,
|
|
1641
|
+
block: nil,
|
|
1642
|
+
self_type: block_type.self_type
|
|
1643
|
+
)
|
|
1644
|
+
args = TypeInference::SendArgs.new(
|
|
1645
|
+
node: node,
|
|
1646
|
+
arguments: node.children,
|
|
1647
|
+
type: type
|
|
1648
|
+
)
|
|
1648
1649
|
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1650
|
+
# @type var errors: Array[Diagnostic::Ruby::Base]
|
|
1651
|
+
errors = []
|
|
1652
|
+
constr = type_check_args(
|
|
1653
|
+
nil,
|
|
1654
|
+
args,
|
|
1655
|
+
Subtyping::Constraints.new(unknowns: []),
|
|
1656
|
+
errors
|
|
1657
|
+
)
|
|
1657
1658
|
|
|
1658
|
-
|
|
1659
|
-
|
|
1659
|
+
errors.each do |error|
|
|
1660
|
+
typing.add_error(error)
|
|
1661
|
+
end
|
|
1662
|
+
else
|
|
1663
|
+
constr = type_check_untyped_args(node.children)
|
|
1660
1664
|
end
|
|
1661
1665
|
|
|
1662
1666
|
add_typing(node, type: block_type.type.return_type)
|
|
@@ -2102,6 +2106,7 @@ module Steep
|
|
|
2102
2106
|
end
|
|
2103
2107
|
|
|
2104
2108
|
if body
|
|
2109
|
+
resbody_construction.typing.add_context_for_node(body, context: resbody_construction.context)
|
|
2105
2110
|
resbody_construction.synthesize(body, hint: hint)
|
|
2106
2111
|
else
|
|
2107
2112
|
Pair.new(constr: body_constr, type: AST::Builtin.nil_type)
|
|
@@ -2172,10 +2177,21 @@ module Steep
|
|
|
2172
2177
|
var_type = AST::Builtin.any_type
|
|
2173
2178
|
else
|
|
2174
2179
|
if each = calculate_interface(collection_type, :each, private: true)
|
|
2175
|
-
|
|
2180
|
+
method_type = (each.method_types || []).find do |type|
|
|
2181
|
+
if type.block
|
|
2182
|
+
if type.block.type.params
|
|
2183
|
+
type.block.type.params.first_param
|
|
2184
|
+
else
|
|
2185
|
+
true
|
|
2186
|
+
end
|
|
2187
|
+
end
|
|
2188
|
+
end
|
|
2189
|
+
if method_type
|
|
2176
2190
|
if block = method_type.block
|
|
2177
|
-
if first_param = block.type
|
|
2191
|
+
if first_param = block.type&.params&.first_param
|
|
2178
2192
|
var_type = first_param.type #: AST::Types::t
|
|
2193
|
+
else
|
|
2194
|
+
var_type - AST::Builtin.any_type
|
|
2179
2195
|
end
|
|
2180
2196
|
end
|
|
2181
2197
|
end
|
|
@@ -2386,31 +2402,33 @@ module Steep
|
|
|
2386
2402
|
|
|
2387
2403
|
if hint.is_a?(AST::Types::Proc) && value_node.type == :sym
|
|
2388
2404
|
if hint.one_arg?
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2392
|
-
|
|
2393
|
-
|
|
2394
|
-
|
|
2395
|
-
|
|
2396
|
-
|
|
2397
|
-
|
|
2398
|
-
method_type.type.
|
|
2405
|
+
if hint.type.params
|
|
2406
|
+
# Assumes Symbol#to_proc implementation
|
|
2407
|
+
param_type = hint.type.params.required[0]
|
|
2408
|
+
case param_type
|
|
2409
|
+
when AST::Types::Any
|
|
2410
|
+
type = AST::Types::Any.new
|
|
2411
|
+
else
|
|
2412
|
+
if method = calculate_interface(param_type, private: true)&.methods&.[](value_node.children[0])
|
|
2413
|
+
return_types = method.method_types.filter_map do |method_type|
|
|
2414
|
+
if method_type.type.params.nil? || method_type.type.params.optional?
|
|
2415
|
+
method_type.type.return_type
|
|
2416
|
+
end
|
|
2399
2417
|
end
|
|
2400
|
-
end
|
|
2401
2418
|
|
|
2402
|
-
|
|
2403
|
-
|
|
2404
|
-
|
|
2405
|
-
|
|
2406
|
-
|
|
2419
|
+
unless return_types.empty?
|
|
2420
|
+
type = AST::Types::Proc.new(
|
|
2421
|
+
type: Interface::Function.new(
|
|
2422
|
+
params: Interface::Function::Params.empty.with_first_param(
|
|
2423
|
+
Interface::Function::Params::PositionalParams::Required.new(param_type)
|
|
2424
|
+
),
|
|
2425
|
+
return_type: return_types[0],
|
|
2426
|
+
location: nil
|
|
2407
2427
|
),
|
|
2408
|
-
|
|
2409
|
-
|
|
2410
|
-
)
|
|
2411
|
-
|
|
2412
|
-
self_type: nil
|
|
2413
|
-
)
|
|
2428
|
+
block: nil,
|
|
2429
|
+
self_type: nil
|
|
2430
|
+
)
|
|
2431
|
+
end
|
|
2414
2432
|
end
|
|
2415
2433
|
end
|
|
2416
2434
|
end
|
|
@@ -3186,7 +3204,7 @@ module Steep
|
|
|
3186
3204
|
end
|
|
3187
3205
|
|
|
3188
3206
|
def type_send_interface(node, interface:, receiver:, receiver_type:, method_name:, arguments:, block_params:, block_body:, tapp:, hint:)
|
|
3189
|
-
method = interface
|
|
3207
|
+
method = interface.methods[method_name]
|
|
3190
3208
|
|
|
3191
3209
|
if method
|
|
3192
3210
|
call, constr = type_method_call(
|
|
@@ -3915,13 +3933,17 @@ module Steep
|
|
|
3915
3933
|
# @type var errors: Array[Diagnostic::Ruby::Base]
|
|
3916
3934
|
errors = []
|
|
3917
3935
|
|
|
3918
|
-
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3936
|
+
if method_type.type.params
|
|
3937
|
+
args = TypeInference::SendArgs.new(node: node, arguments: arguments, type: method_type)
|
|
3938
|
+
constr = constr.type_check_args(
|
|
3939
|
+
method_name,
|
|
3940
|
+
args,
|
|
3941
|
+
constraints,
|
|
3942
|
+
errors
|
|
3943
|
+
)
|
|
3944
|
+
else
|
|
3945
|
+
constr = constr.type_check_untyped_args(arguments)
|
|
3946
|
+
end
|
|
3925
3947
|
|
|
3926
3948
|
if block_params
|
|
3927
3949
|
# block is given
|
|
@@ -4010,11 +4032,12 @@ module Steep
|
|
|
4010
4032
|
end
|
|
4011
4033
|
|
|
4012
4034
|
method_type, solved, s = apply_solution(errors, node: node, method_type: method_type) {
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
|
|
4035
|
+
fvs_ = Set[] #: Set[AST::Types::variable]
|
|
4036
|
+
|
|
4037
|
+
fvs_.merge(method_type.type.params.free_variables) if method_type.type.params
|
|
4038
|
+
fvs_.merge(method_type.block.type.params.free_variables) if method_type.block.type.params
|
|
4039
|
+
|
|
4040
|
+
constraints.solution(checker, variables: fvs_, context: ccontext)
|
|
4018
4041
|
}
|
|
4019
4042
|
|
|
4020
4043
|
method_type.block or raise
|
|
@@ -4102,129 +4125,143 @@ module Steep
|
|
|
4102
4125
|
return_type = method_type.type.return_type
|
|
4103
4126
|
end
|
|
4104
4127
|
else
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4128
|
+
if args
|
|
4129
|
+
# Block is given but method doesn't accept
|
|
4130
|
+
#
|
|
4131
|
+
constr.type_block_without_hint(node: node, block_annotations: block_annotations, block_params: block_params_, block_body: block_body) do |error|
|
|
4132
|
+
errors << error
|
|
4133
|
+
end
|
|
4110
4134
|
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4135
|
+
case node.children[0].type
|
|
4136
|
+
when :super, :zsuper
|
|
4137
|
+
unless method_context!.super_method
|
|
4138
|
+
errors << Diagnostic::Ruby::UnexpectedSuper.new(
|
|
4139
|
+
node: node.children[0],
|
|
4140
|
+
method: method_name
|
|
4141
|
+
)
|
|
4142
|
+
end
|
|
4143
|
+
else
|
|
4144
|
+
errors << Diagnostic::Ruby::UnexpectedBlockGiven.new(
|
|
4145
|
+
node: node,
|
|
4146
|
+
method_type: method_type
|
|
4117
4147
|
)
|
|
4118
4148
|
end
|
|
4149
|
+
|
|
4150
|
+
method_type = eliminate_vars(method_type, type_param_names)
|
|
4151
|
+
return_type = method_type.type.return_type
|
|
4119
4152
|
else
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4153
|
+
if block_body
|
|
4154
|
+
block_annotations = source.annotations(block: node, factory: checker.factory, context: nesting)
|
|
4155
|
+
type_block_without_hint(
|
|
4156
|
+
node: node,
|
|
4157
|
+
block_annotations: block_annotations,
|
|
4158
|
+
block_params: TypeInference::BlockParams.from_node(block_params, annotations: block_annotations),
|
|
4159
|
+
block_body: block_body
|
|
4160
|
+
)
|
|
4161
|
+
end
|
|
4124
4162
|
end
|
|
4125
|
-
|
|
4126
|
-
method_type = eliminate_vars(method_type, type_param_names)
|
|
4127
|
-
return_type = method_type.type.return_type
|
|
4128
4163
|
end
|
|
4129
4164
|
else
|
|
4130
4165
|
# Block syntax is not given
|
|
4131
|
-
|
|
4166
|
+
if args
|
|
4167
|
+
arg = args.block_pass_arg
|
|
4132
4168
|
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4169
|
+
case
|
|
4170
|
+
when forwarded_args_node = args.forwarded_args_node
|
|
4171
|
+
(_, block = method_context!.forward_arg_type) or raise
|
|
4136
4172
|
|
|
4137
|
-
|
|
4138
|
-
|
|
4173
|
+
method_block_type = method_type.block&.to_proc_type || AST::Builtin.nil_type
|
|
4174
|
+
forwarded_block_type = block&.to_proc_type || AST::Builtin.nil_type
|
|
4139
4175
|
|
|
4140
|
-
|
|
4141
|
-
|
|
4142
|
-
|
|
4143
|
-
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4176
|
+
if result = constr.no_subtyping?(sub_type: forwarded_block_type, super_type: method_block_type)
|
|
4177
|
+
errors << Diagnostic::Ruby::IncompatibleArgumentForwarding.new(
|
|
4178
|
+
method_name: method_name,
|
|
4179
|
+
node: forwarded_args_node,
|
|
4180
|
+
block_pair: [block, method_type.block],
|
|
4181
|
+
result: result
|
|
4182
|
+
)
|
|
4183
|
+
end
|
|
4148
4184
|
|
|
4149
|
-
|
|
4150
|
-
|
|
4151
|
-
|
|
4152
|
-
|
|
4185
|
+
when arg.compatible?
|
|
4186
|
+
if arg.node
|
|
4187
|
+
# Block pass (&block) is given
|
|
4188
|
+
node_type, constr = constr.synthesize(arg.node, hint: arg.node_type)
|
|
4153
4189
|
|
|
4154
|
-
|
|
4155
|
-
|
|
4156
|
-
|
|
4190
|
+
nil_given =
|
|
4191
|
+
constr.check_relation(sub_type: node_type, super_type: AST::Builtin.nil_type).success? &&
|
|
4192
|
+
!node_type.is_a?(AST::Types::Any)
|
|
4157
4193
|
|
|
4158
|
-
|
|
4159
|
-
|
|
4160
|
-
|
|
4161
|
-
|
|
4162
|
-
|
|
4163
|
-
|
|
4194
|
+
if nil_given
|
|
4195
|
+
# nil is given ==> no block arg node is given
|
|
4196
|
+
method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
|
|
4197
|
+
constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
|
|
4198
|
+
}
|
|
4199
|
+
method_type = eliminate_vars(method_type, type_param_names) unless solved
|
|
4164
4200
|
|
|
4165
|
-
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
)
|
|
4170
|
-
else
|
|
4171
|
-
# non-nil value is given
|
|
4172
|
-
constr.check_relation(sub_type: node_type, super_type: arg.node_type, constraints: constraints).else do |result|
|
|
4173
|
-
errors << Diagnostic::Ruby::BlockTypeMismatch.new(
|
|
4174
|
-
node: arg.node,
|
|
4175
|
-
expected: arg.node_type,
|
|
4176
|
-
actual: node_type,
|
|
4177
|
-
result: result
|
|
4201
|
+
# Passing no block
|
|
4202
|
+
errors << Diagnostic::Ruby::RequiredBlockMissing.new(
|
|
4203
|
+
node: node,
|
|
4204
|
+
method_type: method_type
|
|
4178
4205
|
)
|
|
4179
|
-
|
|
4206
|
+
else
|
|
4207
|
+
# non-nil value is given
|
|
4208
|
+
constr.check_relation(sub_type: node_type, super_type: arg.node_type, constraints: constraints).else do |result|
|
|
4209
|
+
errors << Diagnostic::Ruby::BlockTypeMismatch.new(
|
|
4210
|
+
node: arg.node,
|
|
4211
|
+
expected: arg.node_type,
|
|
4212
|
+
actual: node_type,
|
|
4213
|
+
result: result
|
|
4214
|
+
)
|
|
4215
|
+
end
|
|
4180
4216
|
|
|
4217
|
+
method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
|
|
4218
|
+
constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
|
|
4219
|
+
}
|
|
4220
|
+
method_type = eliminate_vars(method_type, type_param_names) unless solved
|
|
4221
|
+
end
|
|
4222
|
+
else
|
|
4223
|
+
# Block is not given
|
|
4181
4224
|
method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
|
|
4182
4225
|
constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
|
|
4183
4226
|
}
|
|
4184
4227
|
method_type = eliminate_vars(method_type, type_param_names) unless solved
|
|
4185
4228
|
end
|
|
4186
|
-
|
|
4187
|
-
|
|
4229
|
+
|
|
4230
|
+
return_type = method_type.type.return_type
|
|
4231
|
+
|
|
4232
|
+
when arg.block_missing?
|
|
4233
|
+
# Block is required but not given
|
|
4188
4234
|
method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
|
|
4189
4235
|
constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
|
|
4190
4236
|
}
|
|
4191
|
-
method_type = eliminate_vars(method_type, type_param_names) unless solved
|
|
4192
|
-
end
|
|
4193
|
-
|
|
4194
|
-
return_type = method_type.type.return_type
|
|
4195
4237
|
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
|
|
4199
|
-
constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
|
|
4200
|
-
}
|
|
4201
|
-
|
|
4202
|
-
method_type = eliminate_vars(method_type, type_param_names) unless solved
|
|
4203
|
-
return_type = method_type.type.return_type
|
|
4238
|
+
method_type = eliminate_vars(method_type, type_param_names) unless solved
|
|
4239
|
+
return_type = method_type.type.return_type
|
|
4204
4240
|
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
|
|
4208
|
-
|
|
4241
|
+
errors << Diagnostic::Ruby::RequiredBlockMissing.new(
|
|
4242
|
+
node: node,
|
|
4243
|
+
method_type: method_type
|
|
4244
|
+
)
|
|
4209
4245
|
|
|
4210
|
-
|
|
4211
|
-
|
|
4246
|
+
when arg.unexpected_block?
|
|
4247
|
+
# Unexpected block pass node is given
|
|
4212
4248
|
|
|
4213
|
-
|
|
4249
|
+
arg.node or raise
|
|
4214
4250
|
|
|
4215
|
-
|
|
4216
|
-
|
|
4217
|
-
|
|
4218
|
-
|
|
4219
|
-
|
|
4251
|
+
method_type, solved, _ = apply_solution(errors, node: node, method_type: method_type) {
|
|
4252
|
+
constraints.solution(checker, variables: method_type.free_variables, context: ccontext)
|
|
4253
|
+
}
|
|
4254
|
+
method_type = eliminate_vars(method_type, type_param_names) unless solved
|
|
4255
|
+
return_type = method_type.type.return_type
|
|
4220
4256
|
|
|
4221
|
-
|
|
4257
|
+
node_type, constr = constr.synthesize(arg.node)
|
|
4222
4258
|
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4259
|
+
unless constr.check_relation(sub_type: node_type, super_type: AST::Builtin.nil_type).success?
|
|
4260
|
+
errors << Diagnostic::Ruby::UnexpectedBlockGiven.new(
|
|
4261
|
+
node: node,
|
|
4262
|
+
method_type: method_type
|
|
4263
|
+
)
|
|
4264
|
+
end
|
|
4228
4265
|
end
|
|
4229
4266
|
end
|
|
4230
4267
|
end
|
|
@@ -4796,7 +4833,7 @@ module Steep
|
|
|
4796
4833
|
if shape = calculate_interface(type, private: false)
|
|
4797
4834
|
if entry = shape.methods[method]
|
|
4798
4835
|
method_type = entry.method_types.find do |method_type|
|
|
4799
|
-
method_type.type.params.optional?
|
|
4836
|
+
method_type.type.params.nil? || method_type.type.params.optional?
|
|
4800
4837
|
end
|
|
4801
4838
|
|
|
4802
4839
|
method_type.type.return_type if method_type
|
|
@@ -248,7 +248,7 @@ module Steep
|
|
|
248
248
|
# @type var zip: Array[[Param | MultipleParam, AST::Types::t]]
|
|
249
249
|
zip = []
|
|
250
250
|
|
|
251
|
-
if untyped_args?(params_type)
|
|
251
|
+
if params_type.nil? || untyped_args?(params_type)
|
|
252
252
|
params.each do |param|
|
|
253
253
|
if param == rest_param
|
|
254
254
|
zip << [param, AST::Builtin::Array.instance_type(fill_untyped: true)]
|
|
@@ -596,7 +596,8 @@ module Steep
|
|
|
596
596
|
if shape = subtyping.builder.shape(type, config)
|
|
597
597
|
if entry = shape.methods[method]
|
|
598
598
|
method_type = entry.method_types.find do |method_type|
|
|
599
|
-
method_type.type.params.
|
|
599
|
+
method_type.type.params.nil? ||
|
|
600
|
+
method_type.type.params.optional?
|
|
600
601
|
end
|
|
601
602
|
|
|
602
603
|
method_type.type.return_type if method_type
|
|
@@ -241,6 +241,22 @@ module Steep
|
|
|
241
241
|
|
|
242
242
|
instance = new(args: original, method_type: method_type, forward_arg_type: nil)
|
|
243
243
|
|
|
244
|
+
unless method_type.type.params
|
|
245
|
+
args.each do |arg|
|
|
246
|
+
case arg.type
|
|
247
|
+
when :arg
|
|
248
|
+
name = arg.children[0]
|
|
249
|
+
instance.params[name] = PositionalParameter.new(name: name, type: AST::Builtin.any_type, node: arg)
|
|
250
|
+
when :optarg
|
|
251
|
+
name = arg.children[0]
|
|
252
|
+
instance.params[name] = PositionalParameter.new(name: name, type: AST::Builtin.any_type, node: arg)
|
|
253
|
+
when :forward_arg
|
|
254
|
+
return instance.update(forward_arg_type: true)
|
|
255
|
+
end
|
|
256
|
+
end
|
|
257
|
+
return instance
|
|
258
|
+
end
|
|
259
|
+
|
|
244
260
|
positional_params = method_type.type.params.positional_params
|
|
245
261
|
|
|
246
262
|
loop do
|
|
@@ -500,6 +500,7 @@ module Steep
|
|
|
500
500
|
attr_reader :type
|
|
501
501
|
|
|
502
502
|
def initialize(node:, arguments:, type:)
|
|
503
|
+
raise "Untyped function is not supported" unless type.type.params
|
|
503
504
|
@node = node
|
|
504
505
|
@arguments = arguments
|
|
505
506
|
@type = type
|
|
@@ -508,9 +509,9 @@ module Steep
|
|
|
508
509
|
def params
|
|
509
510
|
case type
|
|
510
511
|
when Interface::MethodType
|
|
511
|
-
type.type.params
|
|
512
|
+
type.type.params or raise
|
|
512
513
|
when AST::Types::Proc
|
|
513
|
-
type.type.params
|
|
514
|
+
type.type.params or raise
|
|
514
515
|
else
|
|
515
516
|
raise
|
|
516
517
|
end
|
|
@@ -526,10 +527,12 @@ module Steep
|
|
|
526
527
|
end
|
|
527
528
|
|
|
528
529
|
def positional_params
|
|
530
|
+
params or raise
|
|
529
531
|
params.positional_params
|
|
530
532
|
end
|
|
531
533
|
|
|
532
534
|
def keyword_params
|
|
535
|
+
params or raise
|
|
533
536
|
params.keyword_params
|
|
534
537
|
end
|
|
535
538
|
|
data/lib/steep/version.rb
CHANGED
data/steep.gemspec
CHANGED
|
@@ -18,8 +18,11 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.metadata["source_code_uri"] = "https://github.com/soutaro/steep"
|
|
19
19
|
spec.metadata["changelog_uri"] = "https://github.com/soutaro/steep/blob/master/CHANGELOG.md"
|
|
20
20
|
|
|
21
|
+
skip_dirs = %w(test spec features smoke sig gemfile_steep .github .vscode)
|
|
22
|
+
skip_files = %w(Gemfile Gemfile.lock rbs_collection.steep.yaml rbs_collection.steep.lock.yaml)
|
|
23
|
+
|
|
21
24
|
spec.files = `git ls-files -z`.split("\x0").reject {|f|
|
|
22
|
-
|
|
25
|
+
skip_dirs.any? {|dir| f.start_with?(dir + File::SEPARATOR) } || skip_files.include?(f)
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
spec.bindir = "exe"
|
|
@@ -33,7 +36,7 @@ Gem::Specification.new do |spec|
|
|
|
33
36
|
spec.add_runtime_dependency "rainbow", ">= 2.2.2", "< 4.0"
|
|
34
37
|
spec.add_runtime_dependency "listen", "~> 3.0"
|
|
35
38
|
spec.add_runtime_dependency "language_server-protocol", ">= 3.15", "< 4.0"
|
|
36
|
-
spec.add_runtime_dependency "rbs", ">= 3.
|
|
39
|
+
spec.add_runtime_dependency "rbs", ">= 3.5.0.pre"
|
|
37
40
|
spec.add_runtime_dependency "concurrent-ruby", ">= 1.1.10"
|
|
38
41
|
spec.add_runtime_dependency "terminal-table", ">= 2", "< 4"
|
|
39
42
|
spec.add_runtime_dependency "securerandom", ">= 0.1"
|