diff --git a/lib/steep/type_construction.rb b/lib/steep/type_construction.rb index c1ee2a800..28d9f9416 100644 --- a/lib/steep/type_construction.rb +++ b/lib/steep/type_construction.rb @@ -4191,6 +4191,16 @@ def try_method_type(node, receiver_type:, method_name:, method_overload:, argume ) else # non-nil value is given + if node_type.is_a?(AST::Types::Name::Instance) && node_type.name.to_s == '::Proc' + errors << Diagnostic::Ruby::UnsupportedSyntax.new( + node: arg.node, + message: "Unsupported block-pass-argument given `#{node_type}`" + ) + + type = Interface::Function.new(params: nil, return_type: AST::Builtin.any_type, location: nil) + node_type = AST::Types::Proc.new(type: type, self_type: nil, block: nil) + end + constr.check_relation(sub_type: node_type, super_type: arg.node_type, constraints: constraints).else do |result| errors << Diagnostic::Ruby::BlockTypeMismatch.new( node: arg.node, diff --git a/smoke/block/test_expectations.yml b/smoke/block/test_expectations.yml index 0d7e06b62..80ad7654b 100644 --- a/smoke/block/test_expectations.yml +++ b/smoke/block/test_expectations.yml @@ -104,9 +104,8 @@ character: 28 severity: ERROR message: |- - Cannot pass a value of type `::Proc` as a block-pass-argument of type `^(::Integer) -> U(3)` - ::Proc <: ^(::Integer) -> U(3) - code: Ruby::BlockTypeMismatch + Unsupported block-pass-argument given `::Proc` + code: Ruby::UnsupportedSyntax - range: start: line: 11 @@ -116,9 +115,8 @@ character: 20 severity: ERROR message: |- - Cannot pass a value of type `::Proc` as a block-pass-argument of type `^(::Integer) -> U(4)` - ::Proc <: ^(::Integer) -> U(4) - code: Ruby::BlockTypeMismatch + Unsupported block-pass-argument given `::Proc` + code: Ruby::UnsupportedSyntax - file: e.rb diagnostics: - range: diff --git a/test/type_construction_test.rb b/test/type_construction_test.rb index 9f799e95c..3cb2fd97d 100644 --- a/test/type_construction_test.rb +++ b/test/type_construction_test.rb @@ -7494,6 +7494,29 @@ def test_proc_with_block_annotation end end + def test_proc_for_block_pass_argument + with_checker() do |checker| + source = parse_ruby(<<-'RUBY') +# @type var f: Proc +f = _ = nil +r = [1, 2, 3].map(&f) + RUBY + + with_standard_construction(checker, source) do |construction, typing| + type, _, context = construction.synthesize(source.node) + + assert_typing_error(typing, size: 1) do |errors| + assert_any!(errors) do |error| + assert_instance_of Diagnostic::Ruby::UnsupportedSyntax, error + assert_equal "Unsupported block-pass-argument given `::Proc`", error.message + end + end + assert_equal parse_type("::Array[untyped]"), context.type_env[:r] + end + end + end + + def test_next_with_next_type with_checker(<